hashie 3.6.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +228 -174
- data/CONTRIBUTING.md +13 -6
- data/README.md +127 -15
- data/UPGRADING.md +83 -7
- data/hashie.gemspec +13 -7
- data/lib/hashie.rb +21 -19
- data/lib/hashie/dash.rb +2 -1
- data/lib/hashie/extensions/active_support/core_ext/hash.rb +14 -0
- data/lib/hashie/extensions/coercion.rb +23 -16
- data/lib/hashie/extensions/dash/indifferent_access.rb +20 -1
- data/lib/hashie/extensions/dash/property_translation.rb +6 -3
- data/lib/hashie/extensions/deep_fetch.rb +4 -2
- data/lib/hashie/extensions/deep_find.rb +12 -3
- data/lib/hashie/extensions/deep_locate.rb +22 -7
- data/lib/hashie/extensions/deep_merge.rb +18 -1
- data/lib/hashie/extensions/indifferent_access.rb +1 -3
- data/lib/hashie/extensions/key_conflict_warning.rb +55 -0
- data/lib/hashie/extensions/mash/define_accessors.rb +90 -0
- data/lib/hashie/extensions/mash/keep_original_keys.rb +2 -1
- data/lib/hashie/extensions/mash/permissive_respond_to.rb +61 -0
- data/lib/hashie/extensions/mash/safe_assignment.rb +3 -1
- data/lib/hashie/extensions/method_access.rb +5 -2
- data/lib/hashie/extensions/parsers/yaml_erb_parser.rb +26 -4
- data/lib/hashie/extensions/ruby_version_check.rb +5 -1
- data/lib/hashie/extensions/strict_key_access.rb +8 -4
- data/lib/hashie/hash.rb +16 -9
- data/lib/hashie/mash.rb +114 -53
- data/lib/hashie/railtie.rb +7 -0
- data/lib/hashie/rash.rb +1 -1
- data/lib/hashie/utils.rb +28 -0
- data/lib/hashie/version.rb +1 -1
- metadata +19 -130
- data/spec/hashie/array_spec.rb +0 -29
- data/spec/hashie/clash_spec.rb +0 -70
- data/spec/hashie/dash_spec.rb +0 -598
- data/spec/hashie/extensions/autoload_spec.rb +0 -24
- data/spec/hashie/extensions/coercion_spec.rb +0 -639
- data/spec/hashie/extensions/dash/coercion_spec.rb +0 -13
- data/spec/hashie/extensions/dash/indifferent_access_spec.rb +0 -84
- data/spec/hashie/extensions/deep_fetch_spec.rb +0 -97
- data/spec/hashie/extensions/deep_find_spec.rb +0 -138
- data/spec/hashie/extensions/deep_locate_spec.rb +0 -137
- data/spec/hashie/extensions/deep_merge_spec.rb +0 -70
- data/spec/hashie/extensions/ignore_undeclared_spec.rb +0 -47
- data/spec/hashie/extensions/indifferent_access_spec.rb +0 -295
- data/spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb +0 -208
- data/spec/hashie/extensions/key_conversion_spec.rb +0 -12
- data/spec/hashie/extensions/mash/keep_original_keys_spec.rb +0 -46
- data/spec/hashie/extensions/mash/safe_assignment_spec.rb +0 -50
- data/spec/hashie/extensions/mash/symbolize_keys_spec.rb +0 -39
- data/spec/hashie/extensions/merge_initializer_spec.rb +0 -23
- data/spec/hashie/extensions/method_access_spec.rb +0 -226
- data/spec/hashie/extensions/strict_key_access_spec.rb +0 -110
- data/spec/hashie/extensions/stringify_keys_spec.rb +0 -124
- data/spec/hashie/extensions/symbolize_keys_spec.rb +0 -129
- data/spec/hashie/hash_spec.rb +0 -84
- data/spec/hashie/mash_spec.rb +0 -771
- data/spec/hashie/parsers/yaml_erb_parser_spec.rb +0 -46
- data/spec/hashie/rash_spec.rb +0 -83
- data/spec/hashie/trash_spec.rb +0 -328
- data/spec/hashie/utils_spec.rb +0 -25
- data/spec/hashie/version_spec.rb +0 -7
- data/spec/hashie_spec.rb +0 -13
- data/spec/integration/elasticsearch/integration_spec.rb +0 -40
- data/spec/integration/omniauth-oauth2/app.rb +0 -52
- data/spec/integration/omniauth-oauth2/integration_spec.rb +0 -26
- data/spec/integration/omniauth-oauth2/some_site.rb +0 -38
- data/spec/integration/omniauth/app.rb +0 -11
- data/spec/integration/omniauth/integration_spec.rb +0 -38
- data/spec/integration/rails-without-dependency/integration_spec.rb +0 -15
- data/spec/integration/rails/app.rb +0 -47
- data/spec/integration/rails/integration_spec.rb +0 -26
- data/spec/spec_helper.rb +0 -23
- data/spec/support/integration_specs.rb +0 -36
- data/spec/support/logger.rb +0 -24
- data/spec/support/module_context.rb +0 -11
- data/spec/support/ruby_version_check.rb +0 -6
data/CONTRIBUTING.md
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
Contributing to Hashie
|
2
2
|
======================
|
3
3
|
|
4
|
-
Hashie is work of [many contributors](https://github.com/
|
4
|
+
Hashie is work of [many contributors](https://github.com/hashie/hashie/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/hashie/hashie/pulls), [propose features and discuss issues](https://github.com/hashie/hashie/issues).
|
5
5
|
|
6
6
|
#### Fork the Project
|
7
7
|
|
8
|
-
Fork the [project on Github](https://github.com/
|
8
|
+
Fork the [project on Github](https://github.com/hashie/hashie) and check out your copy.
|
9
9
|
|
10
10
|
```
|
11
11
|
git clone https://github.com/contributor/hashie.git
|
12
12
|
cd hashie
|
13
|
-
git remote add upstream https://github.com/
|
13
|
+
git remote add upstream https://github.com/hashie/hashie.git
|
14
14
|
```
|
15
15
|
|
16
16
|
#### Create a Topic Branch
|
@@ -23,12 +23,19 @@ git pull upstream master
|
|
23
23
|
git checkout -b my-feature-branch
|
24
24
|
```
|
25
25
|
|
26
|
-
####
|
26
|
+
#### Install dependencies
|
27
|
+
|
28
|
+
You can use the setup script to install dependencies for the gem and its integration tests.
|
29
|
+
|
30
|
+
```
|
31
|
+
bin/setup
|
32
|
+
```
|
33
|
+
|
34
|
+
#### Test
|
27
35
|
|
28
36
|
Ensure that you can build the project and run tests.
|
29
37
|
|
30
38
|
```
|
31
|
-
bundle install
|
32
39
|
bundle exec rake
|
33
40
|
```
|
34
41
|
|
@@ -105,7 +112,7 @@ git push origin my-feature-branch -f
|
|
105
112
|
Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
|
106
113
|
|
107
114
|
```
|
108
|
-
* [#123](https://github.com/
|
115
|
+
* [#123](https://github.com/hashie/hashie/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
|
109
116
|
```
|
110
117
|
|
111
118
|
Amend your previous commit and force push the changes.
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Hashie
|
2
2
|
|
3
|
-
[![Join the chat at https://gitter.im/
|
3
|
+
[![Join the chat at https://gitter.im/hashie/hashie](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/hashie/hashie?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
4
|
[![Gem Version](http://img.shields.io/gem/v/hashie.svg)](http://badge.fury.io/rb/hashie)
|
5
|
-
[![Build Status](http://img.shields.io/travis/
|
6
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/7a0b42c8a22c945571fd/test_coverage)](https://codeclimate.com/github/
|
7
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/7a0b42c8a22c945571fd/maintainability)](https://codeclimate.com/github/
|
5
|
+
[![Build Status](http://img.shields.io/travis/hashie/hashie.svg)](https://travis-ci.org/hashie/hashie)
|
6
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/7a0b42c8a22c945571fd/test_coverage)](https://codeclimate.com/github/hashie/hashie/test_coverage)
|
7
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/7a0b42c8a22c945571fd/maintainability)](https://codeclimate.com/github/hashie/hashie/maintainability)
|
8
8
|
|
9
9
|
Hashie is a growing collection of tools that extend Hashes and make them more useful.
|
10
10
|
|
@@ -16,9 +16,9 @@ Hashie is available as a RubyGem:
|
|
16
16
|
$ gem install hashie
|
17
17
|
```
|
18
18
|
|
19
|
-
##
|
19
|
+
## Stable Release
|
20
20
|
|
21
|
-
You're reading the documentation for the stable release of Hashie,
|
21
|
+
You're reading the documentation for the stable release of Hashie, 4.1.0.(https://github.com/hashie/hashie/blob/v4.1.0/README.md).
|
22
22
|
|
23
23
|
## Hash Extensions
|
24
24
|
|
@@ -190,7 +190,7 @@ end
|
|
190
190
|
|
191
191
|
### KeyConversion
|
192
192
|
|
193
|
-
The KeyConversion extension gives you the convenience methods of `symbolize_keys` and `stringify_keys` along with their bang counterparts. You can also include just stringify or just symbolize with `Hashie::Extensions::StringifyKeys` or `Hashie::Extensions::SymbolizeKeys
|
193
|
+
The KeyConversion extension gives you the convenience methods of `symbolize_keys` and `stringify_keys` along with their bang counterparts. You can also include just stringify or just symbolize with `Hashie::Extensions::StringifyKeys` or [`Hashie::Extensions::SymbolizeKeys`](#mash-extension-symbolizekeys).
|
194
194
|
|
195
195
|
Hashie also has a utility method for converting keys on a Hash without a mixin:
|
196
196
|
|
@@ -316,8 +316,8 @@ p.email # => NoMethodError
|
|
316
316
|
|
317
317
|
### DeepMerge
|
318
318
|
|
319
|
-
This extension
|
320
|
-
system
|
319
|
+
This extension allows you to easily include a recursive merging
|
320
|
+
system into any Hash descendant:
|
321
321
|
|
322
322
|
```ruby
|
323
323
|
class MyHash < Hash
|
@@ -515,6 +515,55 @@ class Response < Hashie::Mash
|
|
515
515
|
end
|
516
516
|
```
|
517
517
|
|
518
|
+
The default is to disable logging for all methods that conflict. If you would like to only disable the logging for specific methods, you can include an array of method keys:
|
519
|
+
|
520
|
+
```ruby
|
521
|
+
class Response < Hashie::Mash
|
522
|
+
disable_warnings :zip, :zap
|
523
|
+
end
|
524
|
+
```
|
525
|
+
|
526
|
+
This behavior is cumulative. The examples above and below behave identically.
|
527
|
+
|
528
|
+
```ruby
|
529
|
+
class Response < Hashie::Mash
|
530
|
+
disable_warnings :zip
|
531
|
+
disable_warnings :zap
|
532
|
+
end
|
533
|
+
```
|
534
|
+
|
535
|
+
Disable warnings will honor the last `disable_warnings` call. Calling without parameters will override the ignored methods list, and calling with parameters will create a new ignored methods list. This includes child classes that inherit from a class that disables warnings.
|
536
|
+
|
537
|
+
```ruby
|
538
|
+
class Message < Hashie::Mash
|
539
|
+
disable_warnings :zip, :zap
|
540
|
+
disable_warnings
|
541
|
+
end
|
542
|
+
|
543
|
+
# No errors will be logged
|
544
|
+
Message.new(merge: 'true', compact: true)
|
545
|
+
```
|
546
|
+
|
547
|
+
```ruby
|
548
|
+
class Message < Hashie::Mash
|
549
|
+
disable_warnings
|
550
|
+
end
|
551
|
+
|
552
|
+
class Response < Message
|
553
|
+
disable_warnings :zip, :zap
|
554
|
+
end
|
555
|
+
|
556
|
+
# 2 errors will be logged
|
557
|
+
Response.new(merge: 'true', compact: true, zip: '90210', zap: 'electric')
|
558
|
+
```
|
559
|
+
|
560
|
+
If you would like to create an anonymous subclass of a Hashie::Mash with key conflict warnings disabled:
|
561
|
+
|
562
|
+
```ruby
|
563
|
+
Hashie::Mash.quiet.new(zip: '90210', compact: true) # no errors logged
|
564
|
+
Hashie::Mash.quiet(:zip).new(zip: '90210', compact: true) # error logged for compact
|
565
|
+
```
|
566
|
+
|
518
567
|
### How does the wrapping of Mash sub-Hashes work?
|
519
568
|
|
520
569
|
Mash duplicates any sub-Hashes that you add to it and wraps them in a Mash. This allows for infinite chaining of nested Hashes within a Mash without modifying the object(s) that are passed into the Mash. When you subclass Mash, the subclass wraps any sub-Hashes in its own class. This preserves any extensions that you mixed into the Mash subclass and allows them to work within the sub-Hashes, in addition to the main containing Mash.
|
@@ -566,7 +615,7 @@ Twitter.extend mash.to_module # NOTE: if you want another name than settings, ca
|
|
566
615
|
Twitter.settings.api_key # => 'abcd'
|
567
616
|
```
|
568
617
|
|
569
|
-
You can use another parser (by default: YamlErbParser):
|
618
|
+
You can use another parser (by default: [YamlErbParser](lib/hashie/extensions/parsers/yaml_erb_parser.rb)):
|
570
619
|
|
571
620
|
```
|
572
621
|
#/etc/data/user.csv
|
@@ -582,6 +631,14 @@ mash = Mash.load('data/user.csv', parser: MyCustomCsvParser)
|
|
582
631
|
mash[1] #=> { name: 'John', lastname: 'Doe' }
|
583
632
|
```
|
584
633
|
|
634
|
+
The `Mash#load` method calls `YAML.safe_load(path, [], [], true)`.
|
635
|
+
|
636
|
+
Specify `permitted_symbols`, `permitted_classes` and `aliases` options as needed.
|
637
|
+
|
638
|
+
```ruby
|
639
|
+
Mash.load('data/user.csv', permitted_classes: [Symbol], permitted_symbols: [], aliases: false)
|
640
|
+
```
|
641
|
+
|
585
642
|
### Mash Extension: KeepOriginalKeys
|
586
643
|
|
587
644
|
This extension can be mixed into a Mash to keep the form of any keys passed directly into the Mash. By default, Mash converts keys to strings to give indifferent access. This extension still allows indifferent access, but keeps the form of the keys to eliminate confusion when you're not expecting the keys to change.
|
@@ -601,6 +658,30 @@ mash['string_key'] #=> 'string'
|
|
601
658
|
mash[:string_key] #=> 'string'
|
602
659
|
```
|
603
660
|
|
661
|
+
### Mash Extension: PermissiveRespondTo
|
662
|
+
|
663
|
+
By default, Mash only states that it responds to built-in methods, affixed methods (e.g. setters, underbangs, etc.), and keys that it currently contains. That means it won't state that it responds to a getter for an unset key, as in the following example:
|
664
|
+
|
665
|
+
```ruby
|
666
|
+
mash = Hashie::Mash.new(a: 1)
|
667
|
+
mash.respond_to? :b #=> false
|
668
|
+
```
|
669
|
+
|
670
|
+
This means that by default Mash is not a perfect match for use with a SimpleDelegator since the delegator will not forward messages for unset keys to the Mash even though it can handle them.
|
671
|
+
|
672
|
+
In order to have a SimpleDelegator-compatible Mash, you can use the `PermissiveRespondTo` extension to make Mash respond to anything.
|
673
|
+
|
674
|
+
```ruby
|
675
|
+
class PermissiveMash < Hashie::Mash
|
676
|
+
include Hashie::Extensions::Mash::PermissiveRespondTo
|
677
|
+
end
|
678
|
+
|
679
|
+
mash = PermissiveMash.new(a: 1)
|
680
|
+
mash.respond_to? :b #=> true
|
681
|
+
```
|
682
|
+
|
683
|
+
This comes at the cost of approximately 20% performance for initialization and setters and 19KB of permanent memory growth for each such class that you create.
|
684
|
+
|
604
685
|
### Mash Extension: SafeAssignment
|
605
686
|
|
606
687
|
This extension can be mixed into a Mash to guard the attempted overwriting of methods by property setters. When mixed in, the Mash will raise an `ArgumentError` if you attempt to write a property with the same name as an existing method.
|
@@ -617,9 +698,9 @@ safe_mash.zip = 'Test' # => ArgumentError
|
|
617
698
|
safe_mash[:zip] = 'test' # => still ArgumentError
|
618
699
|
```
|
619
700
|
|
620
|
-
### Mash Extension
|
701
|
+
### Mash Extension: SymbolizeKeys
|
621
702
|
|
622
|
-
This extension can be mixed into a Mash to change the default behavior of converting keys to strings. After mixing this extension into a Mash, the Mash will convert all keys to symbols.
|
703
|
+
This extension can be mixed into a Mash to change the default behavior of converting keys to strings. After mixing this extension into a Mash, the Mash will convert all keys to symbols. It can be useful to use with keywords argument, which required symbol keys.
|
623
704
|
|
624
705
|
```ruby
|
625
706
|
class SymbolizedMash < ::Hashie::Mash
|
@@ -630,6 +711,12 @@ symbol_mash = SymbolizedMash.new
|
|
630
711
|
symbol_mash['test'] = 'value'
|
631
712
|
symbol_mash.test #=> 'value'
|
632
713
|
symbol_mash.to_h #=> {test: 'value'}
|
714
|
+
|
715
|
+
def example(test:)
|
716
|
+
puts test
|
717
|
+
end
|
718
|
+
|
719
|
+
example(symbol_mash) #=> value
|
633
720
|
```
|
634
721
|
|
635
722
|
There is a major benefit and coupled with a major trade-off to this decision (at least on older Rubies). As a benefit, by using symbols as keys, you will be able to use the implicit conversion of a Mash via the `#to_hash` method to destructure (or splat) the contents of a Mash out to a block. This can be handy for doing iterations through the Mash's keys and values, as follows:
|
@@ -644,6 +731,31 @@ end
|
|
644
731
|
|
645
732
|
However, on Rubies less than 2.0, this means that every key you send to the Mash will generate a symbol. Since symbols are not garbage-collected on older versions of Ruby, this can cause a slow memory leak when using a symbolized Mash with data generated from user input.
|
646
733
|
|
734
|
+
### Mash Extension: DefineAccessors
|
735
|
+
|
736
|
+
This extension can be mixed into a Mash so it makes it behave like `OpenStruct`. It reduces the overhead of `method_missing?` magic by lazily defining field accessors when they're requested.
|
737
|
+
|
738
|
+
```ruby
|
739
|
+
class MyHash < ::Hashie::Mash
|
740
|
+
include Hashie::Extensions::Mash::DefineAccessors
|
741
|
+
end
|
742
|
+
|
743
|
+
mash = MyHash.new
|
744
|
+
MyHash.method_defined?(:foo=) #=> false
|
745
|
+
mash.foo = 123
|
746
|
+
MyHash.method_defined?(:foo=) #=> true
|
747
|
+
|
748
|
+
MyHash.method_defined?(:foo) #=> false
|
749
|
+
mash.foo #=> 123
|
750
|
+
MyHash.method_defined?(:foo) #=> true
|
751
|
+
```
|
752
|
+
|
753
|
+
You can also extend the existing mash without defining a class:
|
754
|
+
|
755
|
+
```ruby
|
756
|
+
mash = ::Hashie::Mash.new.with_accessors!
|
757
|
+
```
|
758
|
+
|
647
759
|
## Dash
|
648
760
|
|
649
761
|
Dash is an extended Hash that has a discrete set of defined properties and only those properties may be set on the hash. Additionally, you can set defaults for each property. You can also flag a property as required. Required properties will raise an exception if unset. Another option is message for required properties, which allow you to add custom messages for required property.
|
@@ -785,7 +897,7 @@ class DataModelHash < Hashie::Dash
|
|
785
897
|
end
|
786
898
|
|
787
899
|
model = DataModelHash.new(id: '123', created: '2014-04-25 22:35:28')
|
788
|
-
model.id.class #=> Fixnum
|
900
|
+
model.id.class #=> Integer (Fixnum if you are using Ruby 2.3 or lower)
|
789
901
|
model.created_at.class #=> Time
|
790
902
|
```
|
791
903
|
|
@@ -854,7 +966,7 @@ this will produce the following
|
|
854
966
|
|
855
967
|
```ruby
|
856
968
|
result = Result.new(id: '123', creation_date: '2012-03-30 17:23:28')
|
857
|
-
result.id.class # => Fixnum
|
969
|
+
result.id.class # => Integer (Fixnum if you are using Ruby 2.3 or lower)
|
858
970
|
result.created_at.class # => Time
|
859
971
|
```
|
860
972
|
|
@@ -921,6 +1033,6 @@ See [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
921
1033
|
|
922
1034
|
## Copyright
|
923
1035
|
|
924
|
-
Copyright (c) 2009-2014 Intridea, Inc. (http://intridea.com/) and [contributors](https://github.com/
|
1036
|
+
Copyright (c) 2009-2014 Intridea, Inc. (http://intridea.com/) and [contributors](https://github.com/hashie/hashie/graphs/contributors).
|
925
1037
|
|
926
1038
|
MIT License. See [LICENSE](LICENSE) for details.
|
data/UPGRADING.md
CHANGED
@@ -1,6 +1,84 @@
|
|
1
1
|
Upgrading Hashie
|
2
2
|
================
|
3
3
|
|
4
|
+
### Upgrading to 4.0.0
|
5
|
+
|
6
|
+
#### Non-destructive Hash methods called on Mash
|
7
|
+
|
8
|
+
The following non-destructive Hash methods called on Mash will now return an instance of the class it was called on.
|
9
|
+
|
10
|
+
| method | ruby |
|
11
|
+
| ----------------- | ---- |
|
12
|
+
| #compact | |
|
13
|
+
| #invert | |
|
14
|
+
| #reject | |
|
15
|
+
| #select | |
|
16
|
+
| #slice | 2.5 |
|
17
|
+
| #transform_keys | 2.5 |
|
18
|
+
| #transform_values | 2.4 |
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
class Parents < Hashie::Mash; end
|
22
|
+
|
23
|
+
parents = Parents.new(father: 'Dad', mother: 'Mom')
|
24
|
+
cool_parents = parents.transform_values { |v| v + v[-1] + 'io'}
|
25
|
+
|
26
|
+
p cool_parents
|
27
|
+
|
28
|
+
# before:
|
29
|
+
{"father"=>"Daddio", "mother"=>"Mommio"}
|
30
|
+
=> {"father"=>"Daddio", "mother"=>"Mommio"}
|
31
|
+
|
32
|
+
# after:
|
33
|
+
#<Parents father="Daddio" mother="Mommio">
|
34
|
+
=> {"father"=>"Dad", "mother"=>"Mom"}
|
35
|
+
```
|
36
|
+
|
37
|
+
This may make places where you had to re-make the Mash redundant, and may cause unintended side effects if your application was expecting a plain old ruby Hash.
|
38
|
+
|
39
|
+
#### Ruby 2.6: Mash#merge and Mash#merge!
|
40
|
+
|
41
|
+
In Ruby > 2.6.0, Hashie now supports passing multiple hash and Mash objects to Mash#merge and Mash#merge!.
|
42
|
+
|
43
|
+
#### Hashie::Mash::CannotDisableMashWarnings error class is removed
|
44
|
+
|
45
|
+
There shouldn't really be a case that anyone was relying on catching this specific error, but if so, they should change it to rescue Hashie::Extensions::KeyConflictWarning::CannotDisableMashWarnings
|
46
|
+
|
47
|
+
### Upgrading to 3.7.0
|
48
|
+
|
49
|
+
#### Mash#load takes options
|
50
|
+
|
51
|
+
The `Hashie::Mash#load` method now accepts options, changing the interface of `Parser#initialize`. If you have a custom parser, you must update its `initialize` method.
|
52
|
+
|
53
|
+
For example, `Hashie::Extensions::Parsers::YamlErbParser` now accepts `permitted_classes`, `permitted_symbols` and `aliases` options.
|
54
|
+
|
55
|
+
Before:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
class Hashie::Extensions::Parsers::YamlErbParser
|
59
|
+
def initialize(file_path)
|
60
|
+
@file_path = file_path
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
After:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
class Hashie::Extensions::Parsers::YamlErbParser
|
69
|
+
def initialize(file_path, options = {})
|
70
|
+
@file_path = file_path
|
71
|
+
@options = options
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
Options can now be passed into `Mash#load`.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
Mash.load(filename, permitted_classes: [])
|
80
|
+
```
|
81
|
+
|
4
82
|
### Upgrading to 3.5.2
|
5
83
|
|
6
84
|
#### Disable logging in Mash subclasses
|
@@ -65,7 +143,7 @@ h.abb? # => false
|
|
65
143
|
|
66
144
|
#### Possible coercion changes
|
67
145
|
|
68
|
-
The improvements made to coercions in version 3.2.1 [issue #200](https://github.com/
|
146
|
+
The improvements made to coercions in version 3.2.1 [issue #200](https://github.com/hashie/hashie/pull/200) do not break the documented API, but are significant enough that changes may effect undocumented side-effects. Applications that depended on those side-effects will need to be updated.
|
69
147
|
|
70
148
|
**Change**: Type coercion no longer creates new objects if the input matches the target type. Previously coerced properties always resulted in the creation of a new object, even when it wasn't necessary. This had the effect of a `dup` or `clone` on coerced properties but not uncoerced ones.
|
71
149
|
|
@@ -81,7 +159,7 @@ Applications that were attempting to rescuing the internal errors should be upda
|
|
81
159
|
|
82
160
|
#### Compatibility with Rails 4 Strong Parameters
|
83
161
|
|
84
|
-
Version 2.1 introduced support to prevent default Rails 4 mass-assignment protection behavior. This was [issue #89](https://github.com/
|
162
|
+
Version 2.1 introduced support to prevent default Rails 4 mass-assignment protection behavior. This was [issue #89](https://github.com/hashie/hashie/issues/89), resolved in [#104](https://github.com/hashie/hashie/pull/104). In version 2.2 this behavior has been removed in [#147](https://github.com/hashie/hashie/pull/147) in favor of a mixin and finally extracted into a separate gem in Hashie 3.0.
|
85
163
|
|
86
164
|
To enable 2.1 compatible behavior with Rails 4, use the [hashie_rails](http://rubygems.org/gems/hashie_rails) gem.
|
87
165
|
|
@@ -89,7 +167,7 @@ To enable 2.1 compatible behavior with Rails 4, use the [hashie_rails](http://ru
|
|
89
167
|
gem 'hashie_rails'
|
90
168
|
```
|
91
169
|
|
92
|
-
See [#154](https://github.com/
|
170
|
+
See [#154](https://github.com/hashie/hashie/pull/154) and [Mash and Rails 4 Strong Parameters](README.md#mash-and-rails-4-strong-parameters) for more details.
|
93
171
|
|
94
172
|
#### Key Conversions in Hashie::Dash and Hashie::Trash
|
95
173
|
|
@@ -117,7 +195,7 @@ p.inspect # => { 'name' => 'dB.' }
|
|
117
195
|
p.to_hash # => { 'name' => 'dB.' }
|
118
196
|
```
|
119
197
|
|
120
|
-
It was not possible to achieve the behavior of preserving keys, as described in [issue #151](https://github.com/
|
198
|
+
It was not possible to achieve the behavior of preserving keys, as described in [issue #151](https://github.com/hashie/hashie/issues/151).
|
121
199
|
|
122
200
|
Version 2.2 does not perform this conversion by default.
|
123
201
|
|
@@ -164,6 +242,4 @@ instance.to_hash # => { :first => 'First', "last" => 'Last' }
|
|
164
242
|
|
165
243
|
The behavior with `symbolize_keys` and `stringify_keys` is unchanged.
|
166
244
|
|
167
|
-
See [#152](https://github.com/
|
168
|
-
|
169
|
-
|
245
|
+
See [#152](https://github.com/hashie/hashie/pull/152) for more information.
|
data/hashie.gemspec
CHANGED
@@ -7,16 +7,22 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.email = ['michael@intridea.com', 'jollyjerry@gmail.com']
|
8
8
|
gem.description = 'Hashie is a collection of classes and mixins that make hashes more powerful.'
|
9
9
|
gem.summary = 'Your friendly neighborhood hash library.'
|
10
|
-
gem.homepage = 'https://github.com/
|
10
|
+
gem.homepage = 'https://github.com/hashie/hashie'
|
11
11
|
gem.license = 'MIT'
|
12
12
|
|
13
13
|
gem.require_paths = ['lib']
|
14
|
-
gem.files
|
14
|
+
gem.files = %w[.yardopts CHANGELOG.md CONTRIBUTING.md LICENSE README.md UPGRADING.md]
|
15
|
+
gem.files += %w[Rakefile hashie.gemspec]
|
15
16
|
gem.files += Dir['lib/**/*.rb']
|
16
|
-
gem.files += Dir['spec/**/*.rb']
|
17
|
-
gem.test_files = Dir['spec/**/*.rb']
|
18
17
|
|
19
|
-
gem.
|
20
|
-
|
21
|
-
|
18
|
+
if gem.respond_to?(:metadata)
|
19
|
+
gem.metadata = {
|
20
|
+
'bug_tracker_uri' => 'https://github.com/hashie/hashie/issues',
|
21
|
+
'changelog_uri' => 'https://github.com/hashie/hashie/blob/master/CHANGELOG.md',
|
22
|
+
'documentation_uri' => 'https://www.rubydoc.info/gems/hashie',
|
23
|
+
'source_code_uri' => 'https://github.com/hashie/hashie'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
gem.add_development_dependency 'bundler'
|
22
28
|
end
|
data/lib/hashie.rb
CHANGED
@@ -12,26 +12,26 @@ module Hashie
|
|
12
12
|
autoload :Utils, 'hashie/utils'
|
13
13
|
|
14
14
|
module Extensions
|
15
|
-
autoload :Coercion,
|
16
|
-
autoload :DeepMerge,
|
17
|
-
autoload :IgnoreUndeclared,
|
18
|
-
autoload :IndifferentAccess,
|
19
|
-
autoload :MergeInitializer,
|
20
|
-
autoload :MethodAccess,
|
21
|
-
autoload :MethodQuery,
|
22
|
-
autoload :MethodReader,
|
23
|
-
autoload :MethodWriter,
|
24
|
-
autoload :StringifyKeys,
|
25
|
-
autoload :SymbolizeKeys,
|
26
|
-
autoload :DeepFetch,
|
27
|
-
autoload :DeepFind,
|
28
|
-
autoload :DeepLocate,
|
29
|
-
autoload :PrettyInspect,
|
30
|
-
autoload :KeyConversion,
|
15
|
+
autoload :Coercion, 'hashie/extensions/coercion'
|
16
|
+
autoload :DeepMerge, 'hashie/extensions/deep_merge'
|
17
|
+
autoload :IgnoreUndeclared, 'hashie/extensions/ignore_undeclared'
|
18
|
+
autoload :IndifferentAccess, 'hashie/extensions/indifferent_access'
|
19
|
+
autoload :MergeInitializer, 'hashie/extensions/merge_initializer'
|
20
|
+
autoload :MethodAccess, 'hashie/extensions/method_access'
|
21
|
+
autoload :MethodQuery, 'hashie/extensions/method_access'
|
22
|
+
autoload :MethodReader, 'hashie/extensions/method_access'
|
23
|
+
autoload :MethodWriter, 'hashie/extensions/method_access'
|
24
|
+
autoload :StringifyKeys, 'hashie/extensions/stringify_keys'
|
25
|
+
autoload :SymbolizeKeys, 'hashie/extensions/symbolize_keys'
|
26
|
+
autoload :DeepFetch, 'hashie/extensions/deep_fetch'
|
27
|
+
autoload :DeepFind, 'hashie/extensions/deep_find'
|
28
|
+
autoload :DeepLocate, 'hashie/extensions/deep_locate'
|
29
|
+
autoload :PrettyInspect, 'hashie/extensions/pretty_inspect'
|
30
|
+
autoload :KeyConversion, 'hashie/extensions/key_conversion'
|
31
31
|
autoload :MethodAccessWithOverride, 'hashie/extensions/method_access'
|
32
|
-
autoload :StrictKeyAccess,
|
33
|
-
autoload :RubyVersion,
|
34
|
-
autoload :RubyVersionCheck,
|
32
|
+
autoload :StrictKeyAccess, 'hashie/extensions/strict_key_access'
|
33
|
+
autoload :RubyVersion, 'hashie/extensions/ruby_version'
|
34
|
+
autoload :RubyVersionCheck, 'hashie/extensions/ruby_version_check'
|
35
35
|
|
36
36
|
module Parsers
|
37
37
|
autoload :YamlErbParser, 'hashie/extensions/parsers/yaml_erb_parser'
|
@@ -45,8 +45,10 @@ module Hashie
|
|
45
45
|
|
46
46
|
module Mash
|
47
47
|
autoload :KeepOriginalKeys, 'hashie/extensions/mash/keep_original_keys'
|
48
|
+
autoload :PermissiveRespondTo, 'hashie/extensions/mash/permissive_respond_to'
|
48
49
|
autoload :SafeAssignment, 'hashie/extensions/mash/safe_assignment'
|
49
50
|
autoload :SymbolizeKeys, 'hashie/extensions/mash/symbolize_keys'
|
51
|
+
autoload :DefineAccessors, 'hashie/extensions/mash/define_accessors'
|
50
52
|
end
|
51
53
|
|
52
54
|
module Array
|