xml-registry 0.7.0 → 0.7.1

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: d392b12b72700de55f9435b4a8e39a7e94039ad9d24ab29a4fe2eace7c17657f
4
- data.tar.gz: 3a1a9fe380f0544d517fee1afdbd7b8efc270fc2a4a0c4aad664ec592bc37de3
3
+ metadata.gz: 667bdd8cb557aaca4ea00df166d7bf0f8542a0c6d2faedeabc14c26dba83d6a0
4
+ data.tar.gz: 8a1ecbca36cee8fe8bf5e31612265f4dc384642d4c53a4d042bf324114b1a8a7
5
5
  SHA512:
6
- metadata.gz: 2f090b28afd7a35b47171d4a3c036ff728a2b93e3822c41f3f6bdeaf7e9e5606f8957dc73148f4980c1d00a9b2004d4e13770b36797934d73f0e4c9038532c46
7
- data.tar.gz: a4ea5df6196a4be5954499cd5b913e1a66fa04280ed12cb30fb837eb545c6ccda2335e27f6c99d9ef0f652cc4745658e7948111ce8bf3f500022c3968ec3fcd8
6
+ metadata.gz: d3f73f6a72768069389584be2e733f2ad85494088bd4ad95ff98f6f86fd183e0f38152777971e1633fc3e59ec4e8e3fcbae9a76161039b8c48ff9be1d3c3f2c1
7
+ data.tar.gz: fb077f993036fe580363abeb6e00300e6fee9989ec18b928f95c2e5d390c39e5df1e6fc100fcbb527d8045fba896f7dd1b9130fe29d982ee1e419a06275dc6f0
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/xml-registry.rb CHANGED
@@ -8,13 +8,13 @@ require 'simple-config'
8
8
 
9
9
 
10
10
  module NumberCheck
11
-
11
+
12
12
  refine String do
13
-
13
+
14
14
  def is_number?
15
15
  self.to_i.to_s == self
16
16
  end
17
-
17
+
18
18
  end
19
19
  end
20
20
 
@@ -22,9 +22,9 @@ class XMLRegistry
22
22
  using NumberCheck
23
23
 
24
24
  attr_reader :doc
25
-
25
+
26
26
  def initialize(template = '<root></root>', debug: false)
27
-
27
+
28
28
  @debug = debug
29
29
  super()
30
30
  @template, _ = RXFHelper.read(template)
@@ -49,21 +49,21 @@ class XMLRegistry
49
49
  # if the 1st element doesn't exist create it
50
50
  e = path.split('/',2).first
51
51
  @doc.root.add_element Rexle::Element.new(e) unless @doc.root.element e
52
- create_path = find_path(path)
52
+ create_path = find_path(path)
53
53
 
54
54
  if not create_path.empty? then
55
55
  parent_path = (path.split('/') - create_path.reverse).join('/')
56
56
  key_builder(parent_path, create_path)
57
57
  end
58
-
59
- add_value(path, value)
58
+
59
+ add_value(path, value)
60
60
  end
61
61
 
62
62
  def []=(path, val)
63
63
  s = path.split('/').map {|x| x[0].is_number? ? x.prepend('x') : x}.join '/'
64
64
  self.set_key(s, val)
65
65
  end
66
-
66
+
67
67
  # get the key value by passing the path
68
68
  # example: get_key('app/gtd/funday').value #=> 'friday'
69
69
  #
@@ -73,13 +73,13 @@ class XMLRegistry
73
73
 
74
74
  key = @doc.root.element path
75
75
  raise ("xml-registry: key %s not found" % path) unless key
