dot_hash 1.1.2 → 1.1.3
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.
- checksums.yaml +4 -4
- data/lib/dot_hash/properties.rb +16 -6
- data/lib/dot_hash/version.rb +1 -1
- data/test/dot_hash/properties_test.rb +32 -5
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2d5f5b5bc01c1658cb038945ccda5d6338021934
|
|
4
|
+
data.tar.gz: a138603a469cafba4ca1d925546a993d30d91a50
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d08a88ae42624709175af9b7566ca88f786a680e88e255c28c587049f8f538c655dda4d1378fb17d93d21849bd5b989a036cda2f54f7b0d6ca061640a27df76e
|
|
7
|
+
data.tar.gz: 718c33b9a6031bceac6f2cdbd382174236c4da920b500027699fee040f3c643f4834231fd190f6b8d05685c6cfb280c3e98ff0570f5227f0a59583d2a6cb387e
|
data/lib/dot_hash/properties.rb
CHANGED
|
@@ -19,6 +19,10 @@ module DotHash
|
|
|
19
19
|
has_key?(key) or super(key, *args)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
def ==(other)
|
|
23
|
+
super || other.to_hash == hash
|
|
24
|
+
end
|
|
25
|
+
|
|
22
26
|
def to_s
|
|
23
27
|
hash.to_s
|
|
24
28
|
end
|
|
@@ -40,15 +44,21 @@ module DotHash
|
|
|
40
44
|
end
|
|
41
45
|
|
|
42
46
|
def execute(key, *args, &block)
|
|
43
|
-
klass = self.class
|
|
44
|
-
|
|
45
47
|
get_value(key) do
|
|
46
48
|
hash.public_send(key, *args) do |*values|
|
|
47
|
-
values
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
block.call(*hashify_args(values))
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
50
53
|
|
|
51
|
-
|
|
54
|
+
def hashify_args(args)
|
|
55
|
+
args.map do |a|
|
|
56
|
+
if a.is_a?(Hash)
|
|
57
|
+
self.class.new(a)
|
|
58
|
+
elsif a.is_a?(Array)
|
|
59
|
+
hashify_args(a)
|
|
60
|
+
else
|
|
61
|
+
a
|
|
52
62
|
end
|
|
53
63
|
end
|
|
54
64
|
end
|
data/lib/dot_hash/version.rb
CHANGED
|
@@ -61,15 +61,42 @@ module DotHash
|
|
|
61
61
|
})
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
it '
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
it '#map sets inner-hashes to Properties' do
|
|
65
|
+
result = properties.map { |k, v| "#{k}: #{v.name}" }
|
|
66
|
+
|
|
67
|
+
assert_equal result, ['ninja: Naruto']
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it '#each_with_object goes nested on block args' do
|
|
71
|
+
result = properties.each_with_object({}) do |(k, v), acc|
|
|
72
|
+
acc[k] = v.name
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
assert_equal result, Properties.new({ninja: 'Naruto'})
|
|
69
76
|
end
|
|
70
77
|
end
|
|
71
78
|
end
|
|
72
79
|
|
|
80
|
+
describe '#==' do
|
|
81
|
+
before do
|
|
82
|
+
@properties = Properties.new({
|
|
83
|
+
ninja: {name: 'Naruto'}
|
|
84
|
+
})
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'is equal to it self' do
|
|
88
|
+
assert_equal properties, properties
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it 'is equal to its hash' do
|
|
92
|
+
assert_equal properties, {ninja: {name: 'Naruto'}}
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it 'is equal to its copy' do
|
|
96
|
+
assert_equal properties, Properties.new(properties.hash)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
73
100
|
describe "#[]" do
|
|
74
101
|
before do
|
|
75
102
|
@properties = Properties.new user: { name: "dude" }
|