Class: FactoryGirl::Evaluator
- Inherits:
-
Object
- Object
- FactoryGirl::Evaluator
show all
- Defined in:
- lib/factory_girl/evaluator.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(build_strategy, overrides = {}) ⇒ Evaluator
Returns a new instance of Evaluator.
20
21
22
23
24
25
26
27
28
|
# File 'lib/factory_girl/evaluator.rb', line 20
def initialize(build_strategy, overrides = {})
@build_strategy = build_strategy
@overrides = overrides
@cached_attributes = overrides
@overrides.each do |name, value|
singleton_class.send :define_method, name, lambda { value }
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/factory_girl/evaluator.rb', line 46
def method_missing(method_name, *args, &block)
if @cached_attributes.key?(method_name)
@cached_attributes[method_name]
else
@instance.send(method_name, *args, &block)
end
end
|
Class Method Details
.attribute_list ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/factory_girl/evaluator.rb', line 8
def self.attribute_list
AttributeList.new.tap do |list|
attribute_lists.each do |attribute_list|
list.apply_attributes attribute_list.to_a
end
end
end
|
Instance Method Details
#__overrides ⇒ Object
54
55
56
|
# File 'lib/factory_girl/evaluator.rb', line 54
def __overrides
@overrides
end
|
#association(factory_name, overrides = {}) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/factory_girl/evaluator.rb', line 30
def association(factory_name, overrides = {})
build_strategy = if overrides.has_key?(:strategy)
overrides[:strategy]
else
Strategy::Create
end
build_strategy = StrategyCalculator.new(build_strategy).strategy
runner = FactoryRunner.new(factory_name, build_strategy, [overrides.except(:strategy)])
@build_strategy.association(runner)
end
|
#instance=(object_instance) ⇒ Object
42
43
44
|
# File 'lib/factory_girl/evaluator.rb', line 42
def instance=(object_instance)
@instance = object_instance
end
|