hashie 2.0.5 → 2.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 (46) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +36 -0
  3. data/.travis.yml +13 -6
  4. data/CHANGELOG.md +40 -21
  5. data/CONTRIBUTING.md +110 -19
  6. data/Gemfile +9 -0
  7. data/LICENSE +1 -1
  8. data/README.md +347 -0
  9. data/Rakefile +4 -2
  10. data/hashie.gemspec +4 -7
  11. data/lib/hashie.rb +3 -0
  12. data/lib/hashie/clash.rb +19 -19
  13. data/lib/hashie/dash.rb +47 -39
  14. data/lib/hashie/extensions/coercion.rb +10 -6
  15. data/lib/hashie/extensions/deep_fetch.rb +29 -0
  16. data/lib/hashie/extensions/deep_merge.rb +15 -6
  17. data/lib/hashie/extensions/ignore_undeclared.rb +41 -0
  18. data/lib/hashie/extensions/indifferent_access.rb +37 -10
  19. data/lib/hashie/extensions/key_conversion.rb +3 -3
  20. data/lib/hashie/extensions/method_access.rb +9 -9
  21. data/lib/hashie/hash.rb +7 -7
  22. data/lib/hashie/hash_extensions.rb +5 -7
  23. data/lib/hashie/mash.rb +38 -31
  24. data/lib/hashie/rash.rb +119 -0
  25. data/lib/hashie/trash.rb +31 -22
  26. data/lib/hashie/version.rb +1 -1
  27. data/spec/hashie/clash_spec.rb +43 -45
  28. data/spec/hashie/dash_spec.rb +115 -53
  29. data/spec/hashie/extensions/coercion_spec.rb +42 -37
  30. data/spec/hashie/extensions/deep_fetch_spec.rb +70 -0
  31. data/spec/hashie/extensions/deep_merge_spec.rb +11 -9
  32. data/spec/hashie/extensions/ignore_undeclared_spec.rb +23 -0
  33. data/spec/hashie/extensions/indifferent_access_spec.rb +117 -64
  34. data/spec/hashie/extensions/key_conversion_spec.rb +28 -27
  35. data/spec/hashie/extensions/merge_initializer_spec.rb +13 -10
  36. data/spec/hashie/extensions/method_access_spec.rb +49 -40
  37. data/spec/hashie/hash_spec.rb +25 -13
  38. data/spec/hashie/mash_spec.rb +243 -187
  39. data/spec/hashie/rash_spec.rb +44 -0
  40. data/spec/hashie/trash_spec.rb +81 -43
  41. data/spec/hashie/version_spec.rb +7 -0
  42. data/spec/spec_helper.rb +0 -4
  43. metadata +27 -78
  44. data/.document +0 -5
  45. data/README.markdown +0 -236
  46. data/lib/hashie/extensions/structure.rb +0 -47
@@ -0,0 +1,44 @@
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
+ subject['other'].should eq 'whee'
19
+ subject['well hello there'].should eq 'hello'
20
+ subject['the world is round'].should eq 'world'
21
+ subject.all('hello world').sort.should eq %w(hello world)
22
+ end
23
+
24
+ it 'finds regexps' do
25
+ subject[/other/].should eq 'whee'
26
+ end
27
+
28
+ it 'finds other objects' do
29
+ subject[true].should eq false
30
+ subject[1].should eq 'awesome'
31
+ end
32
+
33
+ it 'finds numbers from ranges' do
34
+ subject[250].should eq 'rangey'
35
+ subject[999].should eq 'rangey'
36
+ subject[1000].should eq 'rangey'
37
+ subject[1001].should be_nil
38
+ end
39
+
40
+ it 'evaluates proc values' do
41
+ subject['abcdef'].should eq 'bcd'
42
+ subject['ffffff'].should be_nil
43
+ end
44
+ end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Hashie::Trash do
4
4
  class TrashTest < Hashie::Trash
5
- property :first_name, :from => :firstName
5
+ property :first_name, from: :firstName
6
6
  end
7
7
 
8
8
  let(:trash) { TrashTest.new }
