dot_hash 0.2.1 → 0.2.2
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/lib/dot_hash/properties.rb +5 -6
- data/lib/dot_hash/version.rb +1 -1
- data/test/dot_hash/properties_test.rb +9 -1
- metadata +3 -3
data/lib/dot_hash/properties.rb
CHANGED
@@ -11,9 +11,9 @@ module DotHash
|
|
11
11
|
has_key?(key) ? get_value(key) : super
|
12
12
|
end
|
13
13
|
|
14
|
-
def respond_to?(key
|
14
|
+
def respond_to?(key)
|
15
15
|
symbolize_key key
|
16
|
-
has_key?(key) or super(key
|
16
|
+
has_key?(key) or super(key)
|
17
17
|
end
|
18
18
|
|
19
19
|
def [](key)
|
@@ -24,14 +24,13 @@ module DotHash
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def has_key?(key)
|
27
|
-
hash.has_key?
|
27
|
+
hash.has_key?(key.to_sym) or hash.respond_to?(key)
|
28
28
|
end
|
29
29
|
|
30
30
|
def get_value(key)
|
31
31
|
key = key.to_sym
|
32
|
-
value = hash
|
33
|
-
return value unless value.is_a?
|
34
|
-
|
32
|
+
value = hash.fetch(key) { hash.send(key) }
|
33
|
+
return value unless value.is_a?(Hash)
|
35
34
|
hash[key] = self.class.new value
|
36
35
|
end
|
37
36
|
|
data/lib/dot_hash/version.rb
CHANGED
@@ -21,6 +21,10 @@ module DotHash
|
|
21
21
|
it "gets a property from a stringed key" do
|
22
22
|
properties.power.must_equal 100
|
23
23
|
end
|
24
|
+
|
25
|
+
it "gets all values from a given property" do
|
26
|
+
properties.values.must_equal ["15", 100]
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
describe "with a nested hash" do
|
@@ -75,7 +79,11 @@ module DotHash
|
|
75
79
|
end
|
76
80
|
|
77
81
|
it "doesn't respond to a missing property" do
|
78
|
-
properties.wont_respond_to :
|
82
|
+
properties.wont_respond_to :power
|
83
|
+
end
|
84
|
+
|
85
|
+
it "responds to public hash methods" do
|
86
|
+
properties.must_respond_to :keys
|
79
87
|
end
|
80
88
|
end
|
81
89
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dot_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -66,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
segments:
|
68
68
|
- 0
|
69
|
-
hash: -
|
69
|
+
hash: -567602207687414243
|
70
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
71
|
none: false
|
72
72
|
requirements:
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: '0'
|
76
76
|
segments:
|
77
77
|
- 0
|
78
|
-
hash: -
|
78
|
+
hash: -567602207687414243
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project:
|
81
81
|
rubygems_version: 1.8.24
|