class FactoryBot::Evaluator
@api private
Attributes
instance[RW]
Public Class Methods
attribute_list()
click to toggle source
# File lib/factory_bot/evaluator.rb, line 59 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)
click to toggle source
# File lib/factory_bot/evaluator.rb, line 67 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
new(build_strategy, overrides = {})
click to toggle source
# 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
Public Instance Methods
__override_names__()
click to toggle source
# File lib/factory_bot/evaluator.rb, line 51 def __override_names__ @overrides.keys end
association(factory_name, *traits_and_overrides)
click to toggle source
# File lib/factory_bot/evaluator.rb, line 24 def association(factory_name, *traits_and_overrides) overrides = traits_and_overrides.extract_options! 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)
click to toggle source
# File lib/factory_bot/evaluator.rb, line 55 def increment_sequence(sequence) sequence.next(self) end
method_missing(method_name, *args, &block)
click to toggle source
# File lib/factory_bot/evaluator.rb, line 38 def method_missing(method_name, *args, &block) if @instance.respond_to?(method_name) @instance.send(method_name, *args, &block) else SyntaxRunner.new.send(method_name, *args, &block) end end
respond_to_missing?(method_name, _include_private = false)
click to toggle source
# File lib/factory_bot/evaluator.rb, line 47 def respond_to_missing?(method_name, _include_private = false) @instance.respond_to?(method_name) || SyntaxRunner.new.respond_to?(method_name) end