aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/hash_with_indifferent_access.rb
Commit message (Collapse)AuthorAgeFilesLines
* Make #to_options an alias for #symbolize_keysNick Weiland2018-11-011-0/+1
| | | | | | | | | | | | Fixes #34359 Prior to 5.2.0 (2cad8d7), HashWithIndifferentAccess#to_options acted as an alias to HashWithIndifferentAccess#symbolize_keys. Now, #to_options returns an instance of HashWithIndifferentAccess while #symbolize_keys returns and instance of Hash. This pr makes it so HashWithIndifferentAccess#to_options acts as an alias for HashWithIndifferentAccess#symbolize_keys once again.
* Require the except hash extension before trying to alias itLachlan Sylvester2018-10-011-0/+1
|
* Fix HashWithIndifferentAccess#without bugAbraham Chan2018-09-281-0/+2
|
* Remove extra conditions in HWIDA since Rails 6 does not support Ruby 2.2bogdanvlviv2018-02-171-15/+13
| | | | See https://github.com/ruby/ruby/blob/ruby_2_3/NEWS
* Define transform_keys! in HashWithIndifferentAccessRafael Mendonça França2018-02-161-0/+8
| | | | | | | Make sure that when transforming the keys of a HashWithIndifferentAccess we can still access with indifferent access in Ruby 2.5. Closes #32007.
* [Active Support] require_relative => requireAkira Matsuda2017-10-211-2/+2
| | | | This basically reverts 8da30ad6be34339124ba4cb4e36aea260dda12bc
* Move HWIA specific logic for slice and slice! to HWIA classAkira Matsuda2017-10-211-0/+10
|
* Ensure `HashWithIndifferentAccess#transform_keys` to return ↵yuuji.yaginuma2017-09-271-0/+5
| | | | | | | | | | | `HashWithIndifferentAccess` Currently, `#transform_values`, `#select` and `#reject` return instance of `HashWithIndifferentAccess`. But `#transform_keys` returns instance of Hash. This behavior is a bit confusing. I think that `HashWithIndifferentAccess#transform_keys` should also return instance of `HashWithIndifferentAccess` as well as other methods.
* Revert "Merge pull request #15446 from akshay-vishnoi/doc_changes"Matthew Draper2017-08-051-1/+1
| | | | It was right as originally written in #15440.
* Merge pull request #29757 from lugray/hash_with_indifferent_access_defaultSean Griffin2017-07-171-10/+30
|\ | | | | Fix HashWithIndifferentAccess#default when include?(nil)
| * Fix HashWithIndifferentAccess#default when include?(nil)Lisa Ugray2017-07-171-10/+30
| | | | | | | | | | | | | | | | | | | | The implementation of HashWithIndifferentAccess#default didn't distinguish `default` from `default(nil)`, which caused an incorrect result for `default` if `nil` was used as a key. Define HashWithIndifferentAccess#dig so that hackery that behaves differently from Hash#default can be removed from HashWithIndifferentAccess#default.
* | Merge branch 'master' into make-reverse-merge-bang-order-consistentSean Griffin2017-07-171-2/+19
|\|
| * [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-111-0/+1
| |
| * Use frozen-string-literal in ActiveSupportKir Shatrov2017-07-091-0/+1
| |
| * [Active Support] require => require_relativeAkira Matsuda2017-07-011-2/+2
| |
| * 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.
* | Use method from HashErol Fornoles2017-03-061-1/+1
|/
* 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
|