hashie-pre 2.0.0.beta
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.
- data/.document +5 -0
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/.yardopts +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +36 -0
- data/Guardfile +5 -0
- data/LICENSE +20 -0
- data/README.markdown +232 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/hashie.gemspec +22 -0
- data/lib/hashie.rb +23 -0
- data/lib/hashie/clash.rb +86 -0
- data/lib/hashie/dash.rb +150 -0
- data/lib/hashie/extensions/coercion.rb +101 -0
- data/lib/hashie/extensions/deep_merge.rb +7 -0
- data/lib/hashie/extensions/indifferent_access.rb +110 -0
- data/lib/hashie/extensions/key_conversion.rb +52 -0
- data/lib/hashie/extensions/merge_initializer.rb +24 -0
- data/lib/hashie/extensions/method_access.rb +124 -0
- data/lib/hashie/extensions/structure.rb +47 -0
- data/lib/hashie/hash.rb +31 -0
- data/lib/hashie/hash_extensions.rb +49 -0
- data/lib/hashie/mash.rb +216 -0
- data/lib/hashie/trash.rb +77 -0
- data/lib/hashie/version.rb +3 -0
- data/spec/hashie/clash_spec.rb +42 -0
- data/spec/hashie/dash_spec.rb +215 -0
- data/spec/hashie/extensions/coercion_spec.rb +70 -0
- data/spec/hashie/extensions/indifferent_access_spec.rb +66 -0
- data/spec/hashie/extensions/key_conversion_spec.rb +66 -0
- data/spec/hashie/extensions/merge_initializer_spec.rb +20 -0
- data/spec/hashie/extensions/method_access_spec.rb +112 -0
- data/spec/hashie/hash_spec.rb +22 -0
- data/spec/hashie/mash_spec.rb +305 -0
- data/spec/hashie/trash_spec.rb +139 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +12 -0
- metadata +181 -0
@@ -0,0 +1,139 @@
|
|
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
|
+
TrashTest.properties.should include(:first_name)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'creates a method for reading the property' do
|
16
|
+
trash.should respond_to(:first_name)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'creates a method for writing the property' do
|
20
|
+
trash.should respond_to(:first_name=)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'creates a method for writing the translated property' do
|
24
|
+
trash.should respond_to(:firstName=)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'does not create a method for reading the translated property' do
|
28
|
+
trash.should_not respond_to(:firstName)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'writing to properties' do
|
33
|
+
|
34
|
+
it 'does not write to a non-existent property using []=' do
|
35
|
+
lambda{trash['abc'] = 123}.should raise_error(NoMethodError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'writes to an existing property using []=' do
|
39
|
+
lambda{trash['first_name'] = 'Bob'}.should_not raise_error
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'writes to a translated property using []=' do
|
43
|
+
lambda{trash['firstName'] = 'Bob'}.should_not raise_error
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'reads/writes to an existing property using a method call' do
|
47
|
+
trash.first_name = 'Franklin'
|
48
|
+
trash.first_name.should == 'Franklin'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'writes to an translated property using a method call' do
|
52
|
+
trash.firstName = 'Franklin'
|
53
|
+
trash.first_name.should == 'Franklin'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe ' initializing with a Hash' do
|
58
|
+
it 'does not initialize non-existent properties' do
|
59
|
+
lambda{TrashTest.new(:bork => 'abc')}.should raise_error(NoMethodError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'sets the desired properties' do
|
63
|
+
TrashTest.new(:first_name => 'Michael').first_name.should == 'Michael'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'sets the translated properties' do
|
67
|
+
TrashTest.new(:firstName => 'Michael').first_name.should == 'Michael'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'translating properties using a proc' do
|
72
|
+
class TrashLambdaTest < Hashie::Trash
|
73
|
+
property :first_name, :from => :firstName, :with => lambda { |value| value.reverse }
|
74
|
+
end
|
75
|
+
|
76
|
+
let(:lambda_trash) { TrashLambdaTest.new }
|
77
|
+
|
78
|
+
it 'should translate the value given on initialization with the given lambda' do
|
79
|
+
TrashLambdaTest.new(:firstName => 'Michael').first_name.should == 'Michael'.reverse
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should not translate the value if given with the right property' do
|
83
|
+
TrashTest.new(:first_name => 'Michael').first_name.should == 'Michael'
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should translate the value given as property with the given lambda' do
|
87
|
+
lambda_trash.firstName = 'Michael'
|
88
|
+
lambda_trash.first_name.should == 'Michael'.reverse
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should not translate the value given as right property' do
|
92
|
+
lambda_trash.first_name = 'Michael'
|
93
|
+
lambda_trash.first_name.should == 'Michael'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'translating properties without from option using a proc' do
|
98
|
+
|
99
|
+
class TrashLambdaTest2 < Hashie::Trash
|
100
|
+
property :first_name, :transform_with => lambda { |value| value.reverse }
|
101
|
+
end
|
102
|
+
|
103
|
+
let(:lambda_trash) { TrashLambdaTest2.new }
|
104
|
+
|
105
|
+
it 'should translate the value given as property with the given lambda' do
|
106
|
+
lambda_trash.first_name = 'Michael'
|
107
|
+
lambda_trash.first_name.should == 'Michael'.reverse
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should transform the value when given in constructor' do
|
111
|
+
TrashLambdaTest2.new(:first_name => 'Michael').first_name.should == 'Michael'.reverse
|
112
|
+
end
|
113
|
+
|
114
|
+
context "when :from option is given" do
|
115
|
+
class TrashLambdaTest3 < Hashie::Trash
|
116
|
+
property :first_name, :from => :firstName, :transform_with => lambda { |value| value.reverse }
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should not override the :from option in the constructor' do
|
120
|
+
TrashLambdaTest3.new(:first_name => 'Michael').first_name.should == 'Michael'
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should not override the :from option when given as property' do
|
124
|
+
t = TrashLambdaTest3.new
|
125
|
+
t.first_name = 'Michael'
|
126
|
+
t.first_name.should == 'Michael'
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should raise an error when :from have the same value as property" do
|
133
|
+
expect {
|
134
|
+
class WrongTrash < Hashie::Trash
|
135
|
+
property :first_name, :from => :first_name
|
136
|
+
end
|
137
|
+
}.to raise_error(ArgumentError)
|
138
|
+
end
|
139
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hashie-pre
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0.beta
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Bleigh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.9.2
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.9.2
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.5'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.5'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: guard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: guard-rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: growl
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Hashie is a small collection of tools that make hashes more powerful.
|
95
|
+
Currently includes Mash (Mocking Hash) and Dash (Discrete Hash).
|
96
|
+
email:
|
97
|
+
- michael@intridea.com
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .document
|
103
|
+
- .gitignore
|
104
|
+
- .rspec
|
105
|
+
- .travis.yml
|
106
|
+
- .yardopts
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- Guardfile
|
110
|
+
- LICENSE
|
111
|
+
- README.markdown
|
112
|
+
- Rakefile
|
113
|
+
- VERSION
|
114
|
+
- hashie.gemspec
|
115
|
+
- lib/hashie.rb
|
116
|
+
- lib/hashie/clash.rb
|
117
|
+
- lib/hashie/dash.rb
|
118
|
+
- lib/hashie/extensions/coercion.rb
|
119
|
+
- lib/hashie/extensions/deep_merge.rb
|
120
|
+
- lib/hashie/extensions/indifferent_access.rb
|
121
|
+
- lib/hashie/extensions/key_conversion.rb
|
122
|
+
- lib/hashie/extensions/merge_initializer.rb
|
123
|
+
- lib/hashie/extensions/method_access.rb
|
124
|
+
- lib/hashie/extensions/structure.rb
|
125
|
+
- lib/hashie/hash.rb
|
126
|
+
- lib/hashie/hash_extensions.rb
|
127
|
+
- lib/hashie/mash.rb
|
128
|
+
- lib/hashie/trash.rb
|
129
|
+
- lib/hashie/version.rb
|
130
|
+
- spec/hashie/clash_spec.rb
|
131
|
+
- spec/hashie/dash_spec.rb
|
132
|
+
- spec/hashie/extensions/coercion_spec.rb
|
133
|
+
- spec/hashie/extensions/indifferent_access_spec.rb
|
134
|
+
- spec/hashie/extensions/key_conversion_spec.rb
|
135
|
+
- spec/hashie/extensions/merge_initializer_spec.rb
|
136
|
+
- spec/hashie/extensions/method_access_spec.rb
|
137
|
+
- spec/hashie/hash_spec.rb
|
138
|
+
- spec/hashie/mash_spec.rb
|
139
|
+
- spec/hashie/trash_spec.rb
|
140
|
+
- spec/spec.opts
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
homepage: https://github.com/intridea/hashie
|
143
|
+
licenses: []
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
segments:
|
155
|
+
- 0
|
156
|
+
hash: -767890222242089125
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ! '>'
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: 1.3.1
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 1.8.23
|
166
|
+
signing_key:
|
167
|
+
specification_version: 3
|
168
|
+
summary: Your friendly neighborhood hash toolkit.
|
169
|
+
test_files:
|
170
|
+
- spec/hashie/clash_spec.rb
|
171
|
+
- spec/hashie/dash_spec.rb
|
172
|
+
- spec/hashie/extensions/coercion_spec.rb
|
173
|
+
- spec/hashie/extensions/indifferent_access_spec.rb
|
174
|
+
- spec/hashie/extensions/key_conversion_spec.rb
|
175
|
+
- spec/hashie/extensions/merge_initializer_spec.rb
|
176
|
+
- spec/hashie/extensions/method_access_spec.rb
|
177
|
+
- spec/hashie/hash_spec.rb
|
178
|
+
- spec/hashie/mash_spec.rb
|
179
|
+
- spec/hashie/trash_spec.rb
|
180
|
+
- spec/spec.opts
|
181
|
+
- spec/spec_helper.rb
|