From 964dc889e2b5a446df131e83817f1b840a6953ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Busqu=C3=A9?= Date: Tue, 17 Sep 2024 17:44:01 +0200 Subject: [PATCH] Remove upfront extension requires This commit addresses an issue where we were requiring all extension files upfront, which could raise errors if the required gems were not present in the user's environment. To resolve this, we've removed the automatic requires for ActiveRecord and ROM extensions from lib/dry/operation.rb. Instead, we've updated the documentation in both ActiveRecord and ROM extension files to include the necessary require statement in the example code. To ensure our tests continue to pass with these changes, we've also added the requires to the spec_helper file. See report: https://github.com/dry-rb/dry-operation/commit/92cdde9a9fd04e87c4b5d6c070494f444f104139#commitcomment-146824502 --- lib/dry/operation.rb | 2 -- lib/dry/operation/extensions/active_record.rb | 2 ++ lib/dry/operation/extensions/rom.rb | 2 ++ spec/spec_helper.rb | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/dry/operation.rb b/lib/dry/operation.rb index 20ed60e..854e3c8 100644 --- a/lib/dry/operation.rb +++ b/lib/dry/operation.rb @@ -3,8 +3,6 @@ require "zeitwerk" require "dry/monads" require "dry/operation/errors" -require "dry/operation/extensions/active_record" -require "dry/operation/extensions/rom" module Dry # DSL for chaining operations that can fail diff --git a/lib/dry/operation/extensions/active_record.rb b/lib/dry/operation/extensions/active_record.rb index f717a23..c0a1f5d 100644 --- a/lib/dry/operation/extensions/active_record.rb +++ b/lib/dry/operation/extensions/active_record.rb @@ -17,6 +17,8 @@ module Extensions # back and, as usual, the rest of the flow will be skipped. # # ```ruby + # require "dry/operation/extensions/active_record" + # # class MyOperation < Dry::Operation # include Dry::Operation::Extensions::ActiveRecord # diff --git a/lib/dry/operation/extensions/rom.rb b/lib/dry/operation/extensions/rom.rb index 2592849..d1a5e24 100644 --- a/lib/dry/operation/extensions/rom.rb +++ b/lib/dry/operation/extensions/rom.rb @@ -20,6 +20,8 @@ module Extensions # container via a `#rom` method. # # ```ruby + # require "dry/operation/extensions/rom" + # # class MyOperation < Dry::Operation # include Dry::Operation::Extensions::ROM # diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4177198..cac3aca 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,8 @@ Bundler.require :tools require "dry/operation" +require "dry/operation/extensions/active_record" +require "dry/operation/extensions/rom" SPEC_ROOT = Pathname(__dir__).realpath.freeze