xml-registry 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 280ac5c817560aa72e83c93eabf4358d1a169781717442b7b4e2c7ee95ca1ec0
4
- data.tar.gz: 0a8a32baea55901636b3a28ef6b585393883f4717107b17af84a46365a0c8658
3
+ metadata.gz: 17d687a31b3101edd8cb0f580e2e2d186223312ffe3ad3f983ebf6a6c3f4ad2c
4
+ data.tar.gz: cead0b3b39344282cccd54c70c3e747141359eede388f484a9b4488d298be088
5
5
  SHA512:
6
- metadata.gz: af319f07195089806be005eb10b42267e359a65c6f668ccda8ba618b3b36019c433abede751bf10e5d7dadfdb1c3719309538db765bb56c1e7933fc528f42a56
7
- data.tar.gz: a5bddd352a8865dc253cda635dde28a6ba8b66c1ad094c9b2cf5368bb1e74b32164cc8c7e2e9240be7e4e9f25d047a5ffcf1d1ed395ba748dbdf2498a376aca2
6
+ metadata.gz: a0d742f5b7e4f5f346bc5e30c3398954f702e940da670488d23dcb4512226706d6e662c45736a55908e888f2c11ff99a3d9241ff15b9070bd10ffe9e1f8aee6e
7
+ data.tar.gz: d25d7ec9f895d5fe89524fa3f0cf4556c1ca4d9b1106e3a886fad1f8fba36b57d4b3c9e22eb9231f7a1292acd5243ca5468285e8bb9a514a8d526a221622ca8b
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/xml-registry.rb CHANGED
@@ -10,13 +10,13 @@ require 'rxfreadwrite'
10
10
 
11
11
 
12
12
  module NumberCheck
13
-
13
+
14
14
  refine String do
15
-
15
+
16
16
  def is_number?
17
17
  self.to_i.to_s == self
18
18
  end
19
-
19
+
20
20
  end
21
21
  end
22
22
 
@@ -25,9 +25,9 @@ class XMLRegistry
25
25
  include RXFReadWriteModule
26
26
 
27
27
  attr_reader :doc
28
-
28
+
29
29
  def initialize(template = '<root></root>', debug: false)
30
-
30
+
31
31
  @debug = debug
32
32
  super()
33
33
  @template, _ = RXFReader.read(template)
@@ -52,21 +52,21 @@ class XMLRegistry
52
52
  # if the 1st element doesn't exist create it
53
53
  e = path.split('/',2).first
54
54
  @doc.root.add_element Rexle::Element.new(e) unless @doc.root.element e
55
- create_path = find_path(path)
55
+ create_path = find_path(path)
56
56
 
57
57
  if not create_path.empty? then
58
58
  parent_path = (path.split('/') - create_path.reverse).join('/')
59
59
  key_builder(parent_path, create_path)
60
60
  end
61
-
62
- add_value(path, value)
61
+
62
+ add_value(path, value)
63
63
  end
64
64
 
65
65
  def []=(path, val)
66
66
  s = path.split('/').map {|x| x[0].is_number? ? x.prepend('x') : x}.join '/'
67
67
  self.set_key(s, val)
68
68
  end
69
-
69
+
70
70
  # get the key value by passing the path
71
71
  # example: get_key('app/gtd/funday').value #=> 'friday'
72
72
  #
@@ -75,14 +75,15 @@ class XMLRegistry
75
75
  def get_key(path)
76
76
 
77
77
  key = @doc.root.element path
78
- raise ("xml-registry: key %s not found" % path) unless key
79
-
80
- key.instance_eval {
81
- @path = path
78
+ #raise ("xml-registry: key %s not found" % path) unless key
79
+ return nil unless key
80
+
81
+ key.instance_eval {
82
+ @path = path
82
83
 
83
84
  def to_h(e)
84
85
 
85
- v = if e.has_elements? then
86
+ v = if e.has_elements? then
86
87
  e.elements.inject({}) do |r, x|
87
88
  r.merge to_h(x)
88
89
  end
@@ -91,24 +92,24 @@ class XMLRegistry
91
92
  end
92
93
 
93
94
  {e.name => v}
94
- end
95
-
96
- def to_config()
95
+ end
96
+
97
+ def to_config()
97
98
  SimpleConfig.new(to_h(self), attributes: {key: @path})
98
- end
99
-
100
- def to_kvx()
99
+ end
100
+
101
+ def to_kvx()
101
102
  Kvx.new(to_h(self), attributes: {key: @path})
102
- end
103
-
103
+ end
104
+
104
105
  def to_os()
105
106
  OpenStruct.new(to_h(self).first.last)
106
107
  end
107
108
  }
108
-
109
+
109
110
  key
110
111
  end
111
-
112
+
112
113
  # get several keys using a Rexle XPath
113
114
  # example: get_keys('//funday') #=> [<funday>tuesday</funday>,<funday>friday</funday>]
114
115
  #
@@ -116,7 +117,7 @@ class XMLRegistry
116
117
  #
117
118
  def get_keys(path)
118
119
  @doc.root.xpath(path)
119
- end
120
+ end
120
121
 
121
122
  def [](path)
122
123
  s = path.split('/').map {|x| x.is_number? ? x.prepend('x') : x}.join '/'
@@ -128,7 +129,7 @@ class XMLRegistry
128
129
  #
129
130
  #
130
131
  def delete_key(path)
131
- @doc.root.delete path
132
+ @doc.root.delete path
132
133
  end
133
134
 
134
135
  # return the registry as an XML document
@@ -139,14 +140,14 @@ class XMLRegistry
139
140
  end
140
141
 
141
142
  alias :display_xml :to_xml
142
-
143
+
143
144
  def xml(options={})
144
145
  @doc.root.xml options
145
- end
146
+ end
146
147
 
147
148
  # load a new registry xml document replacing the existing registry
148
149
  #
149
- def load_xml(s='')
150
+ def load_xml(s='')
150
151
  @doc = Rexle.new(RXFReader.read(s)[0].force_encoding("UTF-8"))
151
152
  self
152
153
  end
@@ -171,40 +172,40 @@ class XMLRegistry
171
172
  #"pin-no"="4321"
172
173
  #REG
173
174
  #
174
- #reg = XMLRegistry.new
175
- #reg.import s
175
+ #reg = XMLRegistry.new
176
+ #reg.import s
176
177
  #
177
- def import(s)
178
-
178
+ def import(s)
179
+
179
180
  r = RXFReader.read(s)
180
181
  reg_buffer = r.first
181
182
  raise "read file error" unless reg_buffer
182
183
 
183
184
  if reg_buffer.strip[/^\[/] then
184
185
 
185
- reg_items = reg_buffer.gsub(/\n/,'').split(/(?=\[.[^\]]+\])/).map do |x|
186
+ reg_items = reg_buffer.gsub(/\n/,'').split(/(?=\[.[^\]]+\])/).map do |x|
186
187
  [x[/^\[(.[^\]]+)\]/,1], Hash[*($').scan(/"([^"]+)"="(.[^"]*)"/).flatten]]
187
188
  end
188
-
189
- elsif reg_buffer.strip.lines.grep(/^\s+\w/).any?
189
+
190
+ elsif reg_buffer.strip.lines.grep(/^\s+\w/).any?
190
191
 
191
192
  puts 'hierachical import' if @debug
192
193
  doc = LineTree.new(reg_buffer).to_doc
193
-
194
+
194
195
  reg_items = []
195
-
196
+
196
197
  doc.root.each_recursive do |e|
197
-
198
+
198
199
  puts 'e: ' + e.inspect if @debug
199
200
  if e.is_a?(Rexle::Element) and e.children.length < 2 then
200
-
201
+
201
202
  reg_items << [e.backtrack.to_xpath.sub(/^root\//,'')\
202
203
  .sub(/\/[^\/]+$/,''), {e.name => e.text }]
203
-
204
+
204
205
  end
205
-
206
- end
207
-
206
+
207
+ end
208
+
208
209
  else
209
210
 
210
211
  reg_items = reg_buffer.split(/(?=^[^:]+$)/).map do |raw_section|
@@ -214,21 +215,21 @@ class XMLRegistry
214
215
  path = lines.shift.rstrip
215
216
  [path, Hash[lines.map{|x| x.split(':',2).map(&:strip)}]]
216
217
  end
217
-
218
+
218
219
  reg_items.compact!
219
-
220
+
220
221
  end
221
222
 
222
223
  puts 'reg_items: ' + reg_items.inspect if @debug
223
224
  reg_items.each do |path, items|
224
225
  items.each {|k,value| self.set_key("%s/%s" % [path,k], value)}
225
226
  end
226
-
227
+
227
228
  :import
228
229
  end
229
230
 
230
- # Export the registry to file if the filepath is specified. Regardless,
231
- # the registry will be returned as a string in the registry
231
+ # Export the registry to file if the filepath is specified. Regardless,
232
+ # the registry will be returned as a string in the registry
232
233
  # export format.
233
234
  #
234
235
  def export(s=nil)
@@ -270,21 +271,21 @@ class XMLRegistry
270
271
 
271
272
  def print_scan(node, parent=[])
272
273
  out = []
273
- parent << node.name
274
+ parent << node.name
274
275
  items = []
275
276
 
276
277
  node.elements.each do |e|
277
278
  if e.has_elements? then
278
- out << print_scan(e, parent.clone)
279
+ out << print_scan(e, parent.clone)
279
280
  else
280
281
  items << [e.name, e.text]
281
282
  end
282
- end
283
+ end
283
284
  if parent.length > 1 and items.length > 0 then
284
- out << "[%s]\n%s\n" % [parent[1..-1].join("/"),
285
- items.map {|x| "\"%s\"=\"%s\"" % x}.join("\n")]
285
+ out << "[%s]\n%s\n" % [parent[1..-1].join("/"),
286
+ items.map {|x| "\"%s\"=\"%s\"" % x}.join("\n")]
286
287
  end
287
- out
288
+ out
288
289
  end
289
290
 
290
291
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xml-registry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,32 +10,33 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjIwMjE2MTgwNzIwWhcN
15
- MjMwMjE2MTgwNzIwWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCv4BVt
17
- KmxkdjLW52PT4ZpVyDRfU5n/5KT/SUpKglcEix9tF6khOYvkMv1p/vLIdDliIJUD
18
- q+VsQ+2sSn59ueuP9Cp3O3ccgPfC6+gKR/biRSsxwgH4+bik77520XkroRR6bz2c
19
- Zj1D1y2iE8TJ15LL25wumPkr6qL9eEL7TnrS+kGTRHbTC3IphSHDuryJlevTcNa4
20
- F7dgNiAA5rsSWoqwnu+Em3zvcP5eb/+s0EhXIpccMXskztj0tZyXdH79HFGrtNwF
21
- UygeIsPRnQrD0JQBGFxsNrWJdayqQGRnrISTvcMqE3HpRnPPIesliGFK/ykxcPJa
22
- Pz+RfQPug9TI83zu/jDjBtITm5pLzRSCgwljUFy1JbnL6M0YYqTTbbr3GjwOBWJI
23
- cpjB/njMf4CYsDI+SSd8POLdfSjGIeJt306JG9pJb+nKSuQ8V/omEXiKBOyxn510
24
- 81gTyE55i5SLFewxgfK6L22A3Ld3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DTHGhnjXtD6g4ufthiZTJIrL8O0VIhqI+MxYwEC3jgPfQ8AmetZJtKL5I8D7fzr
33
+ TF7DhYOoTXxCnkmJa5343IVMAP/SKLvjp7Q3GB/zTlc1Nbzdr5TtrF/6H1QNTC+E
34
+ HDPkLsIfkHSvrmOMGVrQjV8LvserduHd9B1M1GpOCr0dFeUa6XeljFLhD2QUjBhq
35
+ kL7xiX3RDqcAvy309ILHyfCi3dWb9G/CWOu7eLmnE1zcoff19nQdTEuVj8nMEhIp
36
+ Cs3/Ef1tya/6aFPDCTHdMU1ujt9t/Up7C1JyWLTzzoPktNtweb1a3xOVOs/vaVog
37
+ J5+m17iLpC8bZgQfz17lCcq7Ey37SYJlMIo=
37
38
  -----END CERTIFICATE-----
38
- date: 2022-02-22 00:00:00.000000000 Z
39
+ date: 2023-03-06 00:00:00.000000000 Z
39
40
  dependencies:
40
41
  - !ruby/object:Gem::Dependency
41
42
  name: simple-config
@@ -46,7 +47,7 @@ dependencies:
46
47
  version: '0.7'
47
48
  - - ">="
48
49
  - !ruby/object:Gem::Version
49
- version: 0.7.2
50
+ version: 0.7.3
50
51
  type: :runtime
51
52
  prerelease: false
52
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -56,7 +57,7 @@ dependencies:
56
57
  version: '0.7'
57
58
  - - ">="
58
59
  - !ruby/object:Gem::Version
59
- version: 0.7.2
60
+ version: 0.7.3
60
61
  description:
61
62
  email: digital.robertson@gmail.com
62
63
  executables: []
@@ -83,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  - !ruby/object:Gem::Version
84
85
  version: '0'
85
86
  requirements: []
86
- rubygems_version: 3.2.22
87
+ rubygems_version: 3.4.6
87
88
  signing_key:
88
89
  specification_version: 4
89
90
  summary: The XML registry can be used to store or retrieve app settings etc. in an
metadata.gz.sig CHANGED
Binary file