@@ -27,129 +27,167 @@ describe Hashie::Trash do
27
27
  it 'does not create a method for reading the translated property' do
28
28
  trash.should_not respond_to(:firstName)
29
29
  end
30
+
31
+ it 'maintains translations hash mapping from the original to the translated name' do
32
+ TrashTest.translations[:firstName].should eq :first_name
33
+ end
34
+
35
+ it 'maintains inverse translations hash mapping from the translated to the original name' do
36
+ TrashTest.inverse_translations[:first_name].should eq :firstName
37
+ end
38
+
39
+ it '#permitted_input_keys contain the :from key of properties with translations' do
40
+ TrashTest.permitted_input_keys.should include :firstName
41
+ end
30
42
  end
31
43
 
32
- describe 'writing to properties' do
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
+ TrashTestPermitted.permitted_input_keys.should include :id
51
+ end
52
+ end
33
53
 
54
+ describe 'writing to properties' do
34
55
  it 'does not write to a non-existent property using []=' do
35
- lambda{trash['abc'] = 123}.should raise_error(NoMethodError)
56
+ lambda { trash['abc'] = 123 }.should raise_error(NoMethodError)
36
57
  end
37
58
 
38
59
  it 'writes to an existing property using []=' do
39
- lambda{trash['first_name'] = 'Bob'}.should_not raise_error
60
+ lambda { trash['first_name'] = 'Bob' }.should_not raise_error
40
61
  end
41
62
 
42
63
  it 'writes to a translated property using []=' do
43
- lambda{trash['firstName'] = 'Bob'}.should_not raise_error
64
+ lambda { trash['firstName'] = 'Bob' }.should_not raise_error
44
65
  end
45
66
 
46
67
  it 'reads/writes to an existing property using a method call' do
47
68
  trash.first_name = 'Franklin'
48
- trash.first_name.should == 'Franklin'
69
+ trash.first_name.should eq 'Franklin'
49
70
  end
50
71
 
51
72
  it 'writes to an translated property using a method call' do
52
73
  trash.firstName = 'Franklin'
53
- trash.first_name.should == 'Franklin'
74
+ trash.first_name.should eq 'Franklin'
54
75
  end
55
76
 
56
77
  it 'writes to a translated property using #replace' do
57
- trash.replace(:firstName => 'Franklin')
58
- trash.first_name.should == 'Franklin'
78
+ trash.replace(firstName: 'Franklin')
79
+ trash.first_name.should eq 'Franklin'
59
80
  end
60
81
 
61
82
  it 'writes to a non-translated property using #replace' do
62
- trash.replace(:first_name => 'Franklin')
63
- trash.first_name.should == 'Franklin'
83
+ trash.replace(first_name: 'Franklin')
84
+ trash.first_name.should eq 'Franklin'
64
85
  end
65
86
  end
66
87
 
67
88
  describe ' initializing with a Hash' do
68
89
  it 'does not initialize non-existent properties' do
69
- lambda{TrashTest.new(:bork => 'abc')}.should raise_error(NoMethodError)
90
+ lambda { TrashTest.new(bork: 'abc') }.should raise_error(NoMethodError)
70
91
  end
71
92
 
72
93
  it 'sets the desired properties' do
73
- TrashTest.new(:first_name => 'Michael').first_name.should == 'Michael'
94
+ TrashTest.new(first_name: 'Michael').first_name.should eq 'Michael'
74
95
  end
75
96
 
76
- context "with both the translated property and the property" do
97
+ context 'with both the translated property and the property' do
77
98
  it 'sets the desired properties' do
78
- TrashTest.new(:first_name => 'Michael', :firstName=>'Maeve').first_name.should == 'Michael'
99
+ TrashTest.new(first_name: 'Michael', firstName: 'Maeve').first_name.should eq 'Michael'
79
100
  end
80
101
  end
81
102
 
82
103
  it 'sets the translated properties' do
83
- TrashTest.new(:firstName => 'Michael').first_name.should == 'Michael'
104
+ TrashTest.new(firstName: 'Michael').first_name.should eq 'Michael'
84
105
  end
85
106
  end
86
107
 