76
-
77
- key.instance_eval {
78
- @path = path
76
+
77
+ key.instance_eval {
78
+ @path = path
79
79
 
80
80
  def to_h(e)
81
81
 
82
- v = if e.has_elements? then
82
+ v = if e.has_elements? then
83
83
  e.elements.inject({}) do |r, x|
84
84
  r.merge to_h(x)
85
85
  end
@@ -88,24 +88,24 @@ class XMLRegistry
88
88
  end
89
89
 
90
90
  {e.name => v}
91
- end
92
-
93
- def to_config()
91
+ end
92
+
93
+ def to_config()
94
94
  SimpleConfig.new(to_h(self), attributes: {key: @path})
95
- end
96
-
97
- def to_kvx()
95
+ end
96
+
97
+ def to_kvx()
98
98
  Kvx.new(to_h(self), attributes: {key: @path})
99
- end
100
-
99
+ end
100
+
101
101
  def to_os()
102
102
  OpenStruct.new(to_h(self).first.last)
103
103
  end
104
104
  }
105
-
105
+
106
106
  key
107
107
  end
108
-
108
+
109
109
  # get several keys using a Rexle XPath
110
110
  # example: get_keys('//funday') #=> [<funday>tuesday</funday>,<funday>friday</funday>]
111
111
  #
@@ -113,7 +113,7 @@ class XMLRegistry
113
113
  #
114
114
  def get_keys(path)
115
115
  @doc.root.xpath(path)
116
- end
116
+ end
117
117
 
118
118
  def [](path)
119
119
  s = path.split('/').map {|x| x.is_number? ? x.prepend('x') : x}.join '/'
@@ -125,7 +125,7 @@ class XMLRegistry
125
125
  #
126
126
  #
127
127
  def delete_key(path)
128
- @doc.root.delete path
128
+ @doc.root.delete path
129
129
  end
130
130
 
131
131
  # return the registry as an XML document
@@ -136,15 +136,15 @@ class XMLRegistry
136
136
  end
137
137
 
138
138
  alias :display_xml :to_xml
139
-
139
+
140
140
  def xml(options={})
141
141
  @doc.root.xml options
142
- end
142
+ end
143
143
 
144
144
  # load a new registry xml document replacing the existing registry
145
145
  #
146
- def load_xml(s='')
147
- @doc = Rexle.new(RXFHelper.read(s)[0])
146
+ def load_xml(s='')
147
+ @doc = Rexle.new(RXFHelper.read(s)[0].force_encoding("UTF-8"))
148
148
  self
149
149
  end
150
150
 
@@ -168,40 +168,40 @@ class XMLRegistry
168
168
  #"pin-no"="4321"
169
169
  #REG
170
170
  #
171
- #reg = XMLRegistry.new
172
- #reg.import s
171
+ #reg = XMLRegistry.new
172
+ #reg.import s
173
173
  #
174
- def import(s)
175
-
174
+ def import(s)
175
+
176
176
  r = RXFHelper.read(s)
177
177
  reg_buffer = r.first
178
178
  raise "read file error" unless reg_buffer
179
179
 
180
180
  if reg_buffer.strip[/^\[/] then
181
181
 
182
- reg_items = reg_buffer.gsub(/\n/,'').split(/(?=\[.[^\]]+\])/).map do |x|
182
+ reg_items = reg_buffer.gsub(/\n/,'').split(/(?=\[.[^\]]+\])/).map do |x|
183
183
  [x[/^\[(.[^\]]+)\]/,1], Hash[*($').scan(/"([^"]+)"="(.[^"]*)"/).flatten]]
184
184
  end
185
-
186
- elsif reg_buffer.strip.lines.grep(/^\s+\w/).any?
185
+
186
+ elsif reg_buffer.strip.lines.grep(/^\s+\w/).any?
187
187
 
188
188
  puts 'hierachical import' if @debug
189
189
  doc = LineTree.new(reg_buffer).to_doc
190
-
190
+
191
191
  reg_items = []
192
-
192
+
193
193
  doc.root.each_recursive do |e|
194
-
194
+
195
195
  puts 'e: ' + e.inspect if @debug
196
196
  if e.is_a?(Rexle::Element) and e.children.length < 2 then
197
-
197
+
198
198
  reg_items << [e.backtrack.to_xpath.sub(/^root\//,'')\
199
199
  .sub(/\/[^\/]+$/,''), {e.name => e.text }]
200
-
200
+
201
201
  end
202
-
203
- end
204
-
202
+
203
+ end
204
+
205
205
  else
206
206
 
207
207
  reg_items = reg_buffer.split(/(?=^[^:]+$)/).map do |raw_section|
@@ -211,21 +211,21 @@ class XMLRegistry
211
211
  path = lines.shift.rstrip
212
212
  [path, Hash[lines.map{|x| x.split(':',2).map(&:strip)}]]
213
213
  end
214
-
214
+
215
215
  reg_items.compact!
216
-
216
+
217
217
  end
218
218
 
219
219
  puts 'reg_items: ' + reg_items.inspect if @debug
220
220
  reg_items.each do |path, items|
221
221
  items.each {|k,value| self.set_key("%s/%s" % [path,k], value)}
222
222
  end
223
-
223
+
224
224
  :import
225
225
  end
226
226
 
227
- # Export the registry to file if the filepath is specified. Regardless,
228
- # the registry will be returned as a string in the registry
227
+ # Export the registry to file if the filepath is specified. Regardless,
228
+ # the registry will be returned as a string in the registry
229
229
  # export format.
230
230
  #
231
231
  def export(s=nil)
@@ -267,21 +267,21 @@ class XMLRegistry
267
267
 
268
268
  def print_scan(node, parent=[])
269
269
  out = []
270
- parent << node.name
270
+ parent << node.name
271
271
  items = []
272
272
 
273
273
  node.elements.each do |e|
274
274
  if e.has_elements? then
275
- out << print_scan(e, parent.clone)
275
+ out << print_scan(e, parent.clone)
276
276
  else
277
277
  items << [e.name, e.text]
278
278
  end
279
- end
279
+ end
280
280
  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")]
281
+ out << "[%s]\n%s\n" % [parent[1..-1].join("/"),
282
+ items.map {|x| "\"%s\"=\"%s\"" % x}.join("\n")]
283
283
  end
284
- out
284
+ out
285
285
  end
286
286
 
287
287
  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.7.0
4
+ version: 0.7.1
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
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkxMjIzMjIxNDQwWhcN
15
- MjAxMjIyMjIxNDQwWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDMvIzK
17
- 0RTuEh7Eae7b6JjwT7P/Zi2V+e+yHSL6zfhqMvN6amx2ZBTCsL0fPY6vwS/ggwEJ
18
- mnHzgAFZplpsyNjBTMdxN9dxLgIL1M6u6SgCYH/Bhz5Wc5YwhDetW8i/OUaPgGfs
19
- njt3aEtYWCoeOTbDVc0k9O5fgDRRZFy6Aq6kxBmPrxScv8HUKcdGyfM1FhI/+6JD
20
- 17Q57lqjHRp1Lk55LhMRdX/qVATkfMqXJVtdICRFy74CQplFUax+V0lRTKVCtXXB
21
- z+8qwTLPKBXeakP++TGA1Xfj59RmbYWYJjOcAmKnwu9rpsoSYwRAb+q/YBebnjfa
22
- ToTPjMUCzHJOgOByTjbNPyN/C5gDIeCyVZORDksfolPCgCcjpsGWIJ0pMQbcg80z
23
- RYzR22BNnk6xSUn3xv26Y5NQCfovrog+b/041+/wGu2Hi3eZzu7cYFcOnTwQSDzi
24
- SrCJQj1YvKXNw9PGuCW0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3b2U0cAcVuw3vXAufZEezb0TGxNQUFio52UGCFfj371cxj4u7VNnB55q
35
+ qQ7EyBaXak1o/nkw5pybDKSbUjVOvQpzjla62Xe4FzHerw4+UYRKyq6OjeDckoJD
36
+ qwMwsoB0WJMRTqSZ4g1aEmfr
37
37
  -----END CERTIFICATE-----
38
- date: 2019-12-23 00:00:00.000000000 Z
38
+ date: 2022-02-16 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,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubygems_version: 3.0.3
86
+ rubygems_version: 3.2.22
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  summary: The XML registry can be used to store or retrieve app settings etc. in an
metadata.gz.sig CHANGED
Binary file