xml-registry 0.5.4 → 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
- SHA1:
3
- metadata.gz: d705f4545f13c91ba2535d865a6033d1103f1553
4
- data.tar.gz: 0a8f33f246dcbbec12fd989040117b02ca5a7413
2
+ SHA256:
3
+ metadata.gz: 667bdd8cb557aaca4ea00df166d7bf0f8542a0c6d2faedeabc14c26dba83d6a0
4
+ data.tar.gz: 8a1ecbca36cee8fe8bf5e31612265f4dc384642d4c53a4d042bf324114b1a8a7
5
5
  SHA512:
6
- metadata.gz: ec0d1ad56ef73bcbbb18756c051d35a8001a5290a5c10903d8ea92008a017c911360c72ff238548206230b0455dad608814ea0e07eb41facc804fc1032f7780f
7
- data.tar.gz: f271c662d511027fd153128a9ba6073cd08e7bc5fd2f8bf44e62a699f020f10caafd7d8c7ef7fc880899ef72ca4b9b76cde92d8b2b7bbf52381d3de0ba30371e
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,8 +22,10 @@ class XMLRegistry
22
22
  using NumberCheck
23
23
 
24
24
  attr_reader :doc
25
-
26
- def initialize(template = '<root></root>')
25
+
26
+ def initialize(template = '<root></root>', debug: false)
27
+
28
+ @debug = debug
27
29
  super()
28
30
  @template, _ = RXFHelper.read(template)
29
31
  @doc = Rexle.new(@template)
@@ -47,21 +49,21 @@ class XMLRegistry
47
49
  # if the 1st element doesn't exist create it
48
50
  e = path.split('/',2).first
49
51
  @doc.root.add_element Rexle::Element.new(e) unless @doc.root.element e
50
- create_path = find_path(path)
52
+ create_path = find_path(path)
51
53
 
52
54
  if not create_path.empty? then
53
55
  parent_path = (path.split('/') - create_path.reverse).join('/')
54
56
  key_builder(parent_path, create_path)
55
57
  end
56
-
57
- add_value(path, value)
58
+
59
+ add_value(path, value)
58
60
  end
59
61
 
60
62
  def []=(path, val)
61
63
  s = path.split('/').map {|x| x[0].is_number? ? x.prepend('x') : x}.join '/'
62
64
  self.set_key(s, val)
63
65
  end
64
-
66
+
65
67
  # get the key value by passing the path
66
68
  # example: get_key('app/gtd/funday').value #=> 'friday'
67
69
  #
@@ -71,13 +73,13 @@ class XMLRegistry
71
73
 
72
74
  key = @doc.root.element path
73
75
  raise ("xml-registry: key %s not found" % path) unless key
74
-
75
- key.instance_eval {
76
- @path = path
76
+
77
+ key.instance_eval {
78
+ @path = path
77
79
 
78
80
  def to_h(e)
79
81
 
80
- v = if e.has_elements? then
82
+ v = if e.has_elements? then
81
83
  e.elements.inject({}) do |r, x|
82
84
  r.merge to_h(x)
83
85
  end
@@ -86,24 +88,24 @@ class XMLRegistry
86
88
  end
87
89
 
88
90
  {e.name => v}
89
- end
90
-
91
- def to_config()
91
+ end
92
+
93
+ def to_config()
92
94
  SimpleConfig.new(to_h(self), attributes: {key: @path})
93
- end
94
-
95
- def to_kvx()
95
+ end
96
+
97
+ def to_kvx()
96
98
  Kvx.new(to_h(self), attributes: {key: @path})
97
- end
98
-
99
+ end
100
+
99
101
  def to_os()
100
102
  OpenStruct.new(to_h(self).first.last)
101
103
  end
102
104
  }
103
-
105
+
104
106
  key
105
107
  end
106
-
108
+
107
109
  # get several keys using a Rexle XPath
108
110
  # example: get_keys('//funday') #=> [<funday>tuesday</funday>,<funday>friday</funday>]
109
111
  #
@@ -111,7 +113,7 @@ class XMLRegistry
111
113
  #
112
114
  def get_keys(path)
113
115
  @doc.root.xpath(path)
114
- end
116
+ end
115
117
 
116
118
  def [](path)
117
119
  s = path.split('/').map {|x| x.is_number? ? x.prepend('x') : x}.join '/'
@@ -123,7 +125,7 @@ class XMLRegistry
123
125
  #
124
126
  #
125
127
  def delete_key(path)
126
- @doc.root.delete path
128
+ @doc.root.delete path
127
129
  end
128
130
 
129
131
  # return the registry as an XML document
@@ -134,22 +136,22 @@ class XMLRegistry
134
136
  end
135
137
 
136
138
  alias :display_xml :to_xml
137
-
139
+
138
140
  def xml(options={})
139
141
  @doc.root.xml options
140
- end
142
+ end
141
143
 
142
144
  # load a new registry xml document replacing the existing registry
143
145
  #
144
- def load_xml(s='')
145
- @doc = Rexle.new(RXFHelper.read(s)[0])
146
+ def load_xml(s='')
147
+ @doc = Rexle.new(RXFHelper.read(s)[0].force_encoding("UTF-8"))
146
148
  self
147
149
  end
148
150
 
149
151
  # save the registry to the specified file path
150
152
  #
151
153
  def save(s)
152
- File.open(s, 'w'){|f| f.write @doc.xml pretty: true}
154
+ RXFHelper.write s, @doc.xml(pretty: true)
153
155
  end
154
156
 
155
157
  # import a registry hive from a string in registry format
@@ -166,49 +168,70 @@ class XMLRegistry
166
168
  #"pin-no"="4321"
167
169
  #REG
168
170
  #
169
- #reg = XMLRegistry.new
170
- #reg.import s
171
+ #reg = XMLRegistry.new
172
+ #reg.import s
171
173
  #
172
- def import(s)
173
-
174
+ def import(s)
175
+
174
176
  r = RXFHelper.read(s)
175
177
  reg_buffer = r.first
176
178
  raise "read file error" unless reg_buffer
177
179
 
178
180
  if reg_buffer.strip[/^\[/] then
179
181
 
180
- reg_items = reg_buffer.gsub(/\n/,'').split(/(?=\[.[^\]]+\])/).map do |x|
182
+ reg_items = reg_buffer.gsub(/\n/,'').split(/(?=\[.[^\]]+\])/).map do |x|
181
183
  [x[/^\[(.[^\]]+)\]/,1], Hash[*($').scan(/"([^"]+)"="(.[^"]*)"/).flatten]]
182
184
  end
183
-
185
+
186
+ elsif reg_buffer.strip.lines.grep(/^\s+\w/).any?
187
+
188
+ puts 'hierachical import' if @debug
189
+ doc = LineTree.new(reg_buffer).to_doc
190
+
191
+ reg_items = []
192
+
193
+ doc.root.each_recursive do |e|
194
+
195
+ puts 'e: ' + e.inspect if @debug
196
+ if e.is_a?(Rexle::Element) and e.children.length < 2 then
197
+
198
+ reg_items << [e.backtrack.to_xpath.sub(/^root\//,'')\
199
+ .sub(/\/[^\/]+$/,''), {e.name => e.text }]
200
+
201
+ end
202
+
203
+ end
204
+
184
205
  else
185
206
 
186
207
  reg_items = reg_buffer.split(/(?=^[^:]+$)/).map do |raw_section|
187
208
 
188
209
  lines = raw_section.lines.to_a
189
210
  next if lines.first.strip.empty?
190
- path = lines.shift.chomp
211
+ path = lines.shift.rstrip
191
212
  [path, Hash[lines.map{|x| x.split(':',2).map(&:strip)}]]
192
213
  end
193
-
214
+
194
215
  reg_items.compact!
195
-
216
+
196
217
  end
197
218
 
219
+ puts 'reg_items: ' + reg_items.inspect if @debug
198
220
  reg_items.each do |path, items|
199
221
  items.each {|k,value| self.set_key("%s/%s" % [path,k], value)}
200
222
  end
201
-
223
+
202
224
  :import
203
225
  end
204
226
 
205
- # Export the registry to file if the filepath is specified. Regardless,
206
- # 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
207
229
  # export format.
208
230
  #
209
231
  def export(s=nil)
210
232
  reg = print_scan(@doc.root).join("\n")
211
- File.open(s){|f| f.write reg} if s
233
+ # jr 250118 File.open(s){|f| f.write reg} if s
234
+ RXFHelper.write(s, reg) if s
212
235
  reg
213
236
  end
214
237
 
@@ -244,21 +267,21 @@ class XMLRegistry
244
267
 
245
268
  def print_scan(node, parent=[])
246
269
  out = []
247
- parent << node.name
270
+ parent << node.name
248
271
  items = []
249
272
 
250
273
  node.elements.each do |e|
251
274
  if e.has_elements? then
252
- out << print_scan(e, parent.clone)
275
+ out << print_scan(e, parent.clone)
253
276
  else
254
277
  items << [e.name, e.text]
255
278
  end
256
- end
279
+ end
257
280
  if parent.length > 1 and items.length > 0 then
258
- out << "[%s]\n%s\n" % [parent[1..-1].join("/"),
259
- 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")]
260
283
  end
261
- out
284
+ out
262
285
  end
263
286
 
264
- end
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.5.4
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,28 +10,32 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
- YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTE3MDgzMDE5MDg0MVoXDTE4MDgzMDE5MDg0MVowSDESMBAG
16
- A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
- EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
- ggEBANwS6eox+xJTn89aNj2b9mOImV8L+/29tIKnp3W4CwADagq+RijUXnpFUVjH
19
- LGS9q5BLEEw6Es8HKlcVzVUcr2CUjwmf9MmV2jpxQzrb8joMLgc0pyfcjodmDRca
20
- Dk3kwfYzvVK564Etm2in9DDxDY20GlpUtnIQhD5w7YDsgpG13d25W2bDsAcTKQYx
21
- DObG2/BTp/2Chs32D3uneyAlt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YRKQIGsIn6AkJc34WtKQMxFKXvgeHlfkEinrviwxHm4dSh3Hi
34
+ ye5NuslP3b2U0cAcVuw3vXAufZEezb0TGxNQUFio52UGCFfj371cxj4u7VNnB55q
35
+ qQ7EyBaXak1o/nkw5pybDKSbUjVOvQpzjla62Xe4FzHerw4+UYRKyq6OjeDckoJD
36
+ qwMwsoB0WJMRTqSZ4g1aEmfr
33
37
  -----END CERTIFICATE-----
34
- date: 2017-08-30 00:00:00.000000000 Z
38
+ date: 2022-02-16 00:00:00.000000000 Z
35
39
  dependencies:
36
40
  - !ruby/object:Gem::Dependency
37
41
  name: simple-config
@@ -39,22 +43,22 @@ dependencies:
39
43
  requirements:
40
44
  - - "~>"
41
45
  - !ruby/object:Gem::Version
42
- version: '0.6'
46
+ version: '0.7'
43
47
  - - ">="
44
48
  - !ruby/object:Gem::Version
45
- version: 0.6.1
49
+ version: 0.7.2
46
50
  type: :runtime
47
51
  prerelease: false
48
52
  version_requirements: !ruby/object:Gem::Requirement
49
53
  requirements:
50
54
  - - "~>"
51
55
  - !ruby/object:Gem::Version
52
- version: '0.6'
56
+ version: '0.7'
53
57
  - - ">="
54
58
  - !ruby/object:Gem::Version
55
- version: 0.6.1
59
+ version: 0.7.2
56
60
  description:
57
- email: james@jamesrobertson.eu
61
+ email: digital.robertson@gmail.com
58
62
  executables: []
59
63
  extensions: []
60
64
  extra_rdoc_files: []
@@ -79,9 +83,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
83
  - !ruby/object:Gem::Version
80
84
  version: '0'
81
85
  requirements: []
82
- rubyforge_project:
83
- rubygems_version: 2.6.8
86
+ rubygems_version: 3.2.22
84
87
  signing_key:
85
88
  specification_version: 4
86
- summary: xml-registry
89
+ summary: The XML registry can be used to store or retrieve app settings etc. in an
90
+ XML document.
87
91
  test_files: []
metadata.gz.sig CHANGED
@@ -1,2 +1 @@
1
- %* N��5��RUEY���\���[�U�M�b9��}��C��X��\ȷ巂�D�K��֝'#i�����>���=��Rܨ��}�sM���0A_P��K�?�FJ�6��*���pw_ ��a��R�����?�ʌ4� ���
2
- ������%�n:7�R���|�_�1Q�tm��B͜��\İ�%5�}_'ʮ�k��@�� �Y&9LP?�3���q� F%��p�GV�����ծ-�޵�$w��]�5f7�k}�����
1
+ 8���