dot_hash 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dot_hash/properties.rb +9 -1
- data/lib/dot_hash/settings.rb +1 -1
- data/lib/dot_hash/version.rb +1 -1
- data/test/dot_hash/properties_test.rb +25 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b6ebd2bd11ed70901028a8860a1de59a0e1f053
|
4
|
+
data.tar.gz: 15b93d20539be0617509dda4ceba4e7d5eab967e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f50f36f75d32a5423659b0b84926c0fec927b26a29ac9b40b86313c1d1aced78e21468b298d305630291ac4b72134da2d79a4857313b38fd9b9e9bf3dd4d93e
|
7
|
+
data.tar.gz: 7d5faa7864cd10a212384601423bb277c18b33238f68d4e34043a86d76adfc56c28249561d5a54e62cc77ebbb941748ac2a65f0a04ce67c257cd103f46698404
|
data/lib/dot_hash/properties.rb
CHANGED
@@ -40,8 +40,16 @@ module DotHash
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def execute(key, *args, &block)
|
43
|
+
klass = self.class
|
44
|
+
|
43
45
|
get_value(key) do
|
44
|
-
hash.public_send(key, *args
|
46
|
+
hash.public_send(key, *args) do |*values|
|
47
|
+
values = values.flatten.map do |a|
|
48
|
+
a.is_a?(Hash) ? klass.new(a) : a
|
49
|
+
end
|
50
|
+
|
51
|
+
block.call(*values)
|
52
|
+
end
|
45
53
|
end
|
46
54
|
end
|
47
55
|
|
data/lib/dot_hash/settings.rb
CHANGED
data/lib/dot_hash/version.rb
CHANGED
@@ -54,22 +54,37 @@ module DotHash
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
describe
|
57
|
+
describe 'method delegation' do
|
58
58
|
before do
|
59
|
-
@properties = Properties.new
|
59
|
+
@properties = Properties.new({
|
60
|
+
ninja: {name: 'Naruto'}
|
61
|
+
})
|
60
62
|
end
|
61
63
|
|
62
|
-
it
|
63
|
-
assert_equal
|
64
|
+
it 'converts innerhashes to Properties' do
|
65
|
+
assert_equal(
|
66
|
+
properties.map { |k, v| "#{k}: #{v.name}" },
|
67
|
+
['ninja: Naruto']
|
68
|
+
)
|
64
69
|
end
|
70
|
+
end
|
71
|
+
end
|
65
72
|
|
66
|
-
|
67
|
-
|
68
|
-
|
73
|
+
describe "#[]" do
|
74
|
+
before do
|
75
|
+
@properties = Properties.new user: { name: "dude" }
|
76
|
+
end
|
69
77
|
|
70
|
-
|
71
|
-
|
72
|
-
|
78
|
+
it "accesses properties like a symbol hash" do
|
79
|
+
assert_equal properties[:user][:name], "dude"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "accesses properties like a string hash" do
|
83
|
+
assert_equal properties["user"]["name"], "dude"
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'returns nil when value not present' do
|
87
|
+
assert_nil properties['missing']
|
73
88
|
end
|
74
89
|
end
|
75
90
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dot_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Eden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|