Class: FactoryGirl::Evaluator
- Inherits:
-
Object
- Object
- FactoryGirl::Evaluator
show all
- Defined in:
- lib/factory_girl/evaluator.rb
Defined Under Namespace
Classes: CallbackRunner
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
29
30
31
|
# File 'lib/factory_girl/evaluator.rb', line 20
def initialize(build_strategy, overrides = {})
@build_strategy = build_strategy
@overrides = overrides
@cached_attributes = overrides
singleton = class << self; self end
@overrides.each do |name, value|
singleton.send :define_method, name, lambda { value }
end
@build_strategy.add_observer(CallbackRunner.new(self.class.callbacks, self))
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/factory_girl/evaluator.rb', line 52
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
60
61
62
|
# File 'lib/factory_girl/evaluator.rb', line 60
def __overrides
@overrides
end
|
#association(factory_name, overrides = {}) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/factory_girl/evaluator.rb', line 33
def association(factory_name, overrides = {})
build_strategy = if overrides.has_key?(:method)
$stderr.puts "DEPRECATION WARNING: using :method to specify a build strategy is deprecated; use :strategy instead"
overrides[:method]
elsif 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(:method, :strategy)])
@build_strategy.association(runner)
end
|
#instance=(object_instance) ⇒ Object
48
49
50
|
# File 'lib/factory_girl/evaluator.rb', line 48
def instance=(object_instance)
@instance = object_instance
end
|