From 7b14dde4782916360903c279048b4fe6852e1702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Tue, 26 Jan 2016 11:21:20 -0500 Subject: [PATCH 01/13] README: Clarified IndifferentAccess docs Tried to make the IndifferentAccess documentation clearer. Closes #340 --- README.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cb56c686..cd7532c3 100644 --- a/README.md +++ b/README.md @@ -237,9 +237,30 @@ overriding.__zip #=> [[['zip', 'a-dee-doo-dah']]] ### IndifferentAccess -This extension can be mixed in to instantly give you indifferent access to your Hash subclass. This works just like the params hash in Rails and other frameworks where whether you provide symbols or strings to access keys, you will get the same results. +This extension can be mixed in to your Hash subclass to allow you to use Strings or Symbols interchangeably as keys; similar to the `params` hash in Rails. -A unique feature of Hashie's IndifferentAccess mixin is that it will inject itself recursively into subhashes *without* reinitializing the hash in question. This means you can safely merge together indifferent and non-indifferent hashes arbitrarily deeply without worrying about whether you'll be able to `hash[:other][:another]` properly. +In addition, IndifferentAccess will also inject itself into sub-hashes so they behave the same. + +Example: + +```ruby +class MyHash < Hash + include Hashie::Extensions::MergeInitializer + include Hashie::Extensions::IndifferentAccess +end + +myhash = MyHash.new(:cat => 'meow', 'dog' => 'woof') +myhash['cat'] # => "meow" +myhash[:cat] # => "meow" +myhash[:dog] # => "woof" +myhash['dog'] # => "woof" + +# Auto-Injecting into sub-hashes. +myhash['fishes'] = {} +myhash['fishes'].class # => Hash +myhash['fishes'][:food] = 'flakes' +myhash['fishes']['food'] # => "flakes" +``` ### IgnoreUndeclared From c8731213c95cac2d265e60bb24ed331516106594 Mon Sep 17 00:00:00 2001 From: dblock Date: Tue, 26 Jan 2016 18:08:48 -0500 Subject: [PATCH 02/13] Fix build: ignore rbx-2 failures and add ruby 2.3.0. --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e57e68d0..b7944292 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,12 +3,12 @@ sudo: false cache: bundler rvm: + - 2.3.0 - 2.2.3 - 2.1.7 - 2.0.0 - 1.9.3 - - rbx-2.5.8 - - rbx-2.2.10 + - rbx-2 - jruby-19mode - jruby-head - ruby-head @@ -17,3 +17,4 @@ matrix: allow_failures: - rvm: ruby-head - rvm: jruby-head + - rvm: rbx-2 From f722ee310f1517392c91677c9b4fcec92e8dbc36 Mon Sep 17 00:00:00 2001 From: Michael Herold Date: Sun, 31 Jan 2016 17:02:03 -0600 Subject: [PATCH 03/13] Fix `#merge` breaking indifferent access `HashWithDifferentAccess` wasn't properly setting the indifferent access when merging in other hashes. This reruns `#convert!` after calling the superclass implementation of the method, so it preserves indifferent access on the resulting object. Fixes #345 --- CHANGELOG.md | 1 + lib/hashie/extensions/indifferent_access.rb | 8 ++++++ .../extensions/indifferent_access_spec.rb | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 205202ef..a1de520f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * [#319](https://github.com/intridea/hashie/pull/319): Fix a regression from 3.4.1 where `Hashie::Extensions::DeepFind` is no longer indifference-aware - [@michaelherold](https://github.com/michaelherold). * [#240](https://github.com/intridea/hashie/pull/240): Fixed nesting twice with Clash keys - [@bartoszkopinski](https://github.com/bartoszkopinski). * [#322](https://github.com/intridea/hashie/pull/322): Fixed `reverse_merge` issue with `Mash` subclasses - [@marshall-lee](https://github.com/marshall-lee). +* [#346](https://github.com/intridea/hashie/pull/346): Fixed `merge` breaking indifferent access - [@docwhat](https://github.com/docwhat), [@michaelherold](https://github.com/michaelherold). * Your contribution here. ## 3.4.3 (10/25/2015) diff --git a/lib/hashie/extensions/indifferent_access.rb b/lib/hashie/extensions/indifferent_access.rb index 3bbb93de..55648a62 100644 --- a/lib/hashie/extensions/indifferent_access.rb +++ b/lib/hashie/extensions/indifferent_access.rb @@ -133,6 +133,14 @@ def indifferent_replace(other_hash) self end + def merge(*) + super.convert! + end + + def merge!(*) + super.convert! + end + protected def hash_lacking_indifference?(other) diff --git a/spec/hashie/extensions/indifferent_access_spec.rb b/spec/hashie/extensions/indifferent_access_spec.rb index dfdbcaed..294c0b49 100644 --- a/spec/hashie/extensions/indifferent_access_spec.rb +++ b/spec/hashie/extensions/indifferent_access_spec.rb @@ -31,6 +31,32 @@ class IndifferentHashWithDash < Hashie::Dash property :foo end + describe '#merge' do + it 'indifferently merges in a hash' do + indifferent_hash = Class.new(::Hash) do + include Hashie::Extensions::IndifferentAccess + end.new + + merged_hash = indifferent_hash.merge(:cat => 'meow') + + expect(merged_hash[:cat]).to eq('meow') + expect(merged_hash['cat']).to eq('meow') + end + end + + describe '#merge!' do + it 'indifferently merges in a hash' do + indifferent_hash = Class.new(::Hash) do + include Hashie::Extensions::IndifferentAccess + end.new + + indifferent_hash.merge!(:cat => 'meow') + + expect(indifferent_hash[:cat]).to eq('meow') + expect(indifferent_hash['cat']).to eq('meow') + end + end + describe 'when included in dash' do let(:params) { { foo: 'bar' } } subject { IndifferentHashWithDash.new(params) } From b017e3e1140b17baed77a699d5836cdb1bfad90e Mon Sep 17 00:00:00 2001 From: Michael Herold Date: Sat, 5 Dec 2015 09:37:45 -0600 Subject: [PATCH 04/13] Update the change log format By updating to the "Keep a Changelog" format, we can more easily identify changes that necessitate different levels of version bump. This change updates the changelog to the new format and updates the contributing and releasing guides with new instructions based on the new changelog format. --- CHANGELOG.md | 302 ++++++++++++++++++++++++++++++++++++++---------- CONTRIBUTING.md | 12 +- RELEASING.md | 67 ++++++++--- 3 files changed, 304 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1de520f..d1c798cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,163 +1,339 @@ -## 3.4.4 (Next) +# Change Log +All notable changes to this project will be documented in this file. This +project adheres to [Semantic Versioning 2.0.0][semver]. Any violations of this +scheme are considered to be bugs. + +[semver]: http://semver.org/spec/v2.0.0.html + +## [Unreleased][unreleased] + +[unreleased]: https://github.com/intridea/hashie/compare/v3.4.3...master + +### Added + +* Nothing yet. + +### Changed + +* Nothing yet. + +### Deprecated + +* Nothing yet. + +### Removed + +* Nothing yet. + +### Fixed + +* [#240](https://github.com/intridea/hashie/pull/240): Fixed nesting twice with Clash keys - [@bartoszkopinski](https://github.com/bartoszkopinski). * [#317](https://github.com/intridea/hashie/pull/317): Ensure `Hashie::Extensions::MethodQuery` methods return boolean values - [@michaelherold](https://github.com/michaelherold). * [#319](https://github.com/intridea/hashie/pull/319): Fix a regression from 3.4.1 where `Hashie::Extensions::DeepFind` is no longer indifference-aware - [@michaelherold](https://github.com/michaelherold). -* [#240](https://github.com/intridea/hashie/pull/240): Fixed nesting twice with Clash keys - [@bartoszkopinski](https://github.com/bartoszkopinski). * [#322](https://github.com/intridea/hashie/pull/322): Fixed `reverse_merge` issue with `Mash` subclasses - [@marshall-lee](https://github.com/marshall-lee). * [#346](https://github.com/intridea/hashie/pull/346): Fixed `merge` breaking indifferent access - [@docwhat](https://github.com/docwhat), [@michaelherold](https://github.com/michaelherold). -* Your contribution here. -## 3.4.3 (10/25/2015) +### Security + +* Nothing yet. + +### Miscellanous + +* Nothing yet. +## [3.4.3] - 2015-10-25 + +[3.4.3]: https://github.com/intridea/hashie/compare/v3.4.2...v3.4.3 + +### Added + +* [#306](https://github.com/intridea/hashie/pull/306): Added `Hashie::Extensions::Dash::Coercion` - [@marshall-lee](https://github.com/marshall-lee). * [#314](https://github.com/intridea/hashie/pull/314): Added a `StrictKeyAccess` extension that will raise an error whenever a key is accessed that does not exist in the hash - [@pboling](https://github.com/pboling). + +### Fixed + * [#304](https://github.com/intridea/hashie/pull/304): Ensured compatibility of `Hash` extensions with singleton objects - [@regexident](https://github.com/regexident). -* [#306](https://github.com/intridea/hashie/pull/306): Added `Hashie::Extensions::Dash::Coercion` - [@marshall-lee](https://github.com/marshall-lee). * [#310](https://github.com/intridea/hashie/pull/310): Fixed `Hashie::Extensions::SafeAssignment` bug with private methods - [@marshall-lee](https://github.com/marshall-lee). + +### Miscellaneous + * [#313](https://github.com/intridea/hashie/pull/313): Restrict pending spec to only Ruby versions 2.2.0-2.2.2 - [@pboling](https://github.com/pboling). * [#315](https://github.com/intridea/hashie/pull/315): Default `bin/` scripts: `console` and `setup` - [@pboling](https://github.com/pboling). -## 3.4.2 (6/2/2015) +## [3.4.2] - 2015-06-02 + +[3.4.2]: https://github.com/intridea/hashie/compare/v3.4.1...v3.4.2 + +### Added -* [#292](https://github.com/intridea/hashie/pull/292): Removed `Mash#id` and `Mash#type` - [@jrochkind](https://github.com/jrochkind). * [#297](https://github.com/intridea/hashie/pull/297): Extracted `Trash`'s behavior into a new `Dash::PropertyTranslation` extension - [@michaelherold](https://github.com/michaelherold). -## 3.4.1 (3/31/2015) +### Removed + +* [#292](https://github.com/intridea/hashie/pull/292): Removed `Mash#id` and `Mash#type` - [@jrochkind](https://github.com/jrochkind). + +## [3.4.1] - 2015-03-31 + +[3.4.1]: https://github.com/intridea/hashie/compare/v3.4.0...v3.4.1 + +### Added * [#269](https://github.com/intridea/hashie/pull/272): Added Hashie::Extensions::DeepLocate - [@msievers](https://github.com/msievers). -* [#270](https://github.com/intridea/hashie/pull/277): Fixed ArgumentError raised when using IndifferentAccess and HashWithIndifferentAccess - [@gardenofwine](https://github.com/gardenofwine). * [#281](https://github.com/intridea/hashie/pull/281): Added #reverse_merge to Mash to override ActiveSupport's version - [@mgold](https://github.com/mgold). + +### Fixed + +* [#270](https://github.com/intridea/hashie/pull/277): Fixed ArgumentError raised when using IndifferentAccess and HashWithIndifferentAccess - [@gardenofwine](https://github.com/gardenofwine). * [#282](https://github.com/intridea/hashie/pull/282): Fixed coercions in a subclass accumulating in the superclass - [@maxlinc](https://github.com/maxlinc), [@martinstreicher](https://github.com/martinstreicher). -## 3.4.0 (2/02/2015) +## [3.4.0] - 2015-02-02 + +[3.4.0]: https://github.com/intridea/hashie/compare/v3.3.2...v3.4.0 + +### Added -* [#271](https://github.com/intridea/hashie/pull/271): Added ability to define defaults based on current hash - [@gregory](https://github.com/gregory). -* [#247](https://github.com/intridea/hashie/pull/247): Fixed #stringify_keys and #symbolize_keys collision with ActiveSupport - [@bartoszkopinski](https://github.com/bartoszkopinski). -* [#249](https://github.com/intridea/hashie/pull/249): SafeAssignment will now also protect hash-style assignments - [@jrochkind](https://github.com/jrochkind). * [#251](https://github.com/intridea/hashie/pull/251): Added block support to indifferent access #fetch - [@jgraichen](https://github.com/jgraichen). * [#252](https://github.com/intridea/hashie/pull/252): Added support for conditionally required Hashie::Dash attributes - [@ccashwell](https://github.com/ccashwell). +* [#254](https://github.com/intridea/hashie/pull/254): Added public utility methods for stringify and symbolize keys - [@maxlinc](https://github.com/maxlinc). +* [#260](https://github.com/intridea/hashie/pull/260): Added block support to Extensions::DeepMerge - [@galathius](https://github.com/galathius). +* [#271](https://github.com/intridea/hashie/pull/271): Added ability to define defaults based on current hash - [@gregory](https://github.com/gregory). + +### Changed + +* [#249](https://github.com/intridea/hashie/pull/249): SafeAssignment will now also protect hash-style assignments - [@jrochkind](https://github.com/jrochkind). +* [#264](https://github.com/intridea/hashie/pull/264): Methods such as abc? return true/false with Hashie::Extensions::MethodReader - [@Zloy](https://github.com/Zloy). + +### Fixed + +* [#247](https://github.com/intridea/hashie/pull/247): Fixed #stringify_keys and #symbolize_keys collision with ActiveSupport - [@bartoszkopinski](https://github.com/bartoszkopinski). * [#256](https://github.com/intridea/hashie/pull/256): Inherit key coercions - [@Erol](https://github.com/Erol). * [#259](https://github.com/intridea/hashie/pull/259): Fixed handling of default proc values in Mash - [@Erol](https://github.com/Erol). -* [#260](https://github.com/intridea/hashie/pull/260): Added block support to Extensions::DeepMerge - [@galathius](https://github.com/galathius). -* [#254](https://github.com/intridea/hashie/pull/254): Added public utility methods for stringify and symbolize keys - [@maxlinc](https://github.com/maxlinc). * [#261](https://github.com/intridea/hashie/pull/261): Fixed bug where Dash.property modifies argument object - [@d-tw](https://github.com/d-tw). -* [#264](https://github.com/intridea/hashie/pull/264): Methods such as abc? return true/false with Hashie::Extensions::MethodReader - [@Zloy](https://github.com/Zloy). * [#269](https://github.com/intridea/hashie/pull/269): Add #extractable_options? so ActiveSupport Array#extract_options! can extract it - [@ridiculous](https://github.com/ridiculous). -## 3.3.2 (11/26/2014) +## [3.3.2] - 2014-11-26 + +[3.3.2]: https://github.com/intridea/hashie/compare/v3.3.1...v3.3.2 + +### Added -* [#233](https://github.com/intridea/hashie/pull/233): Custom error messages for required properties in Hashie::Dash subclasses - [@joss](https://github.com/joss). * [#231](https://github.com/intridea/hashie/pull/231): Added support for coercion on class type that inherit from Hash - [@gregory](https://github.com/gregory). -* [#228](https://github.com/intridea/hashie/pull/228): Made Hashie::Extensions::Parsers::YamlErbParser pass template filename to ERB - [@jperville](https://github.com/jperville). -* [#224](https://github.com/intridea/hashie/pull/224): Merging Hashie::Mash now correctly only calls the block on duplicate values - [@amysutedja](https://github.com/amysutedja). -* [#221](https://github.com/intridea/hashie/pull/221): Reduce amount of allocated objects on calls with suffixes in Hashie::Mash - [@kubum](https://github.com/kubum). +* [#233](https://github.com/intridea/hashie/pull/233): Custom error messages for required properties in Hashie::Dash subclasses - [@joss](https://github.com/joss). * [#245](https://github.com/intridea/hashie/pull/245): Added Hashie::Extensions::MethodAccessWithOverride to autoloads - [@Fritzinger](https://github.com/Fritzinger). -## 3.3.1 (8/26/2014) +### Fixed + +* [#221](https://github.com/intridea/hashie/pull/221): Reduce amount of allocated objects on calls with suffixes in Hashie::Mash - [@kubum](https://github.com/kubum). +* [#224](https://github.com/intridea/hashie/pull/224): Merging Hashie::Mash now correctly only calls the block on duplicate values - [@amysutedja](https://github.com/amysutedja). +* [#228](https://github.com/intridea/hashie/pull/228): Made Hashie::Extensions::Parsers::YamlErbParser pass template filename to ERB - [@jperville](https://github.com/jperville). + +## [3.3.1] - 2014-08-26 + +[3.3.1]: https://github.com/intridea/hashie/compare/v3.3.0...v3.3.1 + +### Added * [#183](https://github.com/intridea/hashie/pull/183): Added Mash#load with YAML file support - [@gregory](https://github.com/gregory). -* [#195](https://github.com/intridea/hashie/pull/195): Ensure that the same object is returned after injecting IndifferentAccess - [@michaelherold](https://github.com/michaelherold). -* [#201](https://github.com/intridea/hashie/pull/201): Hashie::Trash transforms can be inherited - [@fobocaster](https://github.com/fobocaster). * [#189](https://github.com/intridea/hashie/pull/189): Added Rash#fetch - [@medcat](https://github.com/medcat). -* [#200](https://github.com/intridea/hashie/pull/200): Improved coercion: primitives and error handling - [@maxlinc](https://github.com/maxlinc). * [#204](https://github.com/intridea/hashie/pull/204): Added Hashie::Extensions::MethodOverridingWriter and MethodAccessWithOverride - [@michaelherold](https://github.com/michaelherold). * [#205](http://github.com/intridea/hashie/pull/205): Added Hashie::Extensions::Mash::SafeAssignment - [@michaelherold](https://github.com/michaelherold). -* [#206](http://github.com/intridea/hashie/pull/206): Fixed stack overflow from repetitively including coercion in subclasses - [@michaelherold](https://github.com/michaelherold). -* [#207](http://github.com/intridea/hashie/pull/207): Fixed inheritance of transformations in Trash - [@fobocaster](https://github.com/fobocaster). * [#209](http://github.com/intridea/hashie/pull/209): Added Hashie::Extensions::DeepFind - [@michaelherold](https://github.com/michaelherold). + +### Fixed + * [#69](https://github.com/intridea/hashie/pull/69): Fixed regression in assigning multiple properties in Hashie::Trash - [@michaelherold](https://github.com/michaelherold), [@einzige](https://github.com/einzige), [@dblock](https://github.com/dblock). +* [#195](https://github.com/intridea/hashie/pull/195): Ensure that the same object is returned after injecting IndifferentAccess - [@michaelherold](https://github.com/michaelherold). +* [#201](https://github.com/intridea/hashie/pull/201): Hashie::Trash transforms can be inherited - [@fobocaster](https://github.com/fobocaster). +* [#200](https://github.com/intridea/hashie/pull/200): Improved coercion: primitives and error handling - [@maxlinc](https://github.com/maxlinc). +* [#206](http://github.com/intridea/hashie/pull/206): Fixed stack overflow from repetitively including coercion in subclasses - [@michaelherold](https://github.com/michaelherold). +* [#207](http://github.com/intridea/hashie/pull/207): Fixed inheritance of transformations in Trash - [@fobocaster](https://github.com/fobocaster). -## 3.2.0 (7/10/2014) +## [3.2.0] - 2014-07-10 + +[3.2.0]: https://github.com/intridea/hashie/compare/v3.1.0...v3.2.0 + +### Added -* [#164](https://github.com/intridea/hashie/pull/164), [#165](https://github.com/intridea/hashie/pull/165), [#166](https://github.com/intridea/hashie/pull/166): Fixed stack overflow when coercing mashes that contain ActiveSupport::HashWithIndifferentAccess values - [@numinit](https://github.com/numinit), [@kgrz](https://github.com/kgrz). * [#177](https://github.com/intridea/hashie/pull/177): Added support for coercing enumerables and collections - [@gregory](https://github.com/gregory). + +### Changed + * [#179](https://github.com/intridea/hashie/pull/179): Mash#values_at will convert each key before doing the lookup - [@nahiluhmot](https://github.com/nahiluhmot). * [#184](https://github.com/intridea/hashie/pull/184): Allow ranges on Rash to match all Numeric types - [@medcat](https://github.com/medcat). + +### Fixed + +* [#164](https://github.com/intridea/hashie/pull/164), [#165](https://github.com/intridea/hashie/pull/165), [#166](https://github.com/intridea/hashie/pull/166): Fixed stack overflow when coercing mashes that contain ActiveSupport::HashWithIndifferentAccess values - [@numinit](https://github.com/numinit), [@kgrz](https://github.com/kgrz). * [#187](https://github.com/intridea/hashie/pull/187): Automatically require version - [@medcat](https://github.com/medcat). * [#190](https://github.com/intridea/hashie/issues/190): Fixed `coerce_key` with `from` Trash feature and Coercion extension - [@gregory](https://github.com/gregory). * [#192](https://github.com/intridea/hashie/pull/192): Fixed StringifyKeys#stringify_keys! to recursively stringify keys of embedded ::Hash types - [@dblock](https://github.com/dblock). -## 3.1.0 (6/25/2014) +## [3.1.0] - 2014-06-25 + +[3.1.0]: https://github.com/intridea/hashie/compare/v3.0.0...v3.1.0 + +### Added + +* [#172](https://github.com/intridea/hashie/pull/172): Added Dash and Trash#update_attributes! - [@gregory](https://github.com/gregory). + +### Changed * [#169](https://github.com/intridea/hashie/pull/169): Hash#to_hash will also convert nested objects that implement to_hash - [@gregory](https://github.com/gregory). +* [#173](https://github.com/intridea/hashie/pull/173): Auto include Dash::IndifferentAccess when IndifferentAccess is included in Dash - [@gregory](https://github.com/gregory). + +### Fixed + * [#171](https://github.com/intridea/hashie/pull/171): Include Trash and Dash class name when raising `NoMethodError` - [@gregory](https://github.com/gregory). -* [#172](https://github.com/intridea/hashie/pull/172): Added Dash and Trash#update_attributes! - [@gregory](https://github.com/gregory). -* [#173](https://github.com/intridea/hashie/pull/173): Auto include Dash::IndifferentAccess when IndiferentAccess is included in Dash - [@gregory](https://github.com/gregory). * [#174](https://github.com/intridea/hashie/pull/174): Fixed `from` and `transform_with` Trash features when IndifferentAccess is included - [@gregory](https://github.com/gregory). -## 3.0.0 (6/3/2014) +## [3.0.0] - 2014-06-03 + +[3.0.0]: https://github.com/intridea/hashie/compare/v2.1.2...v3.0.0 **Note:** This version introduces several backward incompatible API changes. See [UPGRADING](UPGRADING.md) for details. -* [#150](https://github.com/intridea/hashie/pull/159): Handle nil intermediate object on deep fetch - [@stephenaument](https://github.com/stephenaument). -* [#146](https://github.com/intridea/hashie/issues/146): Mash#respond_to? inconsistent with #method_missing and does not respond to #permitted? - [@dblock](https://github.com/dblock). +### Added + +* [#149](https://github.com/intridea/hashie/issues/149): Allow IgnoreUndeclared and DeepMerge to be used with undeclared properties - [@jhaesus](https://github.com/jhaesus). + +### Changed + * [#152](https://github.com/intridea/hashie/pull/152): Do not convert keys to String in Hashie::Dash and Hashie::Trash, use Hashie::Extensions::Dash::IndifferentAccess to achieve backward compatible behavior - [@dblock](https://github.com/dblock). * [#152](https://github.com/intridea/hashie/pull/152): Do not automatically stringify keys in Hashie::Hash#to_hash, pass `:stringify_keys` to achieve backward compatible behavior - [@dblock](https://github.com/dblock). + +### Fixed + +* [#146](https://github.com/intridea/hashie/issues/146): Mash#respond_to? inconsistent with #method_missing and does not respond to #permitted? - [@dblock](https://github.com/dblock). * [#148](https://github.com/intridea/hashie/pull/148): Consolidated Hashie::Hash#stringify_keys implementation - [@dblock](https://github.com/dblock). -* [#149](https://github.com/intridea/hashie/issues/149): Allow IgnoreUndeclared and DeepMerge to be used with undeclared properties - [@jhaesus](https://github.com/jhaesus). +* [#159](https://github.com/intridea/hashie/pull/159): Handle nil intermediate object on deep fetch - [@stephenaument](https://github.com/stephenaument). + +## [2.1.2] - 2014-05-12 + +[2.1.2]: https://github.com/intridea/hashie/compare/v2.1.1...v2.1.2 -## 2.1.2 (5/12/2014) +### Changed * [#169](https://github.com/intridea/hashie/pull/169): Hash#to_hash will also convert nested objects that implement `to_hash` - [@gregory](https://github.com/gregory). -## 2.1.1 (4/12/2014) +## [2.1.1] - 2014-04-12 +[2.1.1]: https://github.com/intridea/hashie/compare/v2.1.0...v2.1.1 + +### Fixed + +* [#131](https://github.com/intridea/hashie/pull/131): Added IgnoreUndeclared, an extension to silently ignore undeclared properties at intialization - [@righi](https://github.com/righi). +* [#138](https://github.com/intridea/hashie/pull/138): Added Hashie::Rash, a hash whose keys can be regular expressions or ranges - [@epitron](https://github.com/epitron). * [#144](https://github.com/intridea/hashie/issues/144): Fixed regression invoking `to_hash` with no parameters - [@mbleigh](https://github.com/mbleigh). -## 2.1.0 (4/6/2014) +## [2.1.0] - 2014-04-06 + +[2.1.0]: https://github.com/intridea/hashie/compare/v2.0.5...v2.1.0 + +### Added * [#134](https://github.com/intridea/hashie/pull/134): Add deep_fetch extension for nested access - [@tylerdooling](https://github.com/tylerdooling). + +### Changed + +* [#89](https://github.com/intridea/hashie/issues/89): Do not respond to every method with suffix in Hashie::Mash, fixes Rails strong_parameters - [@Maxim-Filimonov](https://github.com/Maxim-Filimonov). + +### Removed + * Removed support for Ruby 1.8.7 - [@dblock](https://github.com/dblock). -* Ruby style now enforced with Rubocop - [@dblock](https://github.com/dblock). -* [#138](https://github.com/intridea/hashie/pull/138): Added Hashie::Rash, a hash whose keys can be regular expressions or ranges - [@epitron](https://github.com/epitron). -* [#131](https://github.com/intridea/hashie/pull/131): Added IgnoreUndeclared, an extension to silently ignore undeclared properties at intialization - [@righi](https://github.com/righi). * [#136](https://github.com/intridea/hashie/issues/136): Removed Hashie::Extensions::Structure - [@markiz](https://github.com/markiz). -* [#107](https://github.com/intridea/hashie/pull/107): Fixed excessive value conversions, poor performance of deep merge in Hashie::Mash - [@davemitchell](https://github.com/dblock), [@dblock](https://github.com/dblock). + +### Fixed + * [#69](https://github.com/intridea/hashie/issues/69): Fixed assigning multiple properties in Hashie::Trash - [@einzige](https://github.com/einzige). +* [#99](https://github.com/intridea/hashie/issues/99): Hash#deep_merge raises errors when it encounters integers - [@defsprite](https://github.com/defsprite). * [#100](https://github.com/intridea/hashie/pull/100): IndifferentAccess#store will respect indifference - [@jrochkind](https://github.com/jrochkind). * [#103](https://github.com/intridea/hashie/pull/103): Fixed support for Hashie::Dash properties that end in bang - [@thedavemarshall](https://github.com/thedavemarshall). -* [89](https://github.com/intridea/hashie/issues/89): Do not respond to every method with suffix in Hashie::Mash, fixes Rails strong_parameters - [@Maxim-Filimonov](https://github.com/Maxim-Filimonov). +* [#107](https://github.com/intridea/hashie/pull/107): Fixed excessive value conversions, poor performance of deep merge in Hashie::Mash - [@davemitchell](https://github.com/dblock), [@dblock](https://github.com/dblock). * [#110](https://github.com/intridea/hashie/pull/110): Correctly use Hash#default from Mash#method_missing - [@ryansouza](https://github.com/ryansouza). -* [#120](https://github.com/intridea/hashie/pull/120): Pass options to recursive to_hash calls - [@pwillett](https://github.com/pwillett). -* [#113](https://github.com/intridea/hashie/issues/113): Fixed Hash#merge with Hashie::Dash - [@spencer1248](https://github.com/spencer1248). -* [#99](https://github.com/intridea/hashie/issues/99): Hash#deep_merge raises errors when it encounters integers - [@defsprite](https://github.com/defsprite). -* [#133](https://github.com/intridea/hashie/pull/133): Fixed Hash##to_hash with symbolize_keys - [@mhuggins](https://github.com/mhuggins). -* [#130](https://github.com/intridea/hashie/pull/130): IndifferentAccess now works without MergeInitializer - [@npj](https://github.com/npj). * [#111](https://github.com/intridea/hashie/issues/111): Trash#translations correctly maps original to translated names - [@artm](https://github.com/artm). +* [#113](https://github.com/intridea/hashie/issues/113): Fixed Hash#merge with Hashie::Dash - [@spencer1248](https://github.com/spencer1248). +* [#120](https://github.com/intridea/hashie/pull/120): Pass options to recursive to_hash calls - [@pwillett](https://github.com/pwillett). * [#129](https://github.com/intridea/hashie/pull/129): Added Trash#permitted_input_keys and inverse_translations - [@artm](https://github.com/artm). +* [#130](https://github.com/intridea/hashie/pull/130): IndifferentAccess now works without MergeInitializer - [@npj](https://github.com/npj). +* [#133](https://github.com/intridea/hashie/pull/133): Fixed Hash##to_hash with symbolize_keys - [@mhuggins](https://github.com/mhuggins). -## 2.0.5 +### Miscellaneous + +* Ruby style now enforced with Rubocop - [@dblock](https://github.com/dblock). + +## [2.0.5] - 2013-05-10 + +[2.0.5]: https://github.com/intridea/hashie/compare/v2.0.4...v2.0.5 + +### Fixed * [#96](https://github.com/intridea/hashie/pull/96): Make coercion work better with non-symbol keys in Hashie::Mash - [@wapcaplet](https://github.com/wapcaplet). -## 2.0.4 +## [2.0.4] - 2013-04-24 + +[2.0.4]: https://github.com/intridea/hashie/compare/v2.0.3...v2.0.4 + +### Fixed + +* [#94](https://github.com/intridea/hashie/pull/94): Make #fetch method consistent with normal Hash - [@markiz](https://github.com/markiz). + +### Miscellaneous -* [#04](https://github.com/intridea/hashie/pull/94): Make #fetch method consistent with normal Hash - [@markiz](https://github.com/markiz). * [#90](https://github.com/intridea/hashie/pull/90): Various doc tweaks - [@craiglittle](https://github.com/craiglittle). -## 2.0.3 +## [2.0.3] - 2013-03-18 + +[2.0.3]: https://github.com/intridea/hashie/compare/v2.0.2...v2.0.3 + +### Fixed -* [#88](https://github.com/intridea/hashie/pull/88): Hashie::Mash.new(abc: true).respond_to?(:abc?) works - [@7even](https://github.com/7even). * [#68](https://github.com/intridea/hashie/pull/68): Fix #replace - [@jimeh](https://github.com/jimeh). +* [#88](https://github.com/intridea/hashie/pull/88): Hashie::Mash.new(abc: true).respond_to?(:abc?) works - [@7even](https://github.com/7even). + +## [2.0.2] - 2013-02-26 + +[2.0.2]: https://github.com/intridea/hashie/compare/v2.0.1...v2.0.2 -## 2.0.2 +### Fixed * [#85](https://github.com/intridea/hashie/pull/85): adding symbolize_keys back to to_hash - [@cromulus](https://github.com/cromulus). -## 2.0.1 +## [2.0.1] - 2013-02-26 + +[2.0.1]: https://github.com/intridea/hashie/compare/v2.0.0...v2.0.1 + +### Removed * [#81](https://github.com/intridea/hashie/pull/81): remove Mash#object_id override - [@matschaffer](https://github.com/matschaffer). + +### Miscellaneous + * Gem cleanup: removed VERSION, Gemfile.lock [@jch](https://github.com/jch), [@mbleigh](https://github.com/mbleigh). -## 2.0.0 +## [2.0.0] - 2013-02-16 + +[2.0.0]: https://github.com/intridea/hashie/compare/v1.2.0...v2.0.0 + +### Added + +* [#41](https://github.com/intridea/hashie/pull/41): DeepMerge extension - [@nashby](https://github.com/nashby). +* [#78](https://github.com/intridea/hashie/pull/78): Merge and update accepts a block - [@jch](https://github.com/jch). + +### Changed -* [#72](https://github.com/intridea/hashie/pull/72): Updated gemspec with license info - [@jordimassaguerpla](https://github.com/jordimassaguerpla). -* [#27](https://github.com/intridea/hashie/pull/27): Initialized with merge coerces values - [@mattfawcett](https://github.com/mattfawcett). * [#28](https://github.com/intridea/hashie/pull/28): Hashie::Extensions::Coercion coerce_keys takes arguments - [@mattfawcett](https://github.com/mattfawcett). +* [#77](https://github.com/intridea/hashie/pull/77): Remove id, type, and object_id as special allowable keys [@jch](https://github.com/jch). + +### Fixed + +* [#27](https://github.com/intridea/hashie/pull/27): Initialized with merge coerces values - [@mattfawcett](https://github.com/mattfawcett). * [#39](https://github.com/intridea/hashie/pull/39): Trash removes translated values on initialization - [@sleverbor](https://github.com/sleverbor). -* [#66](https://github.com/intridea/hashie/pull/66): Mash#fetch works with symbol or string keys - [@arthwood](https://github.com/arthwood). * [#49](https://github.com/intridea/hashie/pull/49): Hashie::Hash inherits from ::Hash to avoid ambiguity - [@meh](https://github.com/meh), [@orend](https://github.com/orend). * [#62](https://github.com/intridea/hashie/pull/62): update respond_to? method signature to match ruby core definition - [@dlupu](https://github.com/dlupu). -* [#41](https://github.com/intridea/hashie/pull/41): DeepMerge extension - [@nashby](https://github.com/nashby). * [#63](https://github.com/intridea/hashie/pull/63): Dash defaults are dup'ed before assigned - [@ohrite](https://github.com/ohrite). -* [#77](https://github.com/intridea/hashie/pull/77): Remove id, type, and object_id as special allowable keys [@jch](https://github.com/jch). -* [#78](https://github.com/intridea/hashie/pull/78): Merge and update accepts a block - [@jch](https://github.com/jch). +* [#66](https://github.com/intridea/hashie/pull/66): Mash#fetch works with symbol or string keys - [@arthwood](https://github.com/arthwood). + +### Miscellaneous + +* [#72](https://github.com/intridea/hashie/pull/72): Updated gemspec with license info - [@jordimassaguerpla](https://github.com/jordimassaguerpla). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 92454c4b..060d5b78 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -52,7 +52,17 @@ Document any external behavior in the [README](README.md). #### Update Changelog -Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Make it look like every other line, including your name and link to your Github account. +Add a line to [CHANGELOG](CHANGELOG.md) under *Unreleased*. Make it look like every other line, including your name and link to your Github account. + +There are several categorizations of changes that you can choose from. Add your line to the appropriate section, following these conventions: + +* **Added** - When you add a new behavior to any class or module (or add a new extension) that does not break backwards compatibility, you should mark it as "added". This is generally a fully new behavior that does not touch any pre-existing public API. Changes here require a MINOR version bump, following the Semantic Versioning specification. +* **Changed** - You should mark any change to the behavior of a public API on any class or module as "changed". Changes here require a MAJOR version bump, following the Semantic Versioning specification. +* **Deprecated** - Any time you deprecate part of the public API on any class or module you should mark the change as "deprecated". Deprecated behavior will be removed in the next MAJOR version bump, but should be left in until then. Changes here require a MINOR version bump, following the Semantic Versioning specification. +* **Removed** - You should mark any behavior that you removed from a public API on any class or module as "removed". Changes here require a MAJOR version bump, following the Semantic Versioning specification. +* **Fixed** - Any time you fix a bug you should mark as "fixed". Changes here require a PATCH version bump. +* **Security** - You should mark any security issue that you fix as "security". Changes here require a PATCH version bump. +* **Miscellaneous** - Mark any other changes you make (i.e. documentation updates, test harness changes, etc.) as "miscellaneous". Changes here require a PATCH version bump. #### Commit Changes diff --git a/RELEASING.md b/RELEASING.md index 7972506d..b6048754 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -2,7 +2,7 @@ There're no particular rules about when to release Hashie. Release bug fixes frequenty, features not so frequently and breaking API changes rarely. -### Release +## Release Run tests, check that all tests succeed locally. @@ -13,10 +13,15 @@ bundle exec rake Check that the last build succeeded in [Travis CI](https://travis-ci.org/intridea/hashie) for all supported platforms. -Increment the version, modify [lib/hashie/version.rb](lib/hashie/version.rb). +### Check Next Version -* Increment the third number (minor version) if the release has bug fixes and/or very minor features, only (eg. change `0.5.1` to `0.5.2`). -* Increment the second number (patch version) if the release contains major features or breaking API changes (eg. change `0.5.1` to `0.6.0`). +Increment the version, modify [lib/hashie/version.rb](lib/hashie/version.rb). [Changelog](CHANGELOG.md) entries should be helpfully categorized to assist in picking the next version number. + +* Increment the third number (minor version) if the release has bug fixes and/or very minor features, only (eg. change `0.5.1` to `0.5.2`). These should be in the "Fixed", "Security", or "Miscellaneous" categories in the change log. +* Increment the second number (patch version) if the release contains major features or breaking API changes (eg. change `0.5.1` to `0.6.0`). These should be in the "Added" or "Deprecated" categories in the change log. +* Increment the first number (major version) if the release has any changed or removed behavior on public APIs (eg. change `0.5.1` to `1.0.0`). These should be in the "Changed" or "Removed" categories in the change log. + +### Modify the Readme Modify the "Stable Release" section in [README.md](README.md). Change the text to reflect that this is going to be the documentation for a stable release. Remove references to the previous release of Hashie. Keep the file open, you'll have to undo this change after the release. @@ -26,14 +31,19 @@ Modify the "Stable Release" section in [README.md](README.md). Change the text t You're reading the documentation for the stable release of Hashie, 3.3.0. ``` -Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version. +### Modify the Changelog + +Change "Unreleased" in [CHANGELOG.md](CHANGELOG.md) to the new version. ```markdown -3.3.0 (8/25/2014) -================= +## [3.3.0] - 2014-08-25 + +[3.3.0]: https://github.com/intridea/hashie/compare/v..v ``` -Remove the line with "Your contribution here.", since there will be no more contributions to this release. +Replace `` and `` with the last and new-to-be-released versions to set up the compare view on Github. + +Remove any sections that only have "Nothing yet." underneath them. Commit your changes. @@ -43,6 +53,8 @@ git commit -m "Preparing for release, 3.3.0." git push origin master ``` +### Push to RubyGems.org + Release. ```sh @@ -54,7 +66,7 @@ Pushed git commits and tags. Pushed hashie 3.3.0 to rubygems.org. ``` -### Prepare for the Next Version +## Prepare for the Next Version Modify the "Stable Release" section in [README.md](README.md). Change the text to reflect that this is going to be the next release. @@ -65,15 +77,44 @@ You're reading the documentation for the next release of Hashie, which should be The current stable release is [3.3.0](https://github.com/intridea/hashie/blob/v3.3.0/README.md). ``` -Add the next release to [CHANGELOG.md](CHANGELOG.md). +Add new "Unreleased" section to [CHANGELOG.md](CHANGELOG.md) using this template: ```markdown -Next Release -============ +## [Unreleased][unreleased] + +[unreleased]: https://github.com/intridea/hashie/compare/v...master + +### Added + +* Nothing yet. + +### Changed + +* Nothing yet. -* Your contribution here. +### Deprecated + +* Nothing yet. + +### Removed + +* Nothing yet. + +### Fixed + +* Nothing yet. + +### Security + +* Nothing yet. + +### Miscellanous + +* Nothing yet. ``` +Replace `` with the newly released versions to set up the compare view on Github. + Commit your changes. ```sh From 460a0e6cb9b2116e1579cc6b89f8c152156b6221 Mon Sep 17 00:00:00 2001 From: Prayag Verma Date: Sat, 6 Feb 2016 19:28:47 +0530 Subject: [PATCH 05/13] README: fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found a spelling mistake - includeable → includable --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cd7532c3..346d3da7 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ You're reading the documentation for the next release of Hashie, which should be ## Hash Extensions -The library is broken up into a number of atomically includeable Hash extension modules as described below. This provides maximum flexibility for users to mix and match functionality while maintaining feature parity with earlier versions of Hashie. +The library is broken up into a number of atomically includable Hash extension modules as described below. This provides maximum flexibility for users to mix and match functionality while maintaining feature parity with earlier versions of Hashie. Any of the extensions listed below can be mixed into a class by `include`-ing `Hashie::Extensions::ExtensionName`. From 1433295e22c49db5851d16b5aef7b590a3bf2d40 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sat, 6 Feb 2016 23:41:55 +0900 Subject: [PATCH 06/13] Convert Mash keys for #dig --- .rubocop_todo.yml | 2 +- CHANGELOG.md | 2 +- lib/hashie/mash.rb | 6 ++++++ spec/hashie/mash_spec.rb | 11 +++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index befd2ab7..e027ee0d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -18,7 +18,7 @@ Metrics/AbcSize: # Offense count: 2 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 171 + Max: 176 # Offense count: 6 Metrics/CyclomaticComplexity: diff --git a/CHANGELOG.md b/CHANGELOG.md index d1c798cb..468ca545 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ scheme are considered to be bugs. ### Added -* Nothing yet. +* [#349](https://github.com/intridea/hashie/pull/349): Convert `Hashie::Mash#dig` arguments for Ruby 2.3.0 - [@k0kubun](https://github.com/k0kubun). ### Changed diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb index 8dff97e7..a960d3d7 100644 --- a/lib/hashie/mash.rb +++ b/lib/hashie/mash.rb @@ -250,6 +250,12 @@ def reverse_merge(other_hash) self.class.new(other_hash).merge(self) end + if RUBY_VERSION >= '2.3.0' + def dig(*keys) + super(*keys.map { |key| convert_key(key) }) + end + end + protected def method_name_and_suffix(method_name) diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb index c1420483..9aac1adc 100644 --- a/spec/hashie/mash_spec.rb +++ b/spec/hashie/mash_spec.rb @@ -686,4 +686,15 @@ class SubMash < Hashie::Mash end end end + + if RUBY_VERSION >= '2.3.0' + describe '#dig' do + subject { described_class.new(a: { b: 1 }) } + + it 'accepts both string and symbol as key' do + expect(subject.dig(:a, :b)).to eq(1) + expect(subject.dig('a', 'b')).to eq(1) + end + end + end end From c0c85a68ecb88af00564f74af2889386975bb5a7 Mon Sep 17 00:00:00 2001 From: Vladimir Kochnev Date: Tue, 24 Nov 2015 07:13:24 +0300 Subject: [PATCH 07/13] Stringified translations wasn't working in IgnoreUndeclared. Translation from `:symbol` and translation from `'string'` are different translations. No need in coercion to symbol or some other coercions. --- CHANGELOG.md | 1 + lib/hashie/extensions/ignore_undeclared.rb | 2 +- spec/hashie/extensions/ignore_undeclared_spec.rb | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1c798cb..06b4c9fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ scheme are considered to be bugs. * [#319](https://github.com/intridea/hashie/pull/319): Fix a regression from 3.4.1 where `Hashie::Extensions::DeepFind` is no longer indifference-aware - [@michaelherold](https://github.com/michaelherold). * [#322](https://github.com/intridea/hashie/pull/322): Fixed `reverse_merge` issue with `Mash` subclasses - [@marshall-lee](https://github.com/marshall-lee). * [#346](https://github.com/intridea/hashie/pull/346): Fixed `merge` breaking indifferent access - [@docwhat](https://github.com/docwhat), [@michaelherold](https://github.com/michaelherold). +* [#350](https://github.com/intridea/hashie/pull/350): Fixed from string translations used with `IgnoreUndeclared` - [@marshall-lee](https://github.com/marshall-lee). ### Security diff --git a/lib/hashie/extensions/ignore_undeclared.rb b/lib/hashie/extensions/ignore_undeclared.rb index e16e0a47..ce113fe5 100644 --- a/lib/hashie/extensions/ignore_undeclared.rb +++ b/lib/hashie/extensions/ignore_undeclared.rb @@ -31,7 +31,7 @@ module Extensions module IgnoreUndeclared def initialize_attributes(attributes) attributes.each_pair do |att, value| - next unless self.class.property?(att) || (self.class.respond_to?(:translations) && self.class.translations.include?(att.to_sym)) + next unless self.class.property?(att) || (self.class.respond_to?(:translations) && self.class.translations.include?(att)) self[att] = value end if attributes end diff --git a/spec/hashie/extensions/ignore_undeclared_spec.rb b/spec/hashie/extensions/ignore_undeclared_spec.rb index f207acaf..948a8342 100644 --- a/spec/hashie/extensions/ignore_undeclared_spec.rb +++ b/spec/hashie/extensions/ignore_undeclared_spec.rb @@ -6,6 +6,7 @@ class ForgivingTrash < Hashie::Trash include Hashie::Extensions::IgnoreUndeclared property :city property :state, from: :provence + property :str_state, from: 'str_provence' end subject { ForgivingTrash } @@ -19,7 +20,7 @@ class ForgivingTrash < Hashie::Trash end it 'works with translated properties (with string keys)' do - expect(subject.new(provence: 'Ontario').state).to eq('Ontario') + expect(subject.new('str_provence' => 'Ontario').str_state).to eq('Ontario') end it 'requires properties to be declared on assignment' do From c4fc51d48f92ab2dac1e0d13e152be2e1a1b3b28 Mon Sep 17 00:00:00 2001 From: Vladimir Kochnev Date: Sun, 7 Feb 2016 05:42:30 +0300 Subject: [PATCH 08/13] Refactor IgnoreUndeclared#initialize_attributes. --- lib/hashie/extensions/ignore_undeclared.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/hashie/extensions/ignore_undeclared.rb b/lib/hashie/extensions/ignore_undeclared.rb index ce113fe5..9b506dd9 100644 --- a/lib/hashie/extensions/ignore_undeclared.rb +++ b/lib/hashie/extensions/ignore_undeclared.rb @@ -30,10 +30,13 @@ module Extensions # p.email # => NoMethodError module IgnoreUndeclared def initialize_attributes(attributes) + return unless attributes + klass = self.class + translations = klass.respond_to?(:translations) && klass.translations attributes.each_pair do |att, value| - next unless self.class.property?(att) || (self.class.respond_to?(:translations) && self.class.translations.include?(att)) + next unless klass.property?(att) || (translations && translations.include?(att)) self[att] = value - end if attributes + end end def property_exists?(property) From 589d938128d4e678a6ff02a002a33ae3776d3dc2 Mon Sep 17 00:00:00 2001 From: camelmasa Date: Tue, 23 Feb 2016 12:21:09 +0900 Subject: [PATCH 09/13] Fix too fexible regex --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 346d3da7..a99d2071 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ class Tweet < Hash coerce_key :retweeted, ->(v) do case v when String - return !!(v =~ /^(true|t|yes|y|1)$/i) + return !!(v =~ /\A(true|t|yes|y|1)\z/i) when Numeric return !v.to_i.zero? else From 00e3a49e2953e954d54ea5f8eb1e33e6a96b2f06 Mon Sep 17 00:00:00 2001 From: camelmasa Date: Tue, 23 Feb 2016 12:24:04 +0900 Subject: [PATCH 10/13] Omit `return' --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a99d2071..9b6d6fa2 100644 --- a/README.md +++ b/README.md @@ -135,11 +135,11 @@ class Tweet < Hash coerce_key :retweeted, ->(v) do case v when String - return !!(v =~ /\A(true|t|yes|y|1)\z/i) + !!(v =~ /\A(true|t|yes|y|1)\z/i) when Numeric - return !v.to_i.zero? + !v.to_i.zero? else - return v == true + v == true end end end From 3cfa2b3e080dcbb839504d8d35c35ed47d9fafe3 Mon Sep 17 00:00:00 2001 From: dblock Date: Fri, 29 Apr 2016 12:33:09 -0400 Subject: [PATCH 11/13] Preparing for release, 3.4.4. --- CHANGELOG.md | 24 ++---------------------- README.md | 2 +- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0638094..792b1f09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,26 +6,14 @@ scheme are considered to be bugs. [semver]: http://semver.org/spec/v2.0.0.html -## [Unreleased][unreleased] +## [3.4.4] - 2016-04-29 -[unreleased]: https://github.com/intridea/hashie/compare/v3.4.3...master +[3.4.4]: https://github.com/intridea/hashie/compare/v3.4.3...v3.4.4 ### Added * [#349](https://github.com/intridea/hashie/pull/349): Convert `Hashie::Mash#dig` arguments for Ruby 2.3.0 - [@k0kubun](https://github.com/k0kubun). -### Changed - -* Nothing yet. - -### Deprecated - -* Nothing yet. - -### Removed - -* Nothing yet. - ### Fixed * [#240](https://github.com/intridea/hashie/pull/240): Fixed nesting twice with Clash keys - [@bartoszkopinski](https://github.com/bartoszkopinski). @@ -35,14 +23,6 @@ scheme are considered to be bugs. * [#346](https://github.com/intridea/hashie/pull/346): Fixed `merge` breaking indifferent access - [@docwhat](https://github.com/docwhat), [@michaelherold](https://github.com/michaelherold). * [#350](https://github.com/intridea/hashie/pull/350): Fixed from string translations used with `IgnoreUndeclared` - [@marshall-lee](https://github.com/marshall-lee). -### Security - -* Nothing yet. - -### Miscellanous - -* Nothing yet. - ## [3.4.3] - 2015-10-25 [3.4.3]: https://github.com/intridea/hashie/compare/v3.4.2...v3.4.3 diff --git a/README.md b/README.md index 9b6d6fa2..98f62cf8 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ $ gem install hashie ## Upgrading -You're reading the documentation for the next release of Hashie, which should be 3.4.4. Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version. The current stable release is [3.4.3](https://github.com/intridea/hashie/blob/v3.4.3/README.md). +You're reading the documentation for the stable release of Hashie, 3.4.4. Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version. ## Hash Extensions From fb186400247779f90aacf23fa2cde044cbac387c Mon Sep 17 00:00:00 2001 From: dblock Date: Fri, 29 Apr 2016 12:35:13 -0400 Subject: [PATCH 12/13] Preparing for the next development iteration, 3.4.5. --- CHANGELOG.md | 32 ++++++++++++++++++++++++++++++++ README.md | 2 +- RELEASING.md | 4 +++- lib/hashie/version.rb | 2 +- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 792b1f09..0bb43a63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,38 @@ scheme are considered to be bugs. [semver]: http://semver.org/spec/v2.0.0.html +## [Unreleased][unreleased] + +[unreleased]: https://github.com/intridea/hashie/compare/v3.4.4...master + +### Added + +* Nothing yet. + +### Changed + +* Nothing yet. + +### Deprecated + +* Nothing yet. + +### Removed + +* Nothing yet. + +### Fixed + +* Nothing yet. + +### Security + +* Nothing yet. + +### Miscellanous + +* Nothing yet. + ## [3.4.4] - 2016-04-29 [3.4.4]: https://github.com/intridea/hashie/compare/v3.4.3...v3.4.4 diff --git a/README.md b/README.md index 98f62cf8..7c471f20 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ $ gem install hashie ## Upgrading -You're reading the documentation for the stable release of Hashie, 3.4.4. Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version. +You're reading the documentation for the next release of Hashie, which should be 3.4.5. Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version. The current stable release is [3.4.4](https://github.com/intridea/hashie/blob/v3.4.4/README.md). ## Hash Extensions diff --git a/RELEASING.md b/RELEASING.md index b6048754..d669dd09 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -115,10 +115,12 @@ Add new "Unreleased" section to [CHANGELOG.md](CHANGELOG.md) using this template Replace `` with the newly released versions to set up the compare view on Github. +Increment the minor version, modify [lib/hashie/version.rb](lib/hashie/version.rb). + Commit your changes. ```sh git add CHANGELOG.md README.md -git commit -m "Preparing for next release." +git commit -m "Preparing for next development iteration, 3.3.1." git push origin master ``` diff --git a/lib/hashie/version.rb b/lib/hashie/version.rb index 4517075f..9969583d 100644 --- a/lib/hashie/version.rb +++ b/lib/hashie/version.rb @@ -1,3 +1,3 @@ module Hashie - VERSION = '3.4.4' + VERSION = '3.4.5' end From fa524096f33ebfb7ffadaf3594dddda5fd69ffb4 Mon Sep 17 00:00:00 2001 From: jonathan schatz Date: Tue, 31 May 2016 15:53:33 -0700 Subject: [PATCH 13/13] Fix support for Array#dig --- .rubocop_todo.yml | 14 +++++++------- CHANGELOG.md | 2 +- lib/hashie.rb | 6 ++++++ lib/hashie/array.rb | 11 +++++++++++ lib/hashie/extensions/array/pretty_inspect.rb | 19 +++++++++++++++++++ lib/hashie/extensions/ruby_version_check.rb | 15 +++++++++++++++ lib/hashie/mash.rb | 6 +++++- spec/hashie/array_spec.rb | 17 +++++++++++++++++ spec/hashie/mash_spec.rb | 11 +++++++++-- spec/spec_helper.rb | 2 ++ spec/support/ruby_version_check.rb | 5 +++++ 11 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 lib/hashie/array.rb create mode 100644 lib/hashie/extensions/array/pretty_inspect.rb create mode 100644 lib/hashie/extensions/ruby_version_check.rb create mode 100644 spec/hashie/array_spec.rb create mode 100644 spec/support/ruby_version_check.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e027ee0d..a141524d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2015-10-25 15:28:03 -0400 using RuboCop version 0.34.2. +# on 2016-06-01 14:51:33 -0700 using RuboCop version 0.34.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -18,23 +18,23 @@ Metrics/AbcSize: # Offense count: 2 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 176 + Max: 179 # Offense count: 6 Metrics/CyclomaticComplexity: Max: 11 -# Offense count: 218 +# Offense count: 231 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 170 -# Offense count: 17 +# Offense count: 16 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 28 -# Offense count: 6 +# Offense count: 5 Metrics/PerceivedComplexity: Max: 10 @@ -43,7 +43,7 @@ Style/CaseEquality: Exclude: - 'lib/hashie/hash.rb' -# Offense count: 27 +# Offense count: 32 # Configuration parameters: Exclude. Style/Documentation: Enabled: false @@ -57,7 +57,7 @@ Style/DoubleNegation: - 'lib/hashie/mash.rb' - 'spec/hashie/extensions/coercion_spec.rb' -# Offense count: 3 +# Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues. Style/HashSyntax: diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bb43a63..42e2a38a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,7 @@ scheme are considered to be bugs. ### Fixed -* Nothing yet. +* [#358](https://github.com/intridea/hashie/pull/358): Fix support for Array#dig - [@modosc](https://github.com/modosc/). ### Security diff --git a/lib/hashie.rb b/lib/hashie.rb index 59a7c25e..5346b61d 100644 --- a/lib/hashie.rb +++ b/lib/hashie.rb @@ -7,6 +7,7 @@ module Hashie autoload :Mash, 'hashie/mash' autoload :Trash, 'hashie/trash' autoload :Rash, 'hashie/rash' + autoload :Array, 'hashie/array' module Extensions autoload :Coercion, 'hashie/extensions/coercion' @@ -27,6 +28,7 @@ module Extensions autoload :KeyConversion, 'hashie/extensions/key_conversion' autoload :MethodAccessWithOverride, 'hashie/extensions/method_access' autoload :StrictKeyAccess, 'hashie/extensions/strict_key_access' + autoload :RubyVersionCheck, 'hashie/extensions/ruby_version_check' module Parsers autoload :YamlErbParser, 'hashie/extensions/parsers/yaml_erb_parser' @@ -41,6 +43,10 @@ module Dash module Mash autoload :SafeAssignment, 'hashie/extensions/mash/safe_assignment' end + + module Array + autoload :PrettyInspect, 'hashie/extensions/array/pretty_inspect' + end end class << self diff --git a/lib/hashie/array.rb b/lib/hashie/array.rb new file mode 100644 index 00000000..b0dca8b5 --- /dev/null +++ b/lib/hashie/array.rb @@ -0,0 +1,11 @@ +module Hashie + class Array < ::Array + include Hashie::Extensions::Array::PrettyInspect + include Hashie::Extensions::RubyVersionCheck + with_minimum_ruby('2.3.0') do + def dig(*indexes) + super(*indexes.map { |idx| Integer(idx) }) + end + end + end +end diff --git a/lib/hashie/extensions/array/pretty_inspect.rb b/lib/hashie/extensions/array/pretty_inspect.rb new file mode 100644 index 00000000..48ce119b --- /dev/null +++ b/lib/hashie/extensions/array/pretty_inspect.rb @@ -0,0 +1,19 @@ +module Hashie + module Extensions + module Array + module PrettyInspect + def self.included(base) + base.send :alias_method, :array_inspect, :inspect + base.send :alias_method, :inspect, :hashie_inspect + end + + def hashie_inspect + ret = "#<#{self.class} [" + ret << to_a.map(&:inspect).join(', ') + ret << ']>' + ret + end + end + end + end +end diff --git a/lib/hashie/extensions/ruby_version_check.rb b/lib/hashie/extensions/ruby_version_check.rb new file mode 100644 index 00000000..e1f70d41 --- /dev/null +++ b/lib/hashie/extensions/ruby_version_check.rb @@ -0,0 +1,15 @@ +module Hashie + module Extensions + module RubyVersionCheck + def self.included(base) + base.extend ClassMethods + end + + module ClassMethods + def with_minimum_ruby(version) + yield if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new(version) + end + end + end + end +end diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb index a960d3d7..0cae7ead 100644 --- a/lib/hashie/mash.rb +++ b/lib/hashie/mash.rb @@ -1,4 +1,5 @@ require 'hashie/hash' +require 'hashie/array' module Hashie # Mash allows you to create pseudo-objects that have method-like @@ -56,6 +57,7 @@ module Hashie # class Mash < Hash include Hashie::Extensions::PrettyInspect + include Hashie::Extensions::RubyVersionCheck ALLOWED_SUFFIXES = %w(? ! = _) @@ -250,7 +252,7 @@ def reverse_merge(other_hash) self.class.new(other_hash).merge(self) end - if RUBY_VERSION >= '2.3.0' + with_minimum_ruby('2.3.0') do def dig(*keys) super(*keys.map { |key| convert_key(key) }) end @@ -287,6 +289,8 @@ def convert_value(val, duping = false) #:nodoc: self.class.new(val) when Array val.map { |e| convert_value(e) } + when ::Array + Array.new(val.map { |e| convert_value(e) }) else val end diff --git a/spec/hashie/array_spec.rb b/spec/hashie/array_spec.rb new file mode 100644 index 00000000..6c20a835 --- /dev/null +++ b/spec/hashie/array_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Array do + with_minimum_ruby('2.3.0') do + describe '#dig' do + let(:array) { Hashie::Array.new([:a, :b, :c]) } + + it 'works with a string index' do + expect(array.dig('0')).to eq(:a) + end + + it 'works with a numeric index' do + expect(array.dig(1)).to eq(:b) + end + end + end +end diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb index 9aac1adc..f187d1f9 100644 --- a/spec/hashie/mash_spec.rb +++ b/spec/hashie/mash_spec.rb @@ -687,14 +687,21 @@ class SubMash < Hashie::Mash end end - if RUBY_VERSION >= '2.3.0' + with_minimum_ruby('2.3.0') do describe '#dig' do subject { described_class.new(a: { b: 1 }) } - it 'accepts both string and symbol as key' do expect(subject.dig(:a, :b)).to eq(1) expect(subject.dig('a', 'b')).to eq(1) end + + context 'with numeric key' do + subject { described_class.new('1' => { b: 1 }) } + it 'accepts a numeric value as key' do + expect(subject.dig(1, :b)).to eq(1) + expect(subject.dig('1', :b)).to eq(1) + end + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e1bcd13f..2cd68e3f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,8 +8,10 @@ require 'rspec' require 'hashie' require 'rspec/pending_for' +require './spec/support/ruby_version_check' RSpec.configure do |config| + config.extend RubyVersionCheck config.expect_with :rspec do |expect| expect.syntax = :expect end diff --git a/spec/support/ruby_version_check.rb b/spec/support/ruby_version_check.rb new file mode 100644 index 00000000..c3890c63 --- /dev/null +++ b/spec/support/ruby_version_check.rb @@ -0,0 +1,5 @@ +module RubyVersionCheck + def with_minimum_ruby(version) + yield if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new(version) + end +end