mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
a154e64da1
Declarations are another layer of abstraction between defining the factories via the DSL and compiling the factories and their attributes. Declarations know how to return their attribute(s), and running a factory compiles the declarations before building all attributes on the factory. This moves all the attribute compilation logic into one centralized location on the Factory instance, which means traits (and potentially other features down the road) can have individual attributes overridden within child factories or through FactoryGirl.modify Closes #205
19 lines
289 B
Ruby
19 lines
289 B
Ruby
module FactoryGirl
|
|
class Declaration
|
|
attr_reader :name
|
|
|
|
def initialize(name)
|
|
@name = name
|
|
end
|
|
|
|
def ignore
|
|
@ignored = true
|
|
end
|
|
|
|
def to_attributes
|
|
build.tap do |attributes|
|
|
attributes.each(&:ignore) if @ignored
|
|
end
|
|
end
|
|
end
|
|
end
|