Class: FactoryBot::Evaluator Private
- Inherits:
-
Object
- Object
- FactoryBot::Evaluator
- Defined in:
- lib/factory_bot/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.
Instance Attribute Summary collapse
- #instance ⇒ Object private
Class Method Summary collapse
- .attribute_list ⇒ Object private
- .define_attribute(name, &block) ⇒ Object private
Instance Method Summary collapse
- #__override_names__ ⇒ Object private
- #association(factory_name, *traits_and_overrides) ⇒ Object private
- #increment_sequence(sequence) ⇒ Object private
-
#initialize(build_strategy, overrides = {}) ⇒ Evaluator
constructor
private
A new instance of Evaluator.
- #method_missing(method_name) ⇒ Object private
- #respond_to_missing?(method_name, _include_private = false) ⇒ Boolean private
Constructor Details
#initialize(build_strategy, overrides = {}) ⇒ Evaluator
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.
Returns a new instance of Evaluator.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/factory_bot/evaluator.rb', line 13 def initialize(build_strategy, overrides = {}) @build_strategy = build_strategy @overrides = overrides @cached_attributes = overrides @instance = nil @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
#method_missing(method_name) ⇒ Object
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.
38 39 40 41 42 43 44 |
# File 'lib/factory_bot/evaluator.rb', line 38 def method_missing(method_name, ...) if @instance.respond_to?(method_name) @instance.send(method_name, ...) else SyntaxRunner.new.send(method_name, ...) end end |
Instance Attribute Details
#instance ⇒ Object
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.
36 37 38 |
# File 'lib/factory_bot/evaluator.rb', line 36 def instance @instance end |
Class Method Details
.attribute_list ⇒ Object
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.
58 59 60 61 62 63 64 |
# File 'lib/factory_bot/evaluator.rb', line 58 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 |
.define_attribute(name, &block) ⇒ Object
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.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/factory_bot/evaluator.rb', line 66 def self.define_attribute(name, &block) if instance_methods(false).include?(name) || private_instance_methods(false).include?(name) undef_method(name) end 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
#__override_names__ ⇒ Object
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.
50 51 52 |
# File 'lib/factory_bot/evaluator.rb', line 50 def __override_names__ @overrides.keys end |
#association(factory_name, *traits_and_overrides) ⇒ Object
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.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/factory_bot/evaluator.rb', line 24 def association(factory_name, *traits_and_overrides) overrides = traits_and_overrides. strategy_override = overrides.fetch(:strategy) { FactoryBot.use_parent_strategy ? @build_strategy.to_sym : :create } traits_and_overrides += [overrides.except(:strategy)] runner = FactoryRunner.new(factory_name, strategy_override, traits_and_overrides) @build_strategy.association(runner) end |
#increment_sequence(sequence) ⇒ Object
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.
54 55 56 |
# File 'lib/factory_bot/evaluator.rb', line 54 def increment_sequence(sequence) sequence.next(self) end |
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
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.
46 47 48 |
# File 'lib/factory_bot/evaluator.rb', line 46 def respond_to_missing?(method_name, _include_private = false) @instance.respond_to?(method_name) || SyntaxRunner.new.respond_to?(method_name) end |