Skip to content

Commit

Permalink
Add support ruby 2.4 again
Browse files Browse the repository at this point in the history
By monkey-patching the Hash and String classes

Note that simplecov/simplecov-lcov code needs to be commented out, as this library does not support ruby 2.4
  • Loading branch information
rarruda committed Feb 16, 2022
1 parent 3b73407 commit 45b5f56
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/unleash.rb
Expand Up @@ -7,6 +7,14 @@

Gem.find_files('unleash/strategy/**/*.rb').each{ |path| require path unless path.end_with? '_spec.rb' }

if Gem::Version.new(RUBY_VERSION.split(".")[0..1]&.join(".")) < Gem::Version.new('2.5')
# Monkey patch to allow supporting older versions of ruby
require 'unleash/core_ext/hash'
require 'unleash/core_ext/string'
String.include Unleash::CoreExtensions::String
Hash.include Unleash::CoreExtensions::Hash
end

module Unleash
TIME_RESOLUTION = 3

Expand Down
13 changes: 13 additions & 0 deletions lib/unleash/core_ext/hash.rb
@@ -0,0 +1,13 @@
module Unleash
module CoreExtensions
module Hash
def transform_keys
result = {}
each_key do |key|
result[yield(key)] = self[key]
end
result
end
end
end
end
10 changes: 10 additions & 0 deletions lib/unleash/core_ext/string.rb
@@ -0,0 +1,10 @@
module Unleash
module CoreExtensions
module String
def delete_suffix(suffix)
return self[0..(self.length - 1 - suffix.length)] if self.end_with?(suffix)
self
end
end
end
end
2 changes: 1 addition & 1 deletion unleash-client.gemspec
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
spec.bindir = 'bin'
spec.executables = spec.files.grep(%r{^bin/unleash}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.required_ruby_version = ">= 2.5"
spec.required_ruby_version = ">= 2.4"

spec.add_dependency "murmurhash3", "~> 0.1.6"

Expand Down

0 comments on commit 45b5f56

Please sign in to comment.