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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b6ebd2bd11ed70901028a8860a1de59a0e1f053
4
- data.tar.gz: 15b93d20539be0617509dda4ceba4e7d5eab967e
3
+ metadata.gz: 2d5f5b5bc01c1658cb038945ccda5d6338021934
4
+ data.tar.gz: a138603a469cafba4ca1d925546a993d30d91a50
5
5
  SHA512:
6
- metadata.gz: 9f50f36f75d32a5423659b0b84926c0fec927b26a29ac9b40b86313c1d1aced78e21468b298d305630291ac4b72134da2d79a4857313b38fd9b9e9bf3dd4d93e
7
- data.tar.gz: 7d5faa7864cd10a212384601423bb277c18b33238f68d4e34043a86d76adfc56c28249561d5a54e62cc77ebbb941748ac2a65f0a04ce67c257cd103f46698404
6
+ metadata.gz: d08a88ae42624709175af9b7566ca88f786a680e88e255c28c587049f8f538c655dda4d1378fb17d93d21849bd5b989a036cda2f54f7b0d6ca061640a27df76e
7
+ data.tar.gz: 718c33b9a6031bceac6f2cdbd382174236c4da920b500027699fee040f3c643f4834231fd190f6b8d05685c6cfb280c3e98ff0570f5227f0a59583d2a6cb387e
@@ -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 = values.flatten.map do |a|
48
- a.is_a?(Hash) ? klass.new(a) : a
49
- end
49
+ block.call(*hashify_args(values))
50
+ end
51
+ end
52
+ end
50
53
 
51
- block.call(*values)
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
@@ -1,3 +1,3 @@
1
1
  module DotHash
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
@@ -61,15 +61,42 @@ module DotHash
61
61
  })
62
62
  end
63
63
 
64
- it 'converts innerhashes to Properties' do
65
- assert_equal(
66
- properties.map { |k, v| "#{k}: #{v.name}" },
67
- ['ninja: Naruto']
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" }
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: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Eden