87
108
  describe 'translating properties using a proc' do
88
109
  class TrashLambdaTest < Hashie::Trash
89
- property :first_name, :from => :firstName, :with => lambda { |value| value.reverse }
110
+ property :first_name, from: :firstName, with: lambda { |value| value.reverse }
90
111
  end
91
112
 
92
113
  let(:lambda_trash) { TrashLambdaTest.new }
93
114
 
94
- it 'should translate the value given on initialization with the given lambda' do
95
- TrashLambdaTest.new(:firstName => 'Michael').first_name.should == 'Michael'.reverse
115
+ it 'translates the value given on initialization with the given lambda' do
116
+ TrashLambdaTest.new(firstName: 'Michael').first_name.should eq 'Michael'.reverse
96
117
  end
97
118
 
98
- it 'should not translate the value if given with the right property' do
99
- TrashTest.new(:first_name => 'Michael').first_name.should == 'Michael'
119
+ it 'does not translate the value if given with the right property' do
120
+ TrashTest.new(first_name: 'Michael').first_name.should eq 'Michael'
100
121
  end
101
122
 
102
- it 'should translate the value given as property with the given lambda' do
123
+ it 'translates the value given as property with the given lambda' do
103
124
  lambda_trash.firstName = 'Michael'
104
- lambda_trash.first_name.should == 'Michael'.reverse
125
+ lambda_trash.first_name.should eq 'Michael'.reverse
105
126
  end
106
127
 
107
- it 'should not translate the value given as right property' do
128
+ it 'does not translate the value given as right property' do
108
129
  lambda_trash.first_name = 'Michael'
109
- lambda_trash.first_name.should == 'Michael'
130
+ lambda_trash.first_name.should eq 'Michael'
110
131
  end
111
132
  end
112
133
 
113
- describe 'translating properties without from option using a proc' do
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
+ lambda_trash.first_name.should eq 'Michael'.reverse
144
+ end
114
145
 
115
- class TrashLambdaTest2 < Hashie::Trash
116
- property :first_name, :transform_with => lambda { |value| value.reverse }
146
+ it 'does not translate the value given as right property' do
147
+ lambda_trash.first_name = 'Michael'
148
+ lambda_trash.first_name.should 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 }
117
155
  end
118
156
 
119
- let(:lambda_trash) { TrashLambdaTest2.new }
157
+ let(:lambda_trash) { TrashLambdaTestWithProperties.new }
120
158
 
121
- it 'should translate the value given as property with the given lambda' do
159
+ it 'translates the value given as property with the given lambda' do
122
160
  lambda_trash.first_name = 'Michael'
123
- lambda_trash.first_name.should == 'Michael'.reverse
161
+ lambda_trash.first_name.should eq 'Michael'.reverse
124
162
  end
125
163
 
126
- it 'should transform the value when given in constructor' do
127
- TrashLambdaTest2.new(:first_name => 'Michael').first_name.should == 'Michael'.reverse
164
+ it 'transforms the value when given in constructor' do
165
+ TrashLambdaTestWithProperties.new(first_name: 'Michael').first_name.should eq 'Michael'.reverse
128
166
  end
129
167
 
130
- context "when :from option is given" do
168
+ context 'when :from option is given' do
131
169
  class TrashLambdaTest3 < Hashie::Trash
132
- property :first_name, :from => :firstName, :transform_with => lambda { |value| value.reverse }
170
+ property :first_name, from: :firstName, transform_with: lambda { |value| value.reverse }
133
171
  end
134
172
 
135
- it 'should not override the :from option in the constructor' do
136
- TrashLambdaTest3.new(:first_name => 'Michael').first_name.should == 'Michael'
173
+ it 'does not override the :from option in the constructor' do
174
+ TrashLambdaTest3.new(first_name: 'Michael').first_name.should eq 'Michael'
137
175
  end
138
176
 
139
- it 'should not override the :from option when given as property' do
177
+ it 'does not override the :from option when given as property' do
140
178
  t = TrashLambdaTest3.new
141
179
  t.first_name = 'Michael'
