xml-registry 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/xml-registry.rb +21 -21
  2. metadata +2 -2
data/lib/xml-registry.rb CHANGED
@@ -2,26 +2,26 @@
2
2
 
3
3
  # file: xml-registry.rb
4
4
 
5
- require 'rexml/document'
6
- include REXML
5
+ require 'rexle'
7
6
 
8
7
  class XMLRegistry
9
8
 
10
9
  def initialize()
11
10
  super()
12
11
  @template = '<root><system/><app/><user/><ip_address/></root>'
13
- @doc = Document.new(@template)
12
+ @doc = Rexle.new(@template)
14
13
  end
15
14
 
16
15
  def initialise_registry()
17
- @doc = Document.new(@template)
16
+ @doc = Rexle.new(@template)
18
17
  end
19
18
 
20
19
  alias :reset_registry :initialise_registry
21
20
 
22
21
  def set_key(path, value)
22
+
23
23
  create_path = find_path(path)
24
-
24
+
25
25
  if not create_path.empty? then
26
26
  parent_path = (path.split('/') - create_path.reverse).join('/')
27
27
  key_builder(parent_path, create_path)
@@ -31,30 +31,29 @@ class XMLRegistry
31
31
  end
32
32
 
33
33
  def get_key(path)
34
- XPath.first(@doc.root, path)
34
+ @doc.root.element path
35
35
  end
36
36
 
37
37
  def get_keys(path)
38
- XPath.match(@doc.root, path)
38
+ @doc.root.xpath path
39
39
  end
40
40
 
41
41
  def delete_key(path)
42
- node = XPath.first(@doc.root, path)
43
- node.parent.delete node if node
42
+ @doc.root.delete path
44
43
  end
45
44
 
46
- def to_xml()
47
- @doc.to_s
45
+ def to_xml(options={})
46
+ @doc.xml options
48
47
  end
49
48
 
50
49
  alias :display_xml :to_xml
51
50
 
52
- def load_xml(s='')
53
- @doc = Document.new(read(s))
51
+ def load_xml(s='')
52
+ @doc = Rexle.new(read(s))
54
53
  end
55
54
 
56
55
  def save(s)
57
- File.open(s){|f| @doc.write f}
56
+ File.open(s){|f| f.write @doc.xml}
58
57
  end
59
58
 
60
59
  def import(s)
@@ -78,16 +77,18 @@ class XMLRegistry
78
77
  private
79
78
 
80
79
  def add_key(path='app', key='untitled')
81
- node = @doc.root.elements[path]
82
- node.add_element Element.new(key)
80
+ node = @doc.root.element path
81
+ r = node.add_element Rexle::Element.new(key)
82
+ r
83
83
  end
84
84
 
85
85
  def add_value(key, value)
86
- @doc.root.elements[key].text = value
86
+ @doc.root.element(key).text = value
87
87
  end
88
88
 
89
89
  def find_path(path, create_path=[])
90
- return create_path if @doc.root.elements[path]
90
+
91
+ return create_path if !@doc.root.xpath(path).empty?
91
92
  apath = path.split('/')
92
93
  create_path << apath.pop
93
94
  find_path(apath.join('/'), create_path)
@@ -113,6 +114,7 @@ class XMLRegistry
113
114
  out = []
114
115
  parent << node.name
115
116
  items = []
117
+
116
118
  node.elements.each do |e|
117
119
  if e.has_elements? then
118
120
  out << print_scan(e, parent.clone)
@@ -127,6 +129,4 @@ class XMLRegistry
127
129
  out
128
130
  end
129
131
 
130
- end
131
-
132
-
132
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: xml-registry
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.6
5
+ version: 0.1.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Robertson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-01-13 00:00:00 +00:00
13
+ date: 2012-01-14 00:00:00 +00:00
14
14
  default_executable:
15
15
  dependencies: []
16
16