Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions lib/factory_bot/evaluator_class_definer.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
module FactoryBot
# @api private
class EvaluatorClassDefiner
def initialize(attributes, parent_class)
@parent_class = parent_class
@attributes = attributes

attributes.each do |attribute|
evaluator_class.define_attribute(attribute.name, &attribute.to_proc)
end
end

def evaluator_class
@evaluator_class ||= Class.new(@parent_class).tap do |klass|
module EvaluatorClassDefiner
def self.define_evaluator_class(attributes, parent_class)
Class.new(parent_class).tap do |klass|
klass.attribute_lists ||= []
klass.attribute_lists += [@attributes]
klass.attribute_lists += [attributes]
attributes.each do |attribute|
klass.define_attribute(attribute.name, &attribute.to_proc)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/factory_bot/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def class_name
end

def evaluator_class
@evaluator_class ||= EvaluatorClassDefiner.new(attributes, parent.evaluator_class).evaluator_class
@evaluator_class ||= EvaluatorClassDefiner.define_evaluator_class(attributes, parent.evaluator_class)
end

def attributes
Expand Down
3 changes: 1 addition & 2 deletions spec/factory_bot/evaluator_class_definer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ def define_evaluator(arguments = {})
end

def define_evaluator_class(arguments = {})
evaluator_class_definer = FactoryBot::EvaluatorClassDefiner.new(
FactoryBot::EvaluatorClassDefiner.define_evaluator_class(
arguments[:attributes] || [],
arguments[:parent_class] || FactoryBot::Evaluator
)
evaluator_class_definer.evaluator_class
end

def stub_attribute(name = :attribute, &value)
Expand Down