142
- t.first_name.should == 'Michael'
180
+ t.first_name.should eq 'Michael'
143
181
  end
144
182
 
145
183
  end
146
184
  end
147
185
 
148
- it "should raise an error when :from have the same value as property" do
149
- expect {
186
+ it 'raises an error when :from have the same value as property' do
187
+ expect do
150
188
  class WrongTrash < Hashie::Trash
151
- property :first_name, :from => :first_name
189
+ property :first_name, from: :first_name
152
190
  end
153
- }.to raise_error(ArgumentError)
191
+ end.to raise_error(ArgumentError)
154
192
  end
155
193
  end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hashie do
4
+ it 'has a version' do
5
+ Hashie::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -6,7 +6,3 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
6
  require 'hashie'
7
7
  require 'rspec'
8
8
  require 'rspec/autorun'
9
-
10
- RSpec.configure do |config|
11
-
12
- end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashie
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
5
- prerelease:
4
+ version: 2.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Michael Bleigh
@@ -10,90 +9,37 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-05-10 00:00:00.000000000 Z
12
+ date: 2014-04-06 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rake
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ~>
21
- - !ruby/object:Gem::Version
22
- version: 0.9.2
23
- type: :development
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ~>
29
- - !ruby/object:Gem::Version
30
- version: 0.9.2
31
- - !ruby/object:Gem::Dependency
32
- name: rspec
33
- requirement: !ruby/object:Gem::Requirement
34
- none: false
35
- requirements:
36
- - - ~>
37
- - !ruby/object:Gem::Version
38
- version: '2.5'
39
- type: :development
40
- prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ~>
45
- - !ruby/object:Gem::Version
46
- version: '2.5'
47
- - !ruby/object:Gem::Dependency
48
- name: guard
49
- requirement: !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ! '>='
18
+ - - '>='
53
19
  - !ruby/object:Gem::Version
54
20
  version: '0'
55
21
  type: :development
56
22
  prerelease: false
57
23
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
24
  requirements:
60
- - - ! '>='
25
+ - - '>='
61
26
  - !ruby/object:Gem::Version
62
27
  version: '0'
63
28
  - !ruby/object:Gem::Dependency
64
- name: guard-rspec
65
- requirement: !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ! '>='
69
- - !ruby/object:Gem::Version
70
- version: '0'
71
- type: :development
72
- prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ! '>='
77
- - !ruby/object:Gem::Version
78
- version: '0'
79
- - !ruby/object:Gem::Dependency
80
- name: growl
29
+ name: rspec
81
30
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
31
  requirements:
84
- - - ! '>='
32
+ - - '>='
85
33
  - !ruby/object:Gem::Version
86
34
  version: '0'
87
35
  type: :development
88
36
  prerelease: false
89
37
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
38
  requirements:
92
- - - ! '>='
39
+ - - '>='
93
40
  - !ruby/object:Gem::Version
94
41
  version: '0'
95
- description: Hashie is a small collection of tools that make hashes more powerful.
96
- Currently includes Mash (Mocking Hash) and Dash (Discrete Hash).
42
+ description: Hashie is a collection of classes and mixins that make hashes more powerful.
97
43
  email:
98
44
  - michael@intridea.com
99
45
  - jollyjerry@gmail.com
@@ -101,9 +47,9 @@ executables: []
101
47
  extensions: []
102
48
  extra_rdoc_files: []
103
49
  files:
104
- - .document
105
50
  - .gitignore
106
51
  - .rspec
52
+ - .rubocop.yml
107
53
  - .travis.yml
108
54
  - .yardopts
109
55
  - CHANGELOG.md
@@ -111,79 +57,82 @@ files:
111
57
  - Gemfile
112
58
  - Guardfile
113
59
  - LICENSE
114
- - README.markdown
60
+ - README.md
115
61
  - Rakefile
116
62
  - hashie.gemspec
117
63
  - lib/hashie.rb
118
64
  - lib/hashie/clash.rb
119
65
  - lib/hashie/dash.rb
120
66
  - lib/hashie/extensions/coercion.rb
67
+ - lib/hashie/extensions/deep_fetch.rb
121
68
  - lib/hashie/extensions/deep_merge.rb
