Skip to content

Commit

Permalink
Conditionally define Dry.Equalizer
Browse files Browse the repository at this point in the history
So that it gets defined if one explicitly depends on dry/core/equalizer
  • Loading branch information
flash-gordon committed Oct 11, 2022
1 parent ba9d614 commit 9458492
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/dry/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ def self.loader
loader.setup
end

# Build an equalizer module for the inclusion in other class
#
# ## Credits
#
# Equalizer has been originally imported from the equalizer gem created by Dan Kubb
#
# @api public
def self.Equalizer(*keys, **options)
Dry::Core::Equalizer.new(*keys, **options)
# See dry/core/equalizer.rb
unless singleton_class.method_defined?(:Equalizer)
# Build an equalizer module for the inclusion in other class
#
# ## Credits
#
# Equalizer has been originally imported from the equalizer gem created by Dan Kubb
#
# @api public
def self.Equalizer(*keys, **options)
Dry::Core::Equalizer.new(*keys, **options)
end
end
end
15 changes: 15 additions & 0 deletions lib/dry/core/equalizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,19 @@ def ==(other)
end
end
end

# Old modules that depend on dry/core/equalizer may miss
# this method if dry/core is not required explicitly
unless singleton_class.method_defined?(:Equalizer)
# Build an equalizer module for the inclusion in other class
#
# ## Credits
#
# Equalizer has been originally imported from the equalizer gem created by Dan Kubb
#
# @api public
def self.Equalizer(*keys, **options)
Dry::Core::Equalizer.new(*keys, **options)
end
end
end

0 comments on commit 9458492

Please sign in to comment.