hashie 2.1.2 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +524 -59
  3. data/CONTRIBUTING.md +24 -7
  4. data/README.md +781 -90
  5. data/Rakefile +19 -2
  6. data/UPGRADING.md +245 -0
  7. data/hashie.gemspec +21 -13
  8. data/lib/hashie.rb +60 -21
  9. data/lib/hashie/array.rb +21 -0
  10. data/lib/hashie/clash.rb +24 -12
  11. data/lib/hashie/dash.rb +96 -33
  12. data/lib/hashie/extensions/active_support/core_ext/hash.rb +14 -0
  13. data/lib/hashie/extensions/array/pretty_inspect.rb +19 -0
  14. data/lib/hashie/extensions/coercion.rb +124 -18
  15. data/lib/hashie/extensions/dash/coercion.rb +25 -0
  16. data/lib/hashie/extensions/dash/indifferent_access.rb +56 -0
  17. data/lib/hashie/extensions/dash/property_translation.rb +191 -0
  18. data/lib/hashie/extensions/deep_fetch.rb +7 -5
  19. data/lib/hashie/extensions/deep_find.rb +69 -0
  20. data/lib/hashie/extensions/deep_locate.rb +113 -0
  21. data/lib/hashie/extensions/deep_merge.rb +35 -12
  22. data/lib/hashie/extensions/ignore_undeclared.rb +11 -5
  23. data/lib/hashie/extensions/indifferent_access.rb +28 -16
  24. data/lib/hashie/extensions/key_conflict_warning.rb +55 -0
  25. data/lib/hashie/extensions/key_conversion.rb +0 -82
  26. data/lib/hashie/extensions/mash/define_accessors.rb +90 -0
  27. data/lib/hashie/extensions/mash/keep_original_keys.rb +53 -0
  28. data/lib/hashie/extensions/mash/permissive_respond_to.rb +61 -0
  29. data/lib/hashie/extensions/mash/safe_assignment.rb +18 -0
  30. data/lib/hashie/extensions/mash/symbolize_keys.rb +38 -0
  31. data/lib/hashie/extensions/method_access.rb +154 -11
  32. data/lib/hashie/extensions/parsers/yaml_erb_parser.rb +48 -0
  33. data/lib/hashie/extensions/pretty_inspect.rb +19 -0
  34. data/lib/hashie/extensions/ruby_version.rb +60 -0
  35. data/lib/hashie/extensions/ruby_version_check.rb +21 -0
  36. data/lib/hashie/extensions/strict_key_access.rb +77 -0
  37. data/lib/hashie/extensions/stringify_keys.rb +71 -0
  38. data/lib/hashie/extensions/symbolize_keys.rb +71 -0
  39. data/lib/hashie/hash.rb +27 -8
  40. data/lib/hashie/logger.rb +18 -0
  41. data/lib/hashie/mash.rb +235 -57
  42. data/lib/hashie/railtie.rb +21 -0
  43. data/lib/hashie/rash.rb +40 -16
  44. data/lib/hashie/trash.rb +2 -88
  45. data/lib/hashie/utils.rb +44 -0
  46. data/lib/hashie/version.rb +1 -1
  47. metadata +42 -81
  48. data/.gitignore +0 -9
  49. data/.rspec +0 -2
  50. data/.rubocop.yml +0 -36
  51. data/.travis.yml +0 -15
  52. data/Gemfile +0 -11
  53. data/Guardfile +0 -5
  54. data/lib/hashie/hash_extensions.rb +0 -47
  55. data/spec/hashie/clash_spec.rb +0 -48
  56. data/spec/hashie/dash_spec.rb +0 -338
  57. data/spec/hashie/extensions/coercion_spec.rb +0 -156
  58. data/spec/hashie/extensions/deep_fetch_spec.rb +0 -70
  59. data/spec/hashie/extensions/deep_merge_spec.rb +0 -22
  60. data/spec/hashie/extensions/ignore_undeclared_spec.rb +0 -23
  61. data/spec/hashie/extensions/indifferent_access_spec.rb +0 -152
  62. data/spec/hashie/extensions/key_conversion_spec.rb +0 -103
  63. data/spec/hashie/extensions/merge_initializer_spec.rb +0 -23
  64. data/spec/hashie/extensions/method_access_spec.rb +0 -121
  65. data/spec/hashie/hash_spec.rb +0 -66
  66. data/spec/hashie/mash_spec.rb +0 -467
  67. data/spec/hashie/rash_spec.rb +0 -44
  68. data/spec/hashie/trash_spec.rb +0 -193
  69. data/spec/hashie/version_spec.rb +0 -7
  70. data/spec/spec.opts +0 -3
  71. data/spec/spec_helper.rb +0 -8
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hashie::Rash do
4
- subject do
5
- Hashie::Rash.new(
6
- /hello/ => 'hello',
7
- /world/ => 'world',
8
- 'other' => 'whee',
9
- true => false,
10
- 1 => 'awesome',
11
- 1..1000 => 'rangey',
12
- /(bcd)/ => proc { |m| m[1] }
13
- # /.+/ => "EVERYTHING"
14
- )
15
- end
16
-
17
- it 'finds strings' do
18
- expect(subject['other']).to eq 'whee'
19
- expect(subject['well hello there']).to eq 'hello'
20
- expect(subject['the world is round']).to eq 'world'
21
- expect(subject.all('hello world').sort).to eq %w(hello world)
22
- end
23
-
24
- it 'finds regexps' do
25
- expect(subject[/other/]).to eq 'whee'
26
- end
27
-
28
- it 'finds other objects' do
29
- expect(subject[true]).to eq false
30
- expect(subject[1]).to eq 'awesome'
31
- end
32
-
33
- it 'finds numbers from ranges' do
34
- expect(subject[250]).to eq 'rangey'
35
- expect(subject[999]).to eq 'rangey'
36
- expect(subject[1000]).to eq 'rangey'
37
- expect(subject[1001]).to be_nil
38
- end
39
-
40
- it 'evaluates proc values' do
41
- expect(subject['abcdef']).to eq 'bcd'
42
- expect(subject['ffffff']).to be_nil
43
- end
44
- end
@@ -1,193 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hashie::Trash do
4
- class TrashTest < Hashie::Trash
5
- property :first_name, from: :firstName
6
- end
7
-
8
- let(:trash) { TrashTest.new }
9
-
10
- describe 'translating properties' do
11
- it 'adds the property to the list' do
12
- expect(TrashTest.properties).to include(:first_name)
13
- end
14
-
15
- it 'creates a method for reading the property' do
16
- expect(trash).to respond_to(:first_name)
17
- end
18
-
19
- it 'creates a method for writing the property' do
20
- expect(trash).to respond_to(:first_name=)
21
- end
22
-
23
- it 'creates a method for writing the translated property' do
24
- expect(trash).to respond_to(:firstName=)
25
- end
26
-
27
- it 'does not create a method for reading the translated property' do
28
- expect(trash).not_to respond_to(:firstName)
29
- end
30
-
31
- it 'maintains translations hash mapping from the original to the translated name' do
32
- expect(TrashTest.translations[:firstName]).to eq :first_name
33
- end
34
-
35
- it 'maintains inverse translations hash mapping from the translated to the original name' do
36
- expect(TrashTest.inverse_translations[:first_name]).to eq :firstName
37
- end
38
-
39
- it '#permitted_input_keys contain the :from key of properties with translations' do
40
- expect(TrashTest.permitted_input_keys).to include :firstName
41
- end
42
- end
43
-
44
- describe 'standard properties' do
45
- class TrashTestPermitted < Hashie::Trash
46
- property :id
47
- end
48
-
49
- it '#permitted_input_keys contain names of properties without translations' do
50
- expect(TrashTestPermitted.permitted_input_keys).to include :id
51
- end
52
- end
53
-
54
- describe 'writing to properties' do
55
- it 'does not write to a non-existent property using []=' do
56
- expect { trash['abc'] = 123 }.to raise_error(NoMethodError)
57
- end
58
-
59
- it 'writes to an existing property using []=' do
60
- expect { trash['first_name'] = 'Bob' }.not_to raise_error
61
- end
62
-
63
- it 'writes to a translated property using []=' do
64
- expect { trash['firstName'] = 'Bob' }.not_to raise_error
65
- end
66
-
67
- it 'reads/writes to an existing property using a method call' do
68
- trash.first_name = 'Franklin'
69
- expect(trash.first_name).to eq 'Franklin'
70
- end
71
-
72
- it 'writes to an translated property using a method call' do
73
- trash.firstName = 'Franklin'
74
- expect(trash.first_name).to eq 'Franklin'
75
- end
76
-
77
- it 'writes to a translated property using #replace' do
78
- trash.replace(firstName: 'Franklin')
79
- expect(trash.first_name).to eq 'Franklin'
80
- end
81
-
82
- it 'writes to a non-translated property using #replace' do
83
- trash.replace(first_name: 'Franklin')
84
- expect(trash.first_name).to eq 'Franklin'
85
- end
86
- end
87
-
88
- describe ' initializing with a Hash' do
89
- it 'does not initialize non-existent properties' do
90
- expect { TrashTest.new(bork: 'abc') }.to raise_error(NoMethodError)
91
- end
92
-
93
- it 'sets the desired properties' do
94
- expect(TrashTest.new(first_name: 'Michael').first_name).to eq 'Michael'
95
- end
96
-
97
- context 'with both the translated property and the property' do
98
- it 'sets the desired properties' do
99
- expect(TrashTest.new(first_name: 'Michael', firstName: 'Maeve').first_name).to eq 'Michael'
100
- end
101
- end
102
-
103
- it 'sets the translated properties' do
104
- expect(TrashTest.new(firstName: 'Michael').first_name).to eq 'Michael'
105
- end
106
- end
107
-
108
- describe 'translating properties using a proc' do
109
- class TrashLambdaTest < Hashie::Trash
110
- property :first_name, from: :firstName, with: lambda { |value| value.reverse }
111
- end
112
-
113
- let(:lambda_trash) { TrashLambdaTest.new }
114
-
115
- it 'translates the value given on initialization with the given lambda' do
116
- expect(TrashLambdaTest.new(firstName: 'Michael').first_name).to eq 'Michael'.reverse
117
- end
118
-
119
- it 'does not translate the value if given with the right property' do
120
- expect(TrashTest.new(first_name: 'Michael').first_name).to eq 'Michael'
121
- end
122
-
123
- it 'translates the value given as property with the given lambda' do
124
- lambda_trash.firstName = 'Michael'
125
- expect(lambda_trash.first_name).to eq 'Michael'.reverse
126
- end
127
-
128
- it 'does not translate the value given as right property' do
129
- lambda_trash.first_name = 'Michael'
130
- expect(lambda_trash.first_name).to eq 'Michael'
131
- end
132
- end
133
-
134
- describe 'uses with or transform_with interchangeably' do
135
- class TrashLambdaTestTransformWith < Hashie::Trash
136
- property :first_name, from: :firstName, transform_with: lambda { |value| value.reverse }
137
- end
138
-
139
- let(:lambda_trash) { TrashLambdaTestTransformWith.new }
140
-
141
- it 'translates the value given as property with the given lambda' do
142
- lambda_trash.firstName = 'Michael'
143
- expect(lambda_trash.first_name).to eq 'Michael'.reverse
144
- end
145
-
146
- it 'does not translate the value given as right property' do
147
- lambda_trash.first_name = 'Michael'
148
- expect(lambda_trash.first_name).to eq 'Michael'
149
- end
150
- end
151
-
152
- describe 'translating properties without from option using a proc' do
153
- class TrashLambdaTestWithProperties < Hashie::Trash
154
- property :first_name, transform_with: lambda { |value| value.reverse }
155
- end
156
-
157
- let(:lambda_trash) { TrashLambdaTestWithProperties.new }
158
-
159
- it 'translates the value given as property with the given lambda' do
160
- lambda_trash.first_name = 'Michael'
161
- expect(lambda_trash.first_name).to eq 'Michael'.reverse
162
- end
163
-
164
- it 'transforms the value when given in constructor' do
165
- expect(TrashLambdaTestWithProperties.new(first_name: 'Michael').first_name).to eq 'Michael'.reverse
166
- end
167
-
168
- context 'when :from option is given' do
169
- class TrashLambdaTest3 < Hashie::Trash
170
- property :first_name, from: :firstName, transform_with: lambda { |value| value.reverse }
171
- end
172
-
173
- it 'does not override the :from option in the constructor' do
174
- expect(TrashLambdaTest3.new(first_name: 'Michael').first_name).to eq 'Michael'
175
- end
176
-
177
- it 'does not override the :from option when given as property' do
178
- t = TrashLambdaTest3.new
179
- t.first_name = 'Michael'
180
- expect(t.first_name).to eq 'Michael'
181
- end
182
-
183
- end
184
- end
185
-
186
- it 'raises an error when :from have the same value as property' do
187
- expect do
188
- class WrongTrash < Hashie::Trash
189
- property :first_name, from: :first_name
190
- end
191
- end.to raise_error(ArgumentError)
192
- end
193
- end
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hashie do
4
- it 'has a version' do
5
- expect(Hashie::VERSION).not_to be_nil
6
- end
7
- end
@@ -1,3 +0,0 @@
1
- --colour
2
- --format progress
3
- --backtrace
@@ -1,8 +0,0 @@
1
- require 'rubygems'
2
-
3
- $LOAD_PATH.unshift(File.dirname(__FILE__))
4
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
-
6
- require 'hashie'
7
- require 'rspec'
8
- require 'rspec/autorun'