69
+ - lib/hashie/extensions/ignore_undeclared.rb
122
70
  - lib/hashie/extensions/indifferent_access.rb
123
71
  - lib/hashie/extensions/key_conversion.rb
124
72
  - lib/hashie/extensions/merge_initializer.rb
125
73
  - lib/hashie/extensions/method_access.rb
126
- - lib/hashie/extensions/structure.rb
127
74
  - lib/hashie/hash.rb
128
75
  - lib/hashie/hash_extensions.rb
129
76
  - lib/hashie/mash.rb
77
+ - lib/hashie/rash.rb
130
78
  - lib/hashie/trash.rb
131
79
  - lib/hashie/version.rb
132
80
  - spec/hashie/clash_spec.rb
133
81
  - spec/hashie/dash_spec.rb
134
82
  - spec/hashie/extensions/coercion_spec.rb
83
+ - spec/hashie/extensions/deep_fetch_spec.rb
135
84
  - spec/hashie/extensions/deep_merge_spec.rb
85
+ - spec/hashie/extensions/ignore_undeclared_spec.rb
136
86
  - spec/hashie/extensions/indifferent_access_spec.rb
137
87
  - spec/hashie/extensions/key_conversion_spec.rb
138
88
  - spec/hashie/extensions/merge_initializer_spec.rb
139
89
  - spec/hashie/extensions/method_access_spec.rb
140
90
  - spec/hashie/hash_spec.rb
141
91
  - spec/hashie/mash_spec.rb
92
+ - spec/hashie/rash_spec.rb
142
93
  - spec/hashie/trash_spec.rb
94
+ - spec/hashie/version_spec.rb
143
95
  - spec/spec.opts
144
96
  - spec/spec_helper.rb
145
97
  homepage: https://github.com/intridea/hashie
146
98
  licenses:
147
99
  - MIT
100
+ metadata: {}
148
101
  post_install_message:
149
102
  rdoc_options: []
150
103
  require_paths:
151
104
  - lib
152
105
  required_ruby_version: !ruby/object:Gem::Requirement
153
- none: false
154
106
  requirements:
155
- - - ! '>='
107
+ - - '>='
156
108
  - !ruby/object:Gem::Version
157
109
  version: '0'
158
- segments:
159
- - 0
160
- hash: 214342929644806912
161
110
  required_rubygems_version: !ruby/object:Gem::Requirement
162
- none: false
163
111
  requirements:
164
- - - ! '>='
112
+ - - '>='
165
113
  - !ruby/object:Gem::Version
166
114
  version: '0'
167
- segments:
168
- - 0
169
- hash: 214342929644806912
170
115
  requirements: []
171
116
  rubyforge_project:
172
- rubygems_version: 1.8.23
117
+ rubygems_version: 2.0.14
173
118
  signing_key:
174
- specification_version: 3
175
- summary: Your friendly neighborhood hash toolkit.
119
+ specification_version: 4
120
+ summary: Your friendly neighborhood hash library.
176
121
  test_files:
177
122
  - spec/hashie/clash_spec.rb
178
123
  - spec/hashie/dash_spec.rb
179
124
  - spec/hashie/extensions/coercion_spec.rb
125
+ - spec/hashie/extensions/deep_fetch_spec.rb
180
126
  - spec/hashie/extensions/deep_merge_spec.rb
127
+ - spec/hashie/extensions/ignore_undeclared_spec.rb
181
128
  - spec/hashie/extensions/indifferent_access_spec.rb
182
129
  - spec/hashie/extensions/key_conversion_spec.rb
183
130
  - spec/hashie/extensions/merge_initializer_spec.rb
184
131
  - spec/hashie/extensions/method_access_spec.rb
185
132
  - spec/hashie/hash_spec.rb
186
133
  - spec/hashie/mash_spec.rb
134
+ - spec/hashie/rash_spec.rb
187
135
  - spec/hashie/trash_spec.rb
136
+ - spec/hashie/version_spec.rb
188
137
  - spec/spec.opts
189
138
  - spec/spec_helper.rb