summaryrefslogtreecommitdiff
path: root/lib/hashie/mash.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add Ruby 3.1 to CI (#558)Peter Goldstein2022-01-271-13/+9
| | | | | | | | | | | | | | | | | | * Add Ruby 3.1 to CI Update Rubocop for recent Rubies Disable Rubocop run for Rubies before Ruby 2.4 Quote '3.0' in the CI configuration to ensure it loads a 3.0.x Ruby Set RUBYOPT="--disable_error_highlight" so Ruby 3.1 error matchers pass * Add CHANGELOG.md entry * Re-add deleted line from CHANGELOG.md * Set minimum supported Ruby version to 2.4. Remove a number of code bits designed to support Rubies below version 2.4 * Bump version. Remove unneeded require from Gemfile. Add require to spec/support file
* Add #except under Ruby 3Jack Jennings2021-11-021-0/+7
| | | | | | 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.
* Hashie::Mash already includes Hashie::Extensions::PrettyInspect via Hashie::HashAkira Matsuda2020-11-041-1/+0
|
* Changes to `Mash` initialization key string conversion. (#521)Caroline Artz2020-05-041-10/+9
|
* Suppress a Ruby's warning when using Ruby 2.6.0+Koichi ITO2020-01-181-14/+14
| | | | | | | | | | | | | | | | | | | 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 ```
* 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-141-2/+3
|
* Only define compact on ruby >= 2.4Bobby McDonald2020-01-131-6/+6
|
* 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 #492 from BobbyMcWho/remove-blacklist-whitelistDaniel Doubrovkine (dB.) @dblockdotorg2019-10-281-1/+1
|\ | | | | Remove references to blacklists and whitelists
| * Remove references to blacklists and whitelistsBobby McDonald2019-10-251-1/+1
| |
* | remove tap and use blockBobby McDonald2019-10-171-5/+4
|/
* Allow mash error silencing (#488)Bobby McDonald2019-10-141-50/+16
|
* 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-221-1/+1
| | | | | | | | | | | | | | | | | `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-281-0/+4
| | | | | | | | | | | | | | | | | | | | | | | 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-301-4/+9
| | | | | | | | | | | 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.
* Update Rubocop and address the addressable todosMichael Herold2018-06-171-21/+21
| | | | | | | | | | | | | | | | | | | | | This is a big step forward in our Rubocop setup. I addressed all of the todos from the current version of Rubocop that made sense to. The only things that remain are metrics and one cop that relies on the line length metric to work. I made some judgment calls on disabling a few cops: 1. The `Layout/IndentHeredoc` cop wants you to either use the squiggly heredoc from Ruby 2.3 or introduce a library. Since we are a low-level library that is used as a transitive dependency, we cannot introduce another library as a dependence, so that option is out. Also, we support Rubies back to 2.0 currently, so using the squiggly heredoc isn't an option. Once we remove support for Rubies older than 2.3, we can switch to the squiggly heredoc cop. 2. The `Naming/FileName` cop was reporting false positives for a few files in the repository, so I disabled it on those files. 3. The `Style/DoubleNegation` cop reports lints on a few cases where we use double negation. Given the very generic nature of Hashie, the double-negation is the easiest, clearest way to express that we want an item to be a Boolean. I disabled the cop because we exist in the gray area where this makes sense.
* Propagate Mash `default_proc` to sub-HashesMichael Herold2018-02-041-1/+1
| | | | | | | | | | | | | | | | | | | | In the case where you want to set deeply nested values through chained calls to the `#[]` method or through method accessors (without using the bang methods), you might set a `default_proc` on a Mash that recursively creates the key as you access it. Previously, the `default_proc` was not being propagated down to sub-Hashes because the way that `#dup` was written wasn't passing the `default_proc` do the duplicated object. Now, the `default_proc` is correctly being sent to the duplicated object, which allows this pattern to work: ```ruby h = Hashie::Mash.new { |mash, key| mash[key] = mash.class.new(&mash.default_proc) } h.a.b.c = :xyz h[:a][:b][:c] #=> :xyz h[:x][:y][:z] = :abc h.x.y.z #=> :abc ```
* removed typo in error messageGiles Bowkett2017-08-011-1/+1
|
* Fix "@disable_warnings" spec warning (#416)Alexandre Filipe Campos2017-03-011-1/+1
| | | | | | | | When running rspec specs on the ruby-grape project with warnings enabled this warning is printed hundreds of times. This change fixes the warning. Also, turn on warnings when running rspec to see when this happens.
* Don't log when overwriting Mash keysMichael Herold2017-02-241-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When we switched to using `#respond_to?` to detecting whether to log a Mash collision, we started reporting when we were overwriting keys that already exist in the Mash. This is a poor experience because it causes extra warnings (as in #414) or, in the worst case, causes an "undefined method" error (as in #413). This change fixes that problem and benchmarks to ensure we're not appreciably regressing performance. The results of two benchmarks are below: ``` bundle exec ruby benchmark/mash_method_access.rb: Warming up -------------------------------------- before 92.456k i/100ms Calculating ------------------------------------- before 1.290M (± 4.4%) i/s - 6.472M in 5.028183s Pausing here -- run Ruby again to measure the next benchmark... Warming up -------------------------------------- after 92.941k i/100ms Calculating ------------------------------------- after 1.326M (± 5.4%) i/s - 6.692M in 5.060756s Comparison: after: 1326239.2 i/s before: 1289624.0 i/s - same-ish: difference falls within error ``` and ``` within spec/integrations/omniauth, bundle exec rake perf:ips Warming up -------------------------------------- before 1.260k i/100ms Calculating ------------------------------------- before 13.114k (± 4.2%) i/s - 66.780k in 5.101689s Pausing here -- run Ruby again to measure the next benchmark... Warming up -------------------------------------- after 1.299k i/100ms Calculating ------------------------------------- after 13.149k (± 4.0%) i/s - 66.249k in 5.046630s Comparison: after: 13148.9 i/s before: 13113.8 i/s - same-ish: difference falls within error ``` Closes #413 Closes #414
* Add an extension to maintain original Mash keys (#326)Michael Herold2017-02-221-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | One of the behaviors of Mash that we see regularly surprise users is that Mash stringifies any keys passed into it. This leads to unexpected lack of synergy between Mash and its cousins (particularly Dash), since the property DSLs do not handle indifferent key access. This extension ensures that the original keys are kept inside the Mash's data structure, at the expense of more costly logic for fetching information indifferently. I have included a benchmark that compares the two. The benchmark shows that when you are passing string keys into a Mash, using this extension will actually be _faster_ than the default implementation, but that the reverse is true when passing symbol keys. In #296, I tried to do this universally for all Mashes, which slowed down the fetching behavior for Mash significantly. I like this attempt much better because it allows users to opt into the new behavior if they want it, while still keeping the default implementation as-is. Fixes #196 by giving the option of keeping the original structure of the Mash when using it with Dash. Fixes #246 by giving the option of opting into keeping the original keys. Closes #296 by giving a more flexible path forward that doesn't change the semantics of the main Mash class.
* Fix a performance regression due to loggingMichael Herold2017-02-181-1/+1
| | | | | | | By switching to `#respond_to?` we make the lookup of method collisions a lot faster while retaining the ability to report on them. Closes #410
* Carry over disabling warnings to subclassesMichael Herold2017-02-101-0/+9
|
* Fix passing Pathname object to Hashie::Mesh.load()Albert Song2017-02-081-2/+3
| | | | With a test that would fail without this patch.
* Allow Mash subclasses to disable warningsMichael Herold2017-02-041-0/+25
| | | | | | | | | | | | | | | | | Since we are transitively used as a dependency in many projects, we should have given the ability to toggle this behavior off. The logging feature is more of a "help people get started with Mash" feature. If you're using Hashie in a library, it's likely that you already know the tradeoffs of attempting to override methods on the object. To use this feature, you only have to subclass Mash and then call the class method: ```ruby class KeyStore < Hashie::Mash disable_warnings end ```
* Fix #391: require all dependencies in Hashie::Mash.dblock2017-01-311-0/+2
|
* Add a logging layer to address common issues (#381)Michael Herold2016-11-021-0/+15
|
* Fix support for Array#digjonathan schatz2016-06-011-1/+5
|
* Convert Mash keys for #digTakashi Kokubun2016-02-081-0/+6
|
* Make reverse_merge compatible with subclassing.Vladimir Kochnev2015-11-151-1/+1
|
* Some micro optimizations to Hashie::Mash.Vladimir Kochnev2015-08-311-12/+19
|
* Removed Mash#id and Mash#type.Jonathan Rochkind2015-04-081-8/+0
| | | | | | | | | | Ruby 1.8.7 had Object#id and #type, both of which were deprecated, which Hashie::Mash wanted to cover with more reasonable methods. These methods in Object were removed in ruby 1.9. The cover methods are unneeded, and can cause problems with Mash::SafeAssignment preventing you from using these as keys. Fixes #290
* Add Hashie::Mash#reverse_merge. Increase Rubocop class length.Max Goldstein2015-02-251-0/+5
| | | | Fixes intridea/hashie#270
* add Hashie::Mash#extractable_options?Ryan Buckley2015-01-191-0/+5
|
* Fix handling of default proc values in MashErol Fornoles2014-12-301-7/+8
|
* Merging Hashie::Mash now correctly only calls the block on duplicate valuesAmy Sutedja2014-09-051-1/+1
|
* suffix parser pattern is constant - we shouldn't compile it every time for ↵Andrey Fadeyev2014-09-011-2/+2
| | | | suffix recognition
* Revert "dont convert keys on initialization"dblock2014-08-261-20/+45
| | | | | | | This reverts commit 33f73e0635fc4d2c9f4726c744b50667c82d7b39. Conflicts: CHANGELOG.md
* Add Hashie::Extensions::Mash::SafeAssignmentMichael Herold2014-08-201-1/+6
| | | | This is part 3 of 3 of the to-do list determined in #198.
* dont convert keys on initializationgregory2014-07-221-45/+20
|
* Added Mash#load with YAML file support.gregory2014-07-141-0/+19
|
* Fix Hashie::Mash#values_at.Tom Hulihan2014-06-271-0/+4
| | | | | This method now converts the keys before trying to access them from the Mash.
* Replaced respond_to with respond_to_missing in Mash and ActiveModel.dblock2014-05-011-1/+1
|