hashie 1.1.0 → 1.2.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.
- data/.travis.yml +1 -0
- data/Gemfile.lock +2 -1
- data/lib/hashie/hash.rb +4 -3
- data/lib/hashie/hash_extensions.rb +1 -1
- data/lib/hashie/mash.rb +11 -2
- data/lib/hashie/version.rb +1 -1
- data/spec/hashie/dash_spec.rb +2 -2
- data/spec/hashie/hash_spec.rb +12 -2
- data/spec/hashie/mash_spec.rb +8 -16
- data/spec/spec_helper.rb +0 -1
- metadata +13 -14
- data/VERSION +0 -1
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/lib/hashie/hash.rb
CHANGED
@@ -7,11 +7,12 @@ module Hashie
|
|
7
7
|
class Hash < Hash
|
8
8
|
include Hashie::HashExtensions
|
9
9
|
|
10
|
-
# Converts a mash back to a hash
|
11
|
-
def to_hash
|
10
|
+
# Converts a mash back to a hash.
|
11
|
+
def to_hash(options = {})
|
12
12
|
out = {}
|
13
13
|
keys.each do |k|
|
14
|
-
|
14
|
+
key = options[:symbolize_keys] ? k.to_sym : k.to_s
|
15
|
+
out[key] = Hashie::Hash === self[k] ? self[k].to_hash : self[k]
|
15
16
|
end
|
16
17
|
out
|
17
18
|
end
|
data/lib/hashie/mash.rb
CHANGED
@@ -55,7 +55,13 @@ module Hashie
|
|
55
55
|
default ? super(default) : super(&blk)
|
56
56
|
end
|
57
57
|
|
58
|
-
class << self
|
58
|
+
class << self
|
59
|
+
alias [] new
|
60
|
+
|
61
|
+
def subkey_class
|
62
|
+
self
|
63
|
+
end
|
64
|
+
end
|
59
65
|
|
60
66
|
def id #:nodoc:
|
61
67
|
key?("id") ? self["id"] : super
|
@@ -104,6 +110,9 @@ module Hashie
|
|
104
110
|
def key?(key)
|
105
111
|
super(convert_key(key))
|
106
112
|
end
|
113
|
+
alias_method :has_key?, :key?
|
114
|
+
alias_method :include?, :key?
|
115
|
+
alias_method :member?, :key?
|
107
116
|
|
108
117
|
# Performs a deep_update on a duplicate of the
|
109
118
|
# current mash.
|
@@ -177,7 +186,7 @@ module Hashie
|
|
177
186
|
val.dup
|
178
187
|
when ::Hash
|
179
188
|
val = val.dup if duping
|
180
|
-
self.class.new(val)
|
189
|
+
self.class.subkey_class.new.merge(val)
|
181
190
|
when Array
|
182
191
|
val.collect{ |e| convert_value(e) }
|
183
192
|
else
|
data/lib/hashie/version.rb
CHANGED
data/spec/hashie/dash_spec.rb
CHANGED
@@ -28,12 +28,12 @@ describe DashTest do
|
|
28
28
|
|
29
29
|
it('subclasses Hashie::Hash') { should respond_to(:to_mash) }
|
30
30
|
|
31
|
-
its(:to_s) { should == '
|
31
|
+
its(:to_s) { should == '#<DashTest count=0 email="bob@example.com" first_name="Bob">' }
|
32
32
|
|
33
33
|
it 'lists all set properties in inspect' do
|
34
34
|
subject.first_name = 'Bob'
|
35
35
|
subject.email = 'bob@example.com'
|
36
|
-
subject.inspect.should == '
|
36
|
+
subject.inspect.should == '#<DashTest count=0 email="bob@example.com" first_name="Bob">'
|
37
37
|
end
|
38
38
|
|
39
39
|
its(:count) { should be_zero }
|
data/spec/hashie/hash_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Hash do
|
3
|
+
describe Hashie::Hash do
|
4
4
|
it "should be convertible to a Hashie::Mash" do
|
5
5
|
mash = Hashie::Hash[:some => "hash"].to_mash
|
6
6
|
mash.is_a?(Hashie::Mash).should be_true
|
@@ -19,4 +19,14 @@ describe Hash do
|
|
19
19
|
hash.should == Hashie::Hash[:a => "hey", 123 => "bob"]
|
20
20
|
stringified_hash.should == Hashie::Hash["a" => "hey", "123" => "bob"]
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
|
+
describe '#to_hash' do
|
24
|
+
it 'should convert it to a hash with string keys by default' do
|
25
|
+
Hashie::Hash.new.merge(:a => 'hey', :b => 'foo').to_hash.should == {'a' => 'hey', 'b' => 'foo'}
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should convert to a hash with symbol keys if :symbolize_keys is passed in' do
|
29
|
+
Hashie::Hash.new.merge('a' => 'hey', 'b' => 'doo').to_hash(:symbolize_keys => true).should == {:a => 'hey', :b => 'doo'}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/hashie/mash_spec.rb
CHANGED
@@ -225,16 +225,6 @@ describe Hashie::Mash do
|
|
225
225
|
it 'should respond to a set key' do
|
226
226
|
Hashie::Mash.new(:abc => 'def').should be_respond_to(:abc)
|
227
227
|
end
|
228
|
-
|
229
|
-
it "should delegate properly using delegate library" do
|
230
|
-
class MashDelegate < DelegateClass(Hashie::Mash)
|
231
|
-
end
|
232
|
-
|
233
|
-
delegate = MashDelegate.new(Hashie::Mash.new(:foo => 100))
|
234
|
-
delegate.foo.should == 100
|
235
|
-
delegate.should respond_to(:foo)
|
236
|
-
expect { delegate.bar }.to raise_error(NoMethodError)
|
237
|
-
end
|
238
228
|
end
|
239
229
|
|
240
230
|
context "#initialize" do
|
@@ -276,13 +266,15 @@ describe Hashie::Mash do
|
|
276
266
|
initial.test?.should be_true
|
277
267
|
end
|
278
268
|
|
279
|
-
describe
|
269
|
+
describe '.subkey_class' do
|
270
|
+
it 'should be able to define a subkey class different from itself' do
|
271
|
+
class CustomSubkeyHash < Hashie::Mash
|
272
|
+
def self.subkey_class; Hashie::Mash end
|
273
|
+
end
|
280
274
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
expected = {"foo" => "bar", "bar" => {"homer" => "simpson"}}
|
285
|
-
JSON.parse(@mash.to_json).should == expected
|
275
|
+
subhash = CustomSubkeyHash.new(:subhash => {:abc => :def})[:subhash]
|
276
|
+
subhash.should_not be_kind_of(CustomSubkeyHash)
|
277
|
+
subhash.should be_kind_of(Hashie::Mash)
|
286
278
|
end
|
287
279
|
end
|
288
280
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-10-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70100391048320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.9.2
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70100391048320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70100391047700 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '2.5'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70100391047700
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: guard
|
38
|
-
requirement: &
|
38
|
+
requirement: &70100391047200 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70100391047200
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: guard-rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70100391046540 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70100391046540
|
58
58
|
description: Hashie is a small collection of tools that make hashes more powerful.
|
59
59
|
Currently includes Mash (Mocking Hash) and Dash (Discrete Hash).
|
60
60
|
email:
|
@@ -73,7 +73,6 @@ files:
|
|
73
73
|
- LICENSE
|
74
74
|
- README.rdoc
|
75
75
|
- Rakefile
|
76
|
-
- VERSION
|
77
76
|
- hashie.gemspec
|
78
77
|
- lib/hashie.rb
|
79
78
|
- lib/hashie/clash.rb
|
@@ -104,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
103
|
version: '0'
|
105
104
|
segments:
|
106
105
|
- 0
|
107
|
-
hash:
|
106
|
+
hash: 839965074967514567
|
108
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
108
|
none: false
|
110
109
|
requirements:
|
@@ -113,10 +112,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
112
|
version: '0'
|
114
113
|
segments:
|
115
114
|
- 0
|
116
|
-
hash:
|
115
|
+
hash: 839965074967514567
|
117
116
|
requirements: []
|
118
117
|
rubyforge_project:
|
119
|
-
rubygems_version: 1.8.
|
118
|
+
rubygems_version: 1.8.10
|
120
119
|
signing_key:
|
121
120
|
specification_version: 3
|
122
121
|
summary: Your friendly neighborhood hash toolkit.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.0
|