diff options
author | Masahiro Saito <camelmasa@gmail.com> | 2017-01-06 21:45:16 +0900 |
---|---|---|
committer | Daniel Doubrovkine (dB.) @dblockdotorg <dblock@dblock.org> | 2017-01-06 07:45:16 -0500 |
commit | 87582b589fe04a9f0433478997d42aa8fa798144 (patch) | |
tree | 248c1f76d3bb295a691e39d8b35bb00f186c67c1 | |
parent | 199d816bc0865d4276a1b6db669ef9f3a2fedfc1 (diff) | |
download | hashie-87582b589fe04a9f0433478997d42aa8fa798144.tar.gz |
Support Ruby 2.4.0 (#389)
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | Gemfile | 7 | ||||
-rw-r--r-- | lib/hashie/extensions/coercion.rb | 12 | ||||
-rw-r--r-- | spec/hashie/extensions/coercion_spec.rb | 10 |
5 files changed, 24 insertions, 7 deletions
diff --git a/.travis.yml b/.travis.yml index 5ea090f..15118f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ sudo: false cache: bundler rvm: + - 2.4.0 - 2.3.0 - 2.2.3 - 2.1.7 diff --git a/CHANGELOG.md b/CHANGELOG.md index dd15125..cbcbb63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ scheme are considered to be bugs. ## [Unreleased][unreleased] * [#386](https://github.com/intridea/hashie/pull/386): Fix for #385: Make `deep_merge` always `deep_dup` nested hashes before merging them in so that there are no shared references between the two hashes being merged. - [@mltsy](https://github.com/mltsy). +* [#389](https://github.com/intridea/hashie/pull/389): Support Ruby 2.4.0 - [@camelmasa](https://github.com/camelmasa). [3.4.7]: https://github.com/intridea/hashie/compare/v3.4.6...master @@ -12,7 +12,12 @@ end group :test do # ActiveSupport required to test compatibility with ActiveSupport Core Extensions. - gem 'activesupport', '~> 4.x', require: false + require File.expand_path('../lib/hashie/extensions/ruby_version', __FILE__) + if Hashie::Extensions::RubyVersion.new(RUBY_VERSION) >= Hashie::Extensions::RubyVersion.new('2.4.0') + gem 'activesupport', '~> 5.x', require: false + else + gem 'activesupport', '~> 4.x', require: false + end gem 'codeclimate-test-reporter', '~> 1.0', require: false gem 'rspec-core', '~> 3.1.7' gem 'danger-changelog', '~> 0.1.0', require: false diff --git a/lib/hashie/extensions/coercion.rb b/lib/hashie/extensions/coercion.rb index 962f94f..eb0a6dd 100644 --- a/lib/hashie/extensions/coercion.rb +++ b/lib/hashie/extensions/coercion.rb @@ -12,10 +12,14 @@ module Hashie Symbol => :to_sym } - ABSTRACT_CORE_TYPES = { - Integer => [Fixnum, Bignum], - Numeric => [Fixnum, Bignum, Float, Complex, Rational] - } + ABSTRACT_CORE_TYPES = if RubyVersion.new(RUBY_VERSION) >= RubyVersion.new('2.4.0') + { Numeric => [Integer, Float, Complex, Rational] } + else + { + Integer => [Fixnum, Bignum], + Numeric => [Fixnum, Bignum, Float, Complex, Rational] + } + end def self.included(base) base.send :include, InstanceMethods diff --git a/spec/hashie/extensions/coercion_spec.rb b/spec/hashie/extensions/coercion_spec.rb index d8af161..7d70ed4 100644 --- a/spec/hashie/extensions/coercion_spec.rb +++ b/spec/hashie/extensions/coercion_spec.rb @@ -558,8 +558,14 @@ describe Hashie::Extensions::Coercion do end it 'raises a CoercionError when coercion is not possible' do - subject.coerce_value Fixnum, Symbol - expect { instance[:hi] = 1 }.to raise_error(Hashie::CoercionError, /Cannot coerce property :hi from Fixnum to Symbol/) + type = if Hashie::Extensions::RubyVersion.new(RUBY_VERSION) >= Hashie::Extensions::RubyVersion.new('2.4.0') + Integer + else + Fixnum + end + + subject.coerce_value type, Symbol + expect { instance[:hi] = 1 }.to raise_error(Hashie::CoercionError, /Cannot coerce property :hi from #{type} to Symbol/) end it 'coerces Integer to String' do |