hpath 0.0.3 → 0.0.4

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: 8a89f4dea22fe5b719e3f2c4402806bc07eb0676
4
- data.tar.gz: 8a49750d03f96bfaf46c1a50181778d99eecea08
3
+ metadata.gz: e1f0a047d687a7f9cb64a837e1d21f828bdd0669
4
+ data.tar.gz: 28436f6c1f1ac651a86538ac62f18dc26a5a6868
5
5
  SHA512:
6
- metadata.gz: ffed5bced9a44c68d3d7d85b54580bec011178371519b4827daae79236d9230decf7ffcd6eb58eba2a8596be83490434ec1559032fe8a4308534ff1840c7c1f8
7
- data.tar.gz: a777601d83a4633630ff28ce802577e25fe702a8ff767aa30cc20b922d51814ec986c39d1bbd8690ebd68429ee1a0d6361e24656a3f08d71dc84547952985741
6
+ metadata.gz: d4c027c8649247847b822779fe2e7eea12a10d6261deb1a919ffe40724f3c62271c7dea7c40023558142224ca0db4e1f5808c32e9b3c8f567f9fd6ab6702eb6d
7
+ data.tar.gz: f8a946b78d622f3a5b509177a8f040acb0043718fd88705552668c65272878ec61c1560cc6359466575d265854d5cb5548ab680f6d834ea7cd345d9c0b214e57
@@ -46,12 +46,6 @@ module Hpath
46
46
 
47
47
  def self._set(object, paths, value)
48
48
  if paths.empty?
49
- if object.is_a?(Array)
50
- object.push(value)
51
- elsif object.is_a?(Hash)
52
- object.merge!(value)
53
- end
54
-
55
49
  return
56
50
  else
57
51
  path = paths.shift
@@ -60,12 +54,24 @@ module Hpath
60
54
  if (_object = self._get(object, [path])).nil?
61
55
  if object.is_a?(Array)
62
56
  if path[:type] == Array
63
- object.push(_object = [])
57
+ unless paths.empty?
58
+ object.push(_object = [])
59
+ else
60
+ object.push(_object = value)
61
+ end
64
62
  elsif path[:type] == Hash
65
- object.push({ path[:identifier].to_sym => (_object = {}) })
63
+ unless paths.empty?
64
+ object.push({ path[:identifier].to_sym => (_object = {}) })
65
+ else
66
+ object.push({ path[:identifier].to_sym => (_object = value) })
67
+ end
66
68
  end
67
69
  elsif object.is_a?(Hash)
68
- object[path[:identifier].to_sym] = (_object = path[:type].new)
70
+ unless paths.empty?
71
+ object[path[:identifier].to_sym] = (_object = path[:type].new)
72
+ else
73
+ object[path[:identifier].to_sym] = (_object = value)
74
+ end
69
75
  end
70
76
  end
71
77
 
@@ -1,3 +1,3 @@
1
1
  module Hpath
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -91,6 +91,11 @@ describe Hpath do
91
91
  Hpath.set(hash = {}, "/key1[]/bar", { foo: "bar"})
92
92
  expect(hash).to eq({key1: [{bar: {foo: "bar"}}]})
93
93
  end
94
+
95
+ it "processes \"/key1\" = 1 for a hash" do
96
+ Hpath.set(hash = {}, "/key1", 1)
97
+ expect(hash).to eq({key1: 1})
98
+ end
94
99
  end
95
100
  end
96
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hpath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Sievers