Skip to content

Commit

Permalink
Remove dependency on observer
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain authored and mike-burns committed Dec 27, 2023
1 parent 138ae7d commit ac91aeb
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 13 deletions.
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ PATH
specs:
factory_bot (6.4.3)
activesupport (>= 5.0.0)
observer

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -74,7 +73,6 @@ GEM
middleware (0.1.0)
minitest (5.14.3)
multi_test (0.1.2)
observer (0.1.2)
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
Expand Down
1 change: 0 additions & 1 deletion factory_bot.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Gem::Specification.new do |s|
}

s.add_dependency("activesupport", ">= 5.0.0")
s.add_dependency("observer") if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.3")

s.add_development_dependency("activerecord")
s.add_development_dependency("appraisal")
Expand Down
10 changes: 3 additions & 7 deletions lib/factory_bot/evaluation.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
require "observer"

module FactoryBot
class Evaluation
include Observable

def initialize(evaluator, attribute_assigner, to_create)
def initialize(evaluator, attribute_assigner, to_create, observer)
@evaluator = evaluator
@attribute_assigner = attribute_assigner
@to_create = to_create
@observer = observer
end

delegate :object, :hash, to: :@attribute_assigner
Expand All @@ -20,8 +17,7 @@ def create(result_instance)
end

def notify(name, result_instance)
changed
notify_observers(name, result_instance)
@observer.update(name, result_instance)
end
end
end
4 changes: 2 additions & 2 deletions lib/factory_bot/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def run(build_strategy, overrides, &block)
evaluator = evaluator_class.new(strategy, overrides.symbolize_keys)
attribute_assigner = AttributeAssigner.new(evaluator, build_class, &compiled_constructor)

observer = CallbacksObserver.new(callbacks, evaluator)
evaluation =
Evaluation.new(evaluator, attribute_assigner, compiled_to_create)
evaluation.add_observer(CallbacksObserver.new(callbacks, evaluator))
Evaluation.new(evaluator, attribute_assigner, compiled_to_create, observer)

strategy.result(evaluation).tap(&block)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factory_bot/factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def build_factory
attribute = FactoryBot::Attribute::Dynamic.new(:name, false, -> { "value" })
attributes = [attribute]
declaration = FactoryBot::Declaration::Dynamic.new(:name, false, -> { "value" })
strategy = double("strategy", result: "result", add_observer: true)
strategy = double("strategy", result: "result")
define_model("User", name: :string)
allow(FactoryBot::Declaration::Dynamic).to receive(:new)
.and_return declaration
Expand Down

0 comments on commit ac91aeb

Please sign in to comment.