aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/hash_with_indifferent_access.rb
Commit message (Collapse)AuthorAgeFilesLines
* Implement `fetch_values` for HashWithIndifferentAccess (#28316)Josh Pencheon2017-04-101-0/+13
| | | | | | | `fetch_values` was added to Hash in Ruby 2.3.0: https://bugs.ruby-lang.org/issues/10017 This patch adds an implemention for instances of HWAI, in line with the existing definitions of `fetch` and `values_at`.
* Add aliases for reverse_merge to with_defaultsMatt Casper2017-03-291-0/+2
| | | | | | In the context of controller parameters, reverse_merge is commonly used to provide defaults for user input. Having an alias to reverse_merge called with_defaults feels more idiomatic for Rails.
* Soft-deprecate the top-level HashWithIndifferentAccess classRobin Dupret2017-02-251-0/+2
| | | | | | | Since using a `ActiveSupport::Deprecation::DeprecatedConstantProxy` would prevent people from inheriting this class and extending it from the `ActiveSupport::HashWithIndifferentAccess` one would break the ancestors chain, that's the best option we have here.
* Make HWIA#compact not return nil when no nilsPavel Pravosud2017-02-231-1/+1
|
* Revert "Merge pull request #27925 from robin850/hwia-removal"Kasper Timm Hansen2017-02-201-17/+1
| | | | | | | | | Pointed out by @matthewd that the HWIA subclass changes the AS scoped class and top-level HWIA hierarchies out from under existing classes. This reverts commit 71da39097b67114329be6d8db7fe6911124531af, reversing changes made to 41c33bd4b2ec3f4a482e6030b6fda15091d81e4a.
* Deprecate the top-level `HashWithIndifferentAccess` contantRobin Dupret2017-02-191-1/+17
| | | | | | | | | This constant was kept for the sake of backward compatibility; it is still available under `ActiveSupport::HashWithIndifferentAccess`. Furthermore, since Ruby 2.5 (https://bugs.ruby-lang.org/issues/11547) won't support top level constant lookup, people would have to update their code anyway.
* ensure `#compact` of HWIDA to return HWIDAyuuji.yaginuma2017-01-061-0/+4
| | | | | | | | `Hash#compact` of Ruby native returns new hash. Therefore, in order to return HWIDA as in the past version, need to define own `#compact` to HWIDA. Related: #26868
* Privatize unneededly protected methods in Active SupportAkira Matsuda2016-12-241-4/+4
|
* Remove deprecated new_from_hash_copying_defaultAndrew White2016-11-131-9/+0
|
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
|
* Ensure `#transform_values` of HWIDA to return HWIDAyui-knk2016-10-261-0/+5
| | | | | | | | On Ruby 2.4, naitive `Hash#transform_values` is implemented. `Hash#transform_values` uses an instance of Hash (`rb_hash_new`) to collect returned values of a block. For ensuring `#transform_values` of HWIDA to return HWIDA, we should define `#transform_values` on HWIDA.
* Revert #26826 and add documentationclaudiob2016-10-211-1/+6
| | | | | | | | | | | | | | | | This reverts commit a01cf703 as explained in the comment to #26826: Realized that this PR caused the following warning in Travis CI: ``` /home/travis/build/rails/rails/activesupport/lib/active_support/dependencies.rb:293: warning: loading in progress, circular require considered harmful - /home/travis/build/rails/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb ``` Indeed, `active_support/core_ext/hash/indifferent_access.rb` **needs** to require `active_support/hash_with_indifferent_access.rb` in order to access the class `ActiveSupport::HashWithIndifferentAccess`. The other way around, though, is not _strictly_ required, unless someone tries (like I did in the [gist above](https://gist.github.com/claudiob/43cc7fe77ff95951538af2825a71e5ec)) to use `ActiveSupport::HashWithIndifferentAccess` by only requiring `active_support/hash_with_indifferent_access.rb` without first requiring `active_support/core_ext/hash/indifferent_access.rb`. I think the solution to this is to revert this PR and instead change the documentation to explicitly state that **developers should not require 'active_support/hash_with_indifferent_access'** if all they want is to use `ActiveSupport::HashWithIndifferentAccess` – instead they should require `active_support/core_ext/hash/indifferent_access.rb`.
* Add missing requireclaudiob2016-10-191-0/+1
|
* code gardening: removes redundant selfsXavier Noria2016-08-081-1/+1
| | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty linesRyuta Kamizono2016-08-071-1/+0
|
* applies new string literal convention in activesupport/libXavier Noria2016-08-061-2/+2
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Fix regression in `Hash#dig` for HashWithIndifferentAccess.Jon Moss2016-02-011-3/+7
|
* Match HashWithIndifferentAccess#default's behaviour with Hash#defaultDavid Cornu2016-01-071-6/+18
|
* Deprecate `HWIDA.new_from_hash_copying_default`Sean Griffin2015-10-291-0/+5
| | | | This method was already niche, and is now redundant with `.new`
* Merge pull request #16357 from gchan/hwia-respects-to-hash-defaultSean Griffin2015-10-291-7/+7
|\ | | | | | | | | `HashWithIndifferentAccess.new` respects the default value or proc on objects that respond to `#to_hash`
| * `HashWithIndifferentAccess.new` respects the default value or proc on ↵Gordon Chan2014-07-311-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | objects that respond to `#to_hash`. Builds on the work of #12550 where `.new` will convert the object (that respond to `#to_hash`) to a hash and add that hash's keys and values to itself. This change will also make `.new` respect the default value or proc of objects that respond to `#to_hash`. In other words, this `.new` behaves exactly like `.new_from_hash_copying_default`. `.new_from_hash_copying_default` now simply invokes `.new` and any references to `.new_from_hash_copying_default` are replaced with `.new`. Added tests confirm behavior.
* | [ci skip] Fix rdoc markupakihiro172015-08-121-1/+1
| |
* | ActiveSupport::HashWithIndifferentAccess select and reject should return ↵Bernard Potocki2015-07-171-0/+2
| | | | | | | | enumerator if called without block
* | active_support/indifferent_hash: dont raise on to_hash when default_proc raisesSimon Eskildsen2015-07-101-1/+3
| |
* | active_support/indifferent_hash: fix cloning default_proc on dupSimon Eskildsen2015-07-101-1/+9
| |
* | Revert "Improve the performance of HWIDA `select` and `reject`"Sean Griffin2015-02-061-4/+4
| | | | | | | | This reverts commit 9c47b874d112414df7f80f9ed852adb48ba6d268.
* | Improve the performance of HWIDA `select` and `reject`Sean Griffin2015-02-061-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These are (potentially, depending on input) called in several places in both the router, and Active Record. The code also becomes much cleaner. This results in ~33% performance gain in both methods. Calculating ------------------------------------- before 15.696k i/100ms after 19.865k i/100ms ------------------------------------------------- before 303.064k (± 2.6%) i/s - 1.523M after 446.734k (± 2.4%) i/s - 2.245M On Ruby 2.2, a warning will be emitted about states not being copied, because we're calling `super` from a subclass. We can safely ignore it, however, since we're converting the result back into a HWIDA
* | Fix assignment for frozen value in HWIAAditya Kapoor2015-01-171-1/+1
| |
* | Add necessary 'require reverse_merge' to HAWI.rbclaudiob2014-10-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hashes with indifferent access should support `reverse_merge` out-of-the-box but they don't; for instance the following code fails: ```ruby require 'active_support' require 'active_support/hash_with_indifferent_access' hash = HashWithIndifferentAccess.new key: :old_value hash.reverse_merge key: :new_value ``` This PR fixes the case above by simply requiring `active_support/core_ext/hash/reverse_merge` in `hash_with_indifferent_access.rb` and adding a test that confirms the fix. --- Here are more details about the bugfix. Currently, `reverse_merge` is [defined in HashWithIndifferentAccess](https://github.com/rails/rails/blob/4e8ea13ba1a0870905a46fac5f232d9f41eef8a4/activesupport/lib/active_support/hash_with_indifferent_access.rb#L208) by invoking `super`, that is by invoking `Hash#reverse_merge`: ```ruby def reverse_merge(other_hash) super(self.class.new_from_hash_copying_default(other_hash)) end ``` However, Ruby's `Hash` does not have the `reverse_merge` by default: it must be added by ActiveSupport, and that requires the following line of code to be present: ```ruby require 'active_support/core_ext/hash/reverse_merge' ```
* | Avoid creating an extra hashCarlos Antonio da Silva2014-07-311-2/+2
|/
* Removed unnecessary call to 'convert_key' in 'HashWithIndifferentAccess#to_hash'Gordon Chan2014-07-311-2/+2
| | | | All the keys are already Strings by virtue of being a HashWithIndifferentAccess.
* Make HWIA copy the default proc too.Arthur Neves2014-07-241-0/+1
| | | | [fixes #16279]
* Fix bug that make HashWithIndifferentAccess work differently of HashRafael Mendonça França2014-06-091-1/+1
| | | | | Before HashWithIndifferentAccess were doing deep_dup of the inner hashes when Hash doesn't do. Now both are behaving in the same way.
* [ci skip] Correct documentation of HashWithIndifferentAccess#dupAkshay Vishnoi2014-05-311-2/+2
|
* HashWithIndifferentAccess#dup doc [ci skip]James Blanding2014-05-301-1/+8
| | | | | The phrase "exact copy" in the existing docmentation is somewhat misleading.
* HashWithIndifferentAccess better respects #to_hashPeter Jaros2014-03-281-3/+4
| | | | | | In particular, `.new`, `#update`, `#merge`, `#replace` all accept objects which respond to `#to_hash`, even if those objects are not Hashes directly.
* Consistence in the block styleRafael Mendonça França2014-01-171-4/+4
|
* Remove warnings on Ruby 2.1Rafael Mendonça França2014-01-171-1/+5
|
* Change syntax format for example returned valuesPrem Sichanugrist2013-11-111-1/+1
| | | | | | | | | According to our guideline, we leave 1 space between `#` and `=>`, so we want `# =>` instead of `#=>`. Thanks to @fxn for the suggestion. [ci skip]
* Make HashWithIndifferentAccess#select always return the hash.Marc Schütz2013-07-061-1/+1
| | | | | Hash#select! returns nil if the hash didn't change and thus behaves differently from select, so it's return value can't be used as result for the latter.
* Merge pull request #10627 from vipulnsward/destructive_symbolizeCarlos Antonio da Silva2013-06-251-1/+1
|\ | | | | Change to destructive `deep_symbolize_keys` to avoid a new hash creation.
| * change to destructive `deep_symbolize_keys` after ↵Vipul A M2013-05-151-1/+1
| | | | | | | | https://github.com/rails/rails/commit/df24b8790f22384a068fece7042f04ffd2fcb33e which allows to do so. This helps to avoid extra hash object creation, by symbolizing inplace
* | Merge pull request #10740 from mrsimo/hash-with-indifferent-access-selectRafael Mendonça França2013-06-141-0/+4
|\ \ | | | | | | HashWithIndifferentAccess#select working as intended
| * | HashWithIndifferentAccess#select working as intendedAlbert Llop2013-05-231-0/+4
| | | | | | | | | | | | | | | | | | Before this commit, #reject returned a HashWithIndifferentAccess, whereas #select returned a Hash. Now #select also returns a HashWithIndifferentAccess.
* | | Prevent side effects in `Hash#with_indifferent_access`.Yves Senn2013-05-291-6/+12
|/ /
* / Fix HWIA#to_hash behavior with array of hashes.kennyj2013-05-161-2/+2
|/
* Merge pull request #10266 from vipulnsward/fix_HIA_to_hashRafael Mendonça França2013-05-141-3/+7
|\ | | | | fix HashWithIndifferentAccess#to_hash behaviour
| * fix HashWithIndifferentAccess#to_hash behaviourVipul A M2013-04-191-3/+7
| |
* | symbolize_keys => symbolize_keys! on new hash;Vipul A M2013-04-191-1/+1
|/ | | | "There're" => There are for better readability
* change merge to merge!Vipul A M2013-03-291-1/+1
|