2012-05-05 01:14:21 -04:00
|
|
|
require 'observer'
|
2012-04-13 14:20:19 -04:00
|
|
|
|
2017-10-20 15:20:28 -04:00
|
|
|
module FactoryBot
|
2012-04-13 14:20:19 -04:00
|
|
|
class Evaluation
|
|
|
|
include Observable
|
|
|
|
|
2017-09-28 08:17:17 -04:00
|
|
|
def initialize(evaluator, attribute_assigner, to_create)
|
|
|
|
@evaluator = evaluator
|
2012-04-13 14:20:19 -04:00
|
|
|
@attribute_assigner = attribute_assigner
|
2012-05-12 00:42:44 -04:00
|
|
|
@to_create = to_create
|
2012-04-13 14:20:19 -04:00
|
|
|
end
|
|
|
|
|
2012-05-05 01:14:21 -04:00
|
|
|
delegate :object, :hash, to: :@attribute_assigner
|
|
|
|
|
2012-04-13 14:20:19 -04:00
|
|
|
def create(result_instance)
|
2017-09-28 08:17:17 -04:00
|
|
|
case @to_create.arity
|
|
|
|
when 2 then @to_create[result_instance, @evaluator]
|
|
|
|
else @to_create[result_instance]
|
|
|
|
end
|
2012-04-13 14:20:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def notify(name, result_instance)
|
|
|
|
changed
|
|
|
|
notify_observers(name, result_instance)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|