Class: FactoryGirl::Factory Private
- Inherits:
-
Object
- Object
- FactoryGirl::Factory
- Defined in:
- lib/factory_girl/factory.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary (collapse)
- - (Object) definition readonly private
- - (Object) name readonly private
Instance Method Summary (collapse)
- - (Object) associations private
- - (Object) build_class private
- - (Object) compile private
- - (Object) human_names private
-
- (Factory) initialize(name, options = {})
constructor
private
A new instance of Factory.
-
- (Object) names
private
Names for this factory, including aliases.
- - (Object) run(build_strategy, overrides, &block) private
- - (Object) with_traits(traits) private
Constructor Details
- (Factory) initialize(name, options = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
A new instance of Factory
9 10 11 12 13 14 15 16 17 |
# File 'lib/factory_girl/factory.rb', line 9 def initialize(name, = {}) () @name = name.is_a?(Symbol) ? name : name.to_s.underscore.to_sym @parent = [:parent] @aliases = [:aliases] || [] @class_name = [:class] @definition = Definition.new(@name, [:traits] || []) @compiled = false end |
Instance Attribute Details
- (Object) definition (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
7 8 9 |
# File 'lib/factory_girl/factory.rb', line 7 def definition @definition end |
- (Object) name (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
7 8 9 |
# File 'lib/factory_girl/factory.rb', line 7 def name @name end |
Instance Method Details
- (Object) associations
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 |
# File 'lib/factory_girl/factory.rb', line 49 def associations evaluator_class.attribute_list.associations end |
- (Object) build_class
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 25 26 27 28 |
# File 'lib/factory_girl/factory.rb', line 22 def build_class @build_class ||= if class_name.is_a? Class class_name else class_name.to_s.camelize.constantize end end |
- (Object) compile
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 85 86 87 88 89 |
# File 'lib/factory_girl/factory.rb', line 82 def compile unless @compiled parent.compile parent.defined_traits.each {|trait| define_trait(trait) } @definition.compile @compiled = true end end |
- (Object) human_names
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 |
# File 'lib/factory_girl/factory.rb', line 45 def human_names names.map {|name| name.to_s.humanize.downcase } end |
- (Object) names
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Names for this factory, including aliases.
Example:
factory :user, aliases: [:author] do
# ...
end
FactoryGirl.create(:author).class
# => User
Because an attribute defined without a value or block will build an association with the same name, this allows associations to be defined without factories, such as:
factory :user, aliases: [:author] do
# ...
end
factory :post do
end
FactoryGirl.create(:post)..class
# => User
78 79 80 |
# File 'lib/factory_girl/factory.rb', line 78 def names [name] + @aliases end |
- (Object) run(build_strategy, overrides, &block)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/factory_girl/factory.rb', line 30 def run(build_strategy, overrides, &block) block ||= ->(result) { result } compile strategy = StrategyCalculator.new(build_strategy).strategy.new evaluator = evaluator_class.new(build_class, strategy, overrides.symbolize_keys) attribute_assigner = AttributeAssigner.new(evaluator, build_class, &compiled_constructor) evaluation = Evaluation.new(attribute_assigner, compiled_to_create) evaluation.add_observer(CallbacksObserver.new(callbacks, evaluator)) strategy.result(evaluation).tap(&block) end |
- (Object) with_traits(traits)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
91 92 93 94 95 |
# File 'lib/factory_girl/factory.rb', line 91 def with_traits(traits) self.clone.tap do |factory_with_traits| factory_with_traits.append_traits traits end end |