summaryrefslogtreecommitdiff
path: root/lib/hashie
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'dash-nil-keys' of https://github.com/michaelherold/hashie into ↵dblock2021-11-073-1/+22
|\ | | | | | | michaelherold-dash-nil-keys
| * Ensure all properties are set on exported DashMichael Herold2020-10-222-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When exporting a Dash via `#to_h` or `#to_hash`, we expect all properties to be exported whether or not they are set. However, in the change that allows codependent properties to be nilified, we regressed the behavior of exporting all properties. There is a gotcha here, which I note in the tests for the specs. For posterity, MRI does not send the `#to_hash` method to anything that subclasses `Hash` when you double-splat it. Thus, we cannot override the behavior within MRI. For more information, see [this comment][1] where I detail the behavior of double-splat within MRI. Currently, JRuby also follows this behavior, but it's not guaranteed that other Rubies will. [1]: https://github.com/hashie/hashie/issues/353#issuecomment-363294886
| * Expose `IndifferentAccess` conversion internallyMichael Herold2020-10-221-1/+6
| | | | | | | | | | | | | | In some cases --- like writing meta-extensions of `IndifferentAccess` --- we need access to the ability to convert a key for the purposes of `IndifferentAccess`. Exposing this behavior as a module function makes this possible.
* | Merge pull request #545 from jackjennings/masterDaniel Doubrovkine (dB.)2021-11-082-0/+14
|\ \ | | | | | | Add #except under Ruby 3
| * | Add #except under Ruby 3Jack Jennings2021-11-022-0/+14
| | | | | | | | | | | | | | | | | | Ruby 3 adds the Hash#except method, which should return the correct Hashie object instance when called on a Mash or object using the Hashie::Extensions::IndifferentAccess mixin.
* | | Fixed issue where a source hash key can be used in translating multiple ↵Daniel Lee2021-06-171-1/+6
|/ / | | | | | | properties
* | Hashie::Mash already includes Hashie::Extensions::PrettyInspect via Hashie::HashAkira Matsuda2020-11-041-1/+0
|/
* Fix inconsistencies with Dash defaultsMichael Herold2020-10-232-21/+13
| | | | | | | | | | | The normal behavior of Dash with respect to property defaults differed from the behavior of a Dash/Trash with IgnoreUndeclared mixed in. This is because some situations called the defaults and some did not. This change normalizes the behavior so that all situations where the defaults should be used to override unset values behave consistently, as well as all situations where the default should not override a `nil` value.
* Allow exporting a normal, not-indifferent HashMichael Herold2020-10-221-0/+12
| | | | | | | Following the conventions in `activesupport` and the semantics of the `#to_hash` method in Ruby's standard library, the `#to_hash` method for a hash that has mixed in `IndifferentAccess` will now export the hash as a normal, not-indifferent hash.
* Add hash slice using IndifferentAccess.kenner kliemann2020-10-031-0/+9
|
* Add Hashie::Extensions::Dash::AllowListAlbert Salim2020-09-201-0/+88
| | | | | | | Extends a Dash with the ability to accept only predefined values on a property. #61
* Merge pull request #525 from yogeshjain999/indifferent-convert-changeDaniel Doubrovkine (dB.) @dblockdotorg2020-06-111-2/+2
|\ | | | | | | Small amendments for Hash#merge with IndifferentAccess
| * Small amendments for Hash#merge with IndifferentAccessYogesh Khater2020-06-101-2/+2
| | | | | | | | | | | | | | | | | | 1. Use `indifferent_writer` in `convert!` so that when `indifferent_writer`, `convert_key` or `indifferent_value` is overridden in included class, `merge` can use those. 2. `convert!` was calling twice if `other` hash was lacking indifference. `IndifferentAccess.inject!` already does conversion.
* | Changes to `Mash` initialization key string conversion. (#521)Caroline Artz2020-05-045-19/+29
|/
* Preparing for release, 4.1.0v4.1.0Bobby McDonald2020-02-011-1/+1
|
* Suppress a Ruby's warning when using Ruby 2.6.0+Koichi ITO2020-01-182-15/+19
| | | | | | | | | | | | | | | | | | | This PR suppresses the following warning that `deep_merge` method and `deep_update` method are defined twice when using Ruby 2.6.0+. ```console % bundle exec rake (snip) /Users/koic/src/github.com/hahie/hashie/lib/hashie/mash.rb:226: warning: method redefined; discarding old deep_merge /Users/koic/src/github.com/hahie/hashie/lib/hashie/mash.rb:212: warning: previous definition of deep_merge was here /Users/koic/src/github.com/hahie/hashie/lib/hashie/mash.rb:232: warning: method redefined; discarding old deep_update /Users/koic/src/github.com/hahie/hashie/lib/hashie/mash.rb:218: warning: previous definition of deep_update was here ```
* Suppress an integer unification warning for Ruby 2.4.0+Koichi ITO2020-01-162-4/+4
| | | | | | | | | | | | | | | | | This PR suppresss the following integer unification warning for Ruby 2.4.0+ ```console % ruby -v ruby 2.4.9p362 (2019-10-02 revision 67824) [x86_64-darwin17] % bundle exec rspec spec/hashie/extensions/deep_merge_spec.rb Hashie::Extensions::DeepMerge /Users/koic/src/github.com/hahie/hashie/lib/hashie/utils.rb:38: warning: constant ::Fixnum is deprecated /Users/koic/src/github.com/hahie/hashie/lib/hashie/utils.rb:38: warning: constant ::Bignum is deprecated ```
* Don't warn when setting most affixed keys (#500)Michael Herold2020-01-151-1/+6
| | | | | | | | | | | | | | | | | | | | | Due to how we have implemented the bang/underbang/query behavior within Mash, setting keys that have those affixes in them actually allow overwriting the behavior of those affixes. As such, we shouldn't warn when setting a key that matches those patterns. When it comes to setter-like keys, I believe we still _do_ want to warn for two reasons: 1. Trying to access the key via method access is a syntax error. Ruby expects any method ending in `=` to be a 2+-arity method due to the infix notation of setter methods. This is unexpected behavior unless you're very familiar with Ruby parsing. 2. You can still retrieve the key via the normal `Hash#[]` reader, but it prevents setting a similar key without the equal sign. You can see this in the test about setters. I'd say that is unexpected and surprising behavior. Because of these two gotchas, I think we should still warn in cases where you try to set a key that looks like a setter.
* Fix except use in Mash#load (#508)Bobby McDonald2020-01-142-2/+5
|
* Only define compact on ruby >= 2.4Bobby McDonald2020-01-131-6/+6
|
* Suppress `Psych.safe_load` arg warn when using Psych 3.1.0+Koichi ITO2020-01-131-2/+19
| | | | | | | | | | | | | | | | | | | | | | | This PR suppresses the following `Psych.safe_load` args warn when using Psych 3.1.0 (Ruby 2.6+). ```console % bundle exec rake spec (snip) /Users/koic/src/github.com/intridea/hashie/lib/hashie/extensions/parsers/yaml_erb_parser.rb:22: Passing permitted_classes with the 2nd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, permitted_classes: ...) instead. /Users/koic/src/github.com/intridea/hashie/lib/hashie/extensions/parsers/yaml_erb_parser.rb:22: Passing permitted_symbols with the 3rd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, permitted_symbols: ...) instead. /Users/koic/src/github.com/intridea/hashie/lib/hashie/extensions/parsers/yaml_erb_parser.rb:22: Passing aliases with the 4th argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, aliases: ...) instead ```
* Ensure that Hashie::Arrays are not deconvertedMichael Herold2019-12-131-2/+0
| | | | | | | In order for `#dig` to work properly, we need Arrays to be `Hashie::Array`s to be aware of the key conversion. Our original `Mash#convert_value` method was deconverting `Hashie::Array`s into normal Arrays and causing `#dig` to behave in an unexpected manner.
* update comment for Mash truthiness methodsJeff Manian2019-11-251-1/+2
|
* Merge pull request #499 from michaelherold/permissive-respond-toBobby McDonald2019-11-181-0/+61
|\ | | | | Add a PermissiveRespondTo extension for Mashes
| * Add a PermissiveRespondTo extension for MashesMichael Herold2019-11-171-0/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | By default, Mashes don't state that they respond to unset keys. This causes unexpected behavior when you try to use a Mash with a SimpleDelegator. This new extension allows you create a permissive subclass of Mash that will be fully compatible with SimpleDelegator and allow you to fully do thunk-oriented programming with Mashes. This comes with the trade-off of a ~19KB cache for each of these subclasses and a ~20% performance penalty on any of those subclasses.
* | Prevent deep_merge from mutating nested hashesMichael Herold2019-11-172-1/+44
|/ | | | | | | | | | | | | | | | | | | | | | | | The `DeepMerge` extension has two methods of mutating hashes: a destructive one and a non-destructive one. The `#deep_merge` version should not mutate the original hash or any hash nested within it. The `#deep_merge!` version is free to mutate the receiver. Without deeply duplicating the values contained within the hash, the invariant of immutability cannot be held for the original hash. In order to preserve that invariant, we need to introduce a method of deeply duplicating the hash. The trick here is that we cannot rely on a simple call to `Object#dup`. Some classes within the Ruby standard library are not duplicable in particular versions of Ruby. Newer versions of Ruby allow these classes to be "duplicated" in a way that returns the original value. These classes represent value objects, so it is safe to return the original value ... unless the classes are monkey-patched, but that isn't something we can protect against. This implementation does a best-effort to deeply duplicate an entire hash by relying on these value object classes being able to return themselves without violating immutability.
* Preparing for next development iteration, 4.0.1.Bobby McDonald2019-10-301-1/+1
|
* Preparing for release, 4.0.0.v4.0.0Bobby McDonald2019-10-301-1/+1
|
* Merge pull request #492 from BobbyMcWho/remove-blacklist-whitelistDaniel Doubrovkine (dB.) @dblockdotorg2019-10-283-5/+6
|\ | | | | Remove references to blacklists and whitelists
| * Remove references to blacklists and whitelistsBobby McDonald2019-10-253-5/+6
| |
* | Merge pull request #491 from BobbyMcWho/100-char-linesDaniel Doubrovkine (dB.) @dblockdotorg2019-10-2010-24/+52
|\ \ | | | | | | Change rubocop to restrict to 100 character lines.
| * | Change rubocop to allow 100 character lines.Bobby McDonald2019-10-1710-24/+52
| |/ | | | | | | | | For accessibility reasons, we should limit our lines to 100 chars max. https://github.com/slack-ruby/slack-ruby-client/pull/293#discussion_r309472083
* | remove tap and use blockBobby McDonald2019-10-171-5/+4
|/
* Allow mash error silencing (#488)Bobby McDonald2019-10-142-50/+71
|
* Make Hashie play nice with Rails 6 Hash#except method (#479)Bobby McDonald2019-10-022-0/+21
|
* Implement ruby 2.6 hash merging.Bobby McDonald2019-08-141-5/+30
| | | | | | As of ruby 2.6, Hash#merge and Hash#merge! allow for multiple hashes to be passed to the method, and will merge each one in the order that they were passed.
* Implement non-destructive hash methodsBobby McDonald2019-08-141-0/+42
| | | | | | | | | | | | | | | When calling the following non-destructive hash methods: :compact :invert :reject :select :slice :transform_keys :transform_values we would be returned an instance of a standard Hash rather than a Mash (or subclass). This changes that behavior to instead return an instance of the class the method was called on.
* Add selective key-conflict warnings for Mash subclasses (#478)Bobby McDonald2019-07-181-5/+20
| | | | | | | | | | | In some cases, you want to be able to ignore Mash warnings for keys that you know you aren't going to access via a method accessor, yet be warned for other keys that you know you might want to access. This change adds the ability to selectively ignore warnings for specific keys instead of globally ignoring the warnings. The change retains the original behavior as well, so if you call `Mash.disable_warnings` without a value it will still globally ignore the warnings.
* Allow options on Mash.load (#474)Daniel Doubrovkine (dB.) @dblockdotorg2019-03-223-6/+10
| | | | | | | | | | | | | | | | | `Mash.load` uses the Ruby standard library to load Yaml-serialized files into a Mash. The original implementation used `YAML.load` for this purpose. However, that method is inherently unsafe so we switched to using `YAML.safe_load`. Safely loading Yaml files has many different domain-specific configuration flags that we did not, by default, expose. This change introduces the ability to configure the safe loading of Yaml files so that all types of Yaml can be loaded when necessary using the flags from the standard library. This implementation preserves the backwards-compatibility with the prior implementation so that it should not require updates from users of the current `Mash.load` behavior. For those who this change affects, we included upgrading documentation to ease the transition.
* Add Hashie::Extensions::Mash::DefineAccessors.Vladimir Kochnev2019-01-282-0/+94
| | | | | | | | | | | | | | | | | | | | | | | This patch adds an extension for Mash that makes it behave like `OpenStruct`. It reduces overhead of `method_missing?` magic which is a good thing! It's inspired by the recent @sferik's work on `OpenStruct` — https://github.com/ruby/ruby/pull/1033. When using it in `Mash` subclasses it makes them *remember* methods so then it's more like `ActiveModel` than `OpenStruct` in this case. To use it like `OpenStruct` one could use this shortcut: ```ruby { foo: 1, bar: 2 }.to_mash.with_accessors! ``` Implementation details: It injects to class an anonymous module that stores accessor method definitions. This is inspired by `ActiveModel` / `ActiveRecord`. It allows to override accessors in subclass and call them via `super` if this is intended.
* Reverse condition check in Mash#deep_updateLaerti Papa2018-10-031-1/+1
|
* Do not call any reader attribute in Mash#update if key does not existLaerti Papa2018-10-021-1/+1
| | | | Refs: https://github.com/intridea/hashie/issues/464
* [rubocop] Improve our RuboCop setupMichael Herold2018-09-309-36/+84
| | | | | | | | | | | Disable Metrics/BlockLength in specs because the length of a block in the test suite isn't something we want to lint. We want the tests to be as long as they need to be. Set an explicit line length metric instead of continually updating this as we go. Let's pick a max line length that we want to see and stick with it. This metric should only ever decrease: we don't want to see it ever increase again.
* Remove superfluous commentAlexander Graul2018-09-221-1/+1
| | | | | | After the last commit, the code is self-explanatory. Co-authored-by: Ana María Martínez Gómez <ammartinez@suse.de>
* Use == instead of <= in build_coercionAlexander Graul2018-09-221-1/+1
| | | | | | | | To check if the type class is a Hash, it is more readable to use `==` than `<=`. It returns `false`/`true` instead of `nil`/`0`, but this doesn't make a different when using it in a condition. Co-authored-by: Ana María Martínez Gómez <ammartinez@suse.de>
* Fix a regression with aliases on `Mash.load`Michael Herold2018-08-141-1/+1
| | | | | Also, reorganize the test into the existing file and update the changelog.
* Prepare for next development version, v3.6.1Michael Herold2018-08-131-1/+1
|
* Preparing for release, 3.6.0v3.6.0Michael Herold2018-08-131-1/+1
|
* Add MethodOverridingInitializer extensionLucas Nestor2018-08-111-11/+43
|
* Make Dash greedier when creating gettersMichael Herold2018-08-111-5/+17
| | | | | | | | | | | | | | | | | | Dash, in its current form, was created to be very conservative in creating the getters for its properties. It only creates them when the accompanying setter has not already been created. This means that the property translation capability that is layered on top of Dash to create a Trash cannot have dependence between properties in an order-independent way. This change makes it so Dash now greedily creates a getter method for each property. To ensure that we don't do this more than once for a given Dash class, we track the getters we have previously created. This keeps the number of warnings from Ruby down to the same number of warnings that were emitted prior to this change. Given that Dash users expect the getter to be set, this doesn't feel like it should cause any backwards-compatibility issues.