aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/hash_with_indifferent_access.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fixup 64a430129fKasper Timm Hansen2019-07-251-3/+5
|
* Use binding.local_variable_get for `:for`Kasper Timm Hansen2019-07-251-5/+3
| | | | | | Simplifies the surrounding code outside `convert_value`. Ref: https://github.com/rails/rails/pull/36758
* Avoid hash allocation for HashWithIndifferentAccess#convert_value default ↵Joel Turkel2019-07-241-1/+3
| | | | options
* Merge pull request #34642 from ↵Rafael França2019-05-011-1/+1
|\ | | | | | | | | azimux/improve-hwia-initialize-by-skipping-to_h-if-already-a-hash HashWithIndifferentAccess#initialize performance improvement
| * HashWithIndifferentAccess#initialize performance improvementMiles Georgi2018-12-061-1/+1
| | | | | | | | | | | | | | | | | | Rails 4 -> Rails 5 introduced a #to_hash call in HashWithIndifferentAccess#initialize to guarantee access to the #default and #default_proc methods. This can be a very expensive operation for very large HashWithIndifferentAccess objects. This commit bypasses this #to_hash call if it is already a Hash.
* | Speed improvement for HashWithIndifferentAccess#values_atTimo Schilling2019-04-021-2/+2
| |
* | Speed improvement for HashWithIndifferentAccess#fetch_valuesTimo Schilling2019-04-021-1/+1
| |
* | Speed improvement for HashWithIndifferentAccess#exceptTimo Schilling2019-04-011-0/+3
| |
* | Add HashWithIndifferentAccess#assocStefan Schüßler2019-01-301-0/+13
|/
* 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
| |