xml-registry 0.5.0 → 0.5.1
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
- checksums.yaml.gz.sig +0 -0
- data/lib/xml-registry.rb +21 -18
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d340a550aa48a3f5fa2303c0265eb0d9d950966f
|
4
|
+
data.tar.gz: 8426520b1cdd99fe9d55129e7f2524fa8ec1c853
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7db78c63204b32540ea16516e45b545f0280b098b42de9a7bb32fb976830139ab3e192b2ac8065e34c8d70d1d8146884d80028c373df38d0e39435fd97b3db5
|
7
|
+
data.tar.gz: 37d2b6de36e8b614c687be60866e7a1ab55818898aad0bbe932b1e4427e06feff2b2fa0c7a0c9b72afc81bf00016ba3bef1780dff02ceccce3d88b7b4fa9aa70
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/xml-registry.rb
CHANGED
@@ -7,7 +7,19 @@
|
|
7
7
|
require 'simple-config'
|
8
8
|
|
9
9
|
|
10
|
+
module NumberCheck
|
11
|
+
|
12
|
+
refine String do
|
13
|
+
|
14
|
+
def is_number?
|
15
|
+
self.to_i.to_s == self
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
10
21
|
class XMLRegistry
|
22
|
+
using NumberCheck
|
11
23
|
|
12
24
|
attr_reader :doc
|
13
25
|
|
@@ -34,22 +46,20 @@ class XMLRegistry
|
|
34
46
|
|
35
47
|
# if the 1st element doesn't exist create it
|
36
48
|
e = path.split('/',2).first
|
37
|
-
|
38
49
|
@doc.root.add_element Rexle::Element.new(e) unless @doc.root.element e
|
39
50
|
create_path = find_path(path)
|
40
|
-
|
41
|
-
if not create_path.empty? then
|
42
51
|
|
43
|
-
|
44
|
-
parent_path = (
|
52
|
+
if not create_path.empty? then
|
53
|
+
parent_path = (path.split('/') - create_path.reverse).join('/')
|
45
54
|
key_builder(parent_path, create_path)
|
46
55
|
end
|
47
|
-
|
56
|
+
|
48
57
|
add_value(path, value)
|
49
58
|
end
|
50
59
|
|
51
60
|
def []=(path, val)
|
52
|
-
|
61
|
+
s = path.split('/').map {|x| x.is_number? ? x.prepend('x') : x}.join '/'
|
62
|
+
self.set_key(s, val)
|
53
63
|
end
|
54
64
|
|
55
65
|
# get the key value by passing the path
|
@@ -100,7 +110,8 @@ class XMLRegistry
|
|
100
110
|
end
|
101
111
|
|
102
112
|
def [](path)
|
103
|
-
|
113
|
+
s = path.split('/').map {|x| x.is_number? ? x.prepend('x') : x}.join '/'
|
114
|
+
@doc.root.element s
|
104
115
|
end
|
105
116
|
|
106
117
|
# delete the key at the specified path
|
@@ -202,28 +213,20 @@ class XMLRegistry
|
|
202
213
|
private
|
203
214
|
|
204
215
|
def add_key(path='app', key='untitled')
|
205
|
-
|
206
216
|
node = @doc.root.element path
|
207
217
|
r = node.add_element Rexle::Element.new(key)
|
208
218
|
r
|
209
|
-
|
210
219
|
end
|
211
220
|
|
212
221
|
def add_value(key, value)
|
213
|
-
|
214
|
-
@doc.root.element(s).text = value
|
222
|
+
@doc.root.element(key).text = value
|
215
223
|
end
|
216
224
|
|
217
225
|
def find_path(path, create_path=[])
|
218
226
|
|
219
227
|
return create_path if !@doc.root.xpath(path).empty?
|
220
228
|
apath = path.split('/')
|
221
|
-
|
222
|
-
x = apath.pop
|
223
|
-
|
224
|
-
x.prepend 'x' if x.to_i.to_s == x
|
225
|
-
create_path << x
|
226
|
-
|
229
|
+
create_path << apath.pop
|
227
230
|
find_path(apath.join('/'), create_path)
|
228
231
|
end
|
229
232
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|