xml-registry 0.6.0 → 0.8.0

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
  SHA256:
3
- metadata.gz: 1be5e09b2429e5cca7b0cec165269845ad9bda4fbf7384705f2b884d814381bd
4
- data.tar.gz: 04d20465fd4a50bb43a214767904014401ae7437d389a00fde627cbfa9ccd5dd
3
+ metadata.gz: 280ac5c817560aa72e83c93eabf4358d1a169781717442b7b4e2c7ee95ca1ec0
4
+ data.tar.gz: 0a8a32baea55901636b3a28ef6b585393883f4717107b17af84a46365a0c8658
5
5
  SHA512:
6
- metadata.gz: c2c0ed23c3128cbff4c697a6944813b7d5d65816929a8e05ba3874152445ebfc4def88394efbaa5dde494a3f1bdb225f5d3297247eb2c354b14e6bd835e04c42
7
- data.tar.gz: 26e18295443a69b2632138c749723173d7d8f0326190951217f33e3d20416e0b47840eb4f1c35e7f17a630e87b0e72c037bb1efd52359e4a06b197b879ff7345
6
+ metadata.gz: af319f07195089806be005eb10b42267e359a65c6f668ccda8ba618b3b36019c433abede751bf10e5d7dadfdb1c3719309538db765bb56c1e7933fc528f42a56
7
+ data.tar.gz: a5bddd352a8865dc253cda635dde28a6ba8b66c1ad094c9b2cf5368bb1e74b32164cc8c7e2e9240be7e4e9f25d047a5ffcf1d1ed395ba748dbdf2498a376aca2
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/xml-registry.rb CHANGED
@@ -2,32 +2,35 @@
2
2
 
3
3
  # file: xml-registry.rb
4
4
 
5
- #require 'rexle'
6
- #require 'rxfhelper'
5
+ require 'rexle'
6
+ require 'kvx'
7
+ require 'ostruct'
7
8
  require 'simple-config'
9
+ require 'rxfreadwrite'
8
10
 
9
11
 
10
12
  module NumberCheck
11
-
13
+
12
14
  refine String do
13
-
15
+
14
16
  def is_number?
15
17
  self.to_i.to_s == self
16
18
  end
17
-
19
+
18
20
  end
19
21
  end
20
22
 
21
23
  class XMLRegistry
22
24
  using NumberCheck
25
+ include RXFReadWriteModule
23
26
 
24
27
  attr_reader :doc
25
-
28
+
26
29
  def initialize(template = '<root></root>', debug: false)
27
-
30
+
28
31
  @debug = debug
29
32
  super()
30
- @template, _ = RXFHelper.read(template)
33
+ @template, _ = RXFReader.read(template)
31
34
  @doc = Rexle.new(@template)
32
35
  end
33
36
 
@@ -49,21 +52,21 @@ class XMLRegistry
49
52
  # if the 1st element doesn't exist create it
50
53
  e = path.split('/',2).first
51
54
  @doc.root.add_element Rexle::Element.new(e) unless @doc.root.element e
52
- create_path = find_path(path)
55
+ create_path = find_path(path)
53
56
 
54
57
  if not create_path.empty? then
55
58
  parent_path = (path.split('/') - create_path.reverse).join('/')
56
59
  key_builder(parent_path, create_path)
57
60
  end
58
-
59
- add_value(path, value)
61
+
62
+ add_value(path, value)
60
63
  end
61
64
 
62
65
  def []=(path, val)
63
66
  s = path.split('/').map {|x| x[0].is_number? ? x.prepend('x') : x}.join '/'
64
67
  self.set_key(s, val)
65
68
  end
66
-
69
+
67
70
  # get the key value by passing the path
68
71
  # example: get_key('app/gtd/funday').value #=> 'friday'
69
72
  #
@@ -73,13 +76,13 @@ class XMLRegistry
73
76
 
74
77
  key = @doc.root.element path
75
78
  raise ("xml-registry: key %s not found" % path) unless key
76
-
77
- key.instance_eval {
78
- @path = path
79
+
80
+ key.instance_eval {
81
+ @path = path
79
82
 
80
83
  def to_h(e)
81
84
 
82
- v = if e.has_elements? then
85
+ v = if e.has_elements? then
83
86
  e.elements.inject({}) do |r, x|
84
87
  r.merge to_h(x)
85
88
  end
@@ -88,24 +91,24 @@ class XMLRegistry
88
91
  end
89
92
 
90
93
  {e.name => v}
91
- end
92
-
93
- def to_config()
94
+ end
95
+
96
+ def to_config()
94
97
  SimpleConfig.new(to_h(self), attributes: {key: @path})
95
- end
96
-
97
- def to_kvx()
98
+ end
99
+
100
+ def to_kvx()
98
101
  Kvx.new(to_h(self), attributes: {key: @path})
99
- end
100
-
102
+ end
103
+
101
104
  def to_os()
102
105
  OpenStruct.new(to_h(self).first.last)
103
106
  end
104
107
  }
105
-
108
+
106
109
  key
107
110
  end
108
-
111
+
109
112
  # get several keys using a Rexle XPath
110
113
  # example: get_keys('//funday') #=> [<funday>tuesday</funday>,<funday>friday</funday>]
111
114
  #
@@ -113,7 +116,7 @@ class XMLRegistry
113
116
  #
114
117
  def get_keys(path)
115
118
  @doc.root.xpath(path)
116
- end
119
+ end
117
120
 
118
121
  def [](path)
119
122
  s = path.split('/').map {|x| x.is_number? ? x.prepend('x') : x}.join '/'
@@ -125,7 +128,7 @@ class XMLRegistry
125
128
  #
126
129
  #
127
130
  def delete_key(path)
128
- @doc.root.delete path
131
+ @doc.root.delete path
129
132
  end
130
133
 
131
134
  # return the registry as an XML document
@@ -136,22 +139,22 @@ class XMLRegistry
136
139
  end
137
140
 
138
141
  alias :display_xml :to_xml
139
-
142
+
140
143
  def xml(options={})
141
144
  @doc.root.xml options
142
- end
145
+ end
143
146
 
144
147
  # load a new registry xml document replacing the existing registry
145
148
  #
146
- def load_xml(s='')
147
- @doc = Rexle.new(RXFHelper.read(s)[0])
149
+ def load_xml(s='')
150
+ @doc = Rexle.new(RXFReader.read(s)[0].force_encoding("UTF-8"))
148
151
  self
149
152
  end
150
153
 
151
154
  # save the registry to the specified file path
152
155
  #
153
156
  def save(s)
154
- RXFHelper.write s, @doc.xml(pretty: true)
157
+ FileX.write s, @doc.xml(pretty: true)
155
158
  end
156
159
 
157
160
  # import a registry hive from a string in registry format
@@ -168,70 +171,70 @@ class XMLRegistry
168
171
  #"pin-no"="4321"
169
172
  #REG
170
173
  #
171
- #reg = XMLRegistry.new
172
- #reg.import s
174
+ #reg = XMLRegistry.new
175
+ #reg.import s
173
176
  #
174
- def import(s)
175
-
176
- r = RXFHelper.read(s)
177
+ def import(s)
178
+
179
+ r = RXFReader.read(s)
177
180
  reg_buffer = r.first
178
181
  raise "read file error" unless reg_buffer
179
182
 
180
183
  if reg_buffer.strip[/^\[/] then
181
184
 
182
- reg_items = reg_buffer.gsub(/\n/,'').split(/(?=\[.[^\]]+\])/).map do |x|
185
+ reg_items = reg_buffer.gsub(/\n/,'').split(/(?=\[.[^\]]+\])/).map do |x|
183
186
  [x[/^\[(.[^\]]+)\]/,1], Hash[*($').scan(/"([^"]+)"="(.[^"]*)"/).flatten]]
184
187
  end
185
-
186
- elsif reg_buffer.strip.lines.grep(/^\s+\w/).any?
188
+
189
+ elsif reg_buffer.strip.lines.grep(/^\s+\w/).any?
187
190
 
188
191
  puts 'hierachical import' if @debug
189
192
  doc = LineTree.new(reg_buffer).to_doc
190
-
193
+
191
194
  reg_items = []
192
-
195
+
193
196
  doc.root.each_recursive do |e|
194
-
197
+
195
198
  puts 'e: ' + e.inspect if @debug
196
199
  if e.is_a?(Rexle::Element) and e.children.length < 2 then
197
-
200
+
198
201
  reg_items << [e.backtrack.to_xpath.sub(/^root\//,'')\
199
202
  .sub(/\/[^\/]+$/,''), {e.name => e.text }]
200
-
203
+
201
204
  end
202
-
203
- end
204
-
205
+
206
+ end
207
+
205
208
  else
206
209
 
207
210
  reg_items = reg_buffer.split(/(?=^[^:]+$)/).map do |raw_section|
208
211
 
209
212
  lines = raw_section.lines.to_a
210
213
  next if lines.first.strip.empty?
211
- path = lines.shift.chomp
214
+ path = lines.shift.rstrip
212
215
  [path, Hash[lines.map{|x| x.split(':',2).map(&:strip)}]]
213
216
  end
214
-
217
+
215
218
  reg_items.compact!
216
-
219
+
217
220
  end
218
221
 
219
222
  puts 'reg_items: ' + reg_items.inspect if @debug
220
223
  reg_items.each do |path, items|
221
224
  items.each {|k,value| self.set_key("%s/%s" % [path,k], value)}
222
225
  end
223
-
226
+
224
227
  :import
225
228
  end
226
229
 
227
- # Export the registry to file if the filepath is specified. Regardless,
228
- # the registry will be returned as a string in the registry
230
+ # Export the registry to file if the filepath is specified. Regardless,
231
+ # the registry will be returned as a string in the registry
229
232
  # export format.
230
233
  #
231
234
  def export(s=nil)
232
235
  reg = print_scan(@doc.root).join("\n")
233
236
  # jr 250118 File.open(s){|f| f.write reg} if s
234
- RXFHelper.write(s, reg) if s
237
+ FileX.write(s, reg) if s
235
238
  reg
236
239
  end
237
240
 
@@ -267,21 +270,21 @@ class XMLRegistry
267
270
 
268
271
  def print_scan(node, parent=[])
269
272
  out = []
270
- parent << node.name
273
+ parent << node.name
271
274
  items = []
272
275
 
273
276
  node.elements.each do |e|
274
277
  if e.has_elements? then
275
- out << print_scan(e, parent.clone)
278
+ out << print_scan(e, parent.clone)
276
279
  else
277
280
  items << [e.name, e.text]
278
281
  end
279
- end
282
+ end
280
283
  if parent.length > 1 and items.length > 0 then
281
- out << "[%s]\n%s\n" % [parent[1..-1].join("/"),
282
- items.map {|x| "\"%s\"=\"%s\"" % x}.join("\n")]
284
+ out << "[%s]\n%s\n" % [parent[1..-1].join("/"),
285
+ items.map {|x| "\"%s\"=\"%s\"" % x}.join("\n")]
283
286
  end
284
- out
287
+ out
285
288
  end
286
289
 
287
290
  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.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -11,31 +11,31 @@ cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTgxMDAzMjEzNzM2WhcN
15
- MTkxMDAzMjEzNzM2WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDuKHYE
17
- VDoo5C3fYSy3TALaW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ub6rFUeCGfpi/Verm9WPRqH
36
- oY185KtHIZDihehN4jjAxIqU
28
+ BgkqhkiG9w0BAQsFAAOCAYEAlxjvjTEJuVVf7sNEtVkj2iPnmMYboSAdwt6vzQdR
29
+ kdwTQwbS83bzwtgMva+34LZYD1Rukfo8TlKi8jspSd6vMnU1KNicsiMphKgjPFZ/
30
+ IQOF/zOcQevEmPeis9/I8q8krX4515jaQAy/B1umRAAaBZ5HaG6RP//RfgFXiP7N
31
+ O+o7cMXuG5mtSBZiDsWFJbnm/jxYxsu2/KP0nptKacfGYuJ1AhbzbXcIuBDQPPds
32
+ iLOmzi+BcvbB5CS3COOQ3/ZfxXlpeq+SXZMd0tMuSXAi+iMQxR+L/siByoDXKzPw
33
+ 7ipnNUzjevQz/sMYRKQIGsIn6AkJc34WtKQMxFKXvgeHlfkEinrviwxHm4dSh3Hi
34
+ ye5NuslP3b2U0cAcVuw3vXAufZEezb0TGxNQUFio52UGCFfj371cxj4u7VNnB55q
35
+ qQ7EyBaXak1o/nkw5pybDKSbUjVOvQpzjla62Xe4FzHerw4+UYRKyq6OjeDckoJD
36
+ qwMwsoB0WJMRTqSZ4g1aEmfr
37
37
  -----END CERTIFICATE-----
38
- date: 2018-10-03 00:00:00.000000000 Z
38
+ date: 2022-02-22 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: simple-config
@@ -43,22 +43,22 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0.6'
46
+ version: '0.7'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 0.6.4
49
+ version: 0.7.2
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '0.6'
56
+ version: '0.7'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 0.6.4
59
+ version: 0.7.2
60
60
  description:
61
- email: james@jamesrobertson.eu
61
+ email: digital.robertson@gmail.com
62
62
  executables: []
63
63
  extensions: []
64
64
  extra_rdoc_files: []
@@ -83,8 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubyforge_project:
87
- rubygems_version: 2.7.6
86
+ rubygems_version: 3.2.22
88
87
  signing_key:
89
88
  specification_version: 4
90
89
  summary: The XML registry can be used to store or retrieve app settings etc. in an
metadata.gz.sig CHANGED
Binary file