Class: FactoryGirl::Evaluator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_girl/evaluator.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.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Evaluator) initialize(build_class, build_strategy, overrides = {})

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 Evaluator



13
14
15
16
17
18
19
20
21
22
# File 'lib/factory_girl/evaluator.rb', line 13

def initialize(build_class, build_strategy, overrides = {})
  @build_class       = build_class
  @build_strategy    = build_strategy
  @overrides         = overrides
  @cached_attributes = overrides

  @overrides.each do |name, value|
    singleton_class.define_attribute(name) { value }
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method_name, *args, &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.



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/factory_girl/evaluator.rb', line 37

def method_missing(method_name, *args, &block)
  if @cached_attributes.key?(method_name)
    @cached_attributes[method_name]
  else
    if @instance.respond_to?(method_name)
      @instance.send(method_name, *args, &block)
    else
      SyntaxRunner.new.send(method_name, *args, &block)
    end
  end
end

Class Method Details

+ (Object) attribute_list

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.



53
54
55
56
57
58
59
# File 'lib/factory_girl/evaluator.rb', line 53

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

+ (Object) define_attribute(name, &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.



61
62
63
64
65
66
67
68
69
# File 'lib/factory_girl/evaluator.rb', line 61

def self.define_attribute(name, &block)
  define_method(name) do
    if @cached_attributes.key?(name)
      @cached_attributes[name]
    else
      @cached_attributes[name] = instance_exec(&block)
    end
  end
end

Instance Method Details

- (Object) __override_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.



49
50
51
# File 'lib/factory_girl/evaluator.rb', line 49

def __override_names__
  @overrides.keys
end

- (Object) association(factory_name, overrides = {})

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.



26
27
28
29
30
31
# File 'lib/factory_girl/evaluator.rb', line 26

def association(factory_name, overrides = {})
  strategy_override = overrides.fetch(:strategy) { :create }

  runner = FactoryRunner.new(factory_name, strategy_override, [overrides.except(:strategy)])
  @build_strategy.association(runner)
end

- (Object) instance=(object_instance)

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.



33
34
35
# File 'lib/factory_girl/evaluator.rb', line 33

def instance=(object_instance)
  @instance = object_instance
end