xml-registry 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/lib/xml-registry.rb +60 -8
- data.tar.gz.sig +0 -0
- metadata +21 -32
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0dea5c94aaf1371d724090586238786aed77de6a
|
4
|
+
data.tar.gz: 7889299df94f76b8ec6aaf4aebc9546ad3ca4ea0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e5c3ce602558bef9a569c9b5217a54ad2c7ec61fcd09cf0ab942fc2b229427aaa16b7928f4c79ed44f2f1d4c2c1101095841cd317d561cc215cc98be14157b6a
|
7
|
+
data.tar.gz: 0907bf7ae071b8960e868a194343cd2bb2a58069a58d40aaa4e0d662f259c7a92f5cbf1f2e2d9a0b89a0cc24585e0d54766622fd71d5c163f7209f802915292a
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/lib/xml-registry.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# file: xml-registry.rb
|
4
4
|
|
@@ -8,20 +8,30 @@ class XMLRegistry
|
|
8
8
|
|
9
9
|
attr_reader :doc
|
10
10
|
|
11
|
-
def initialize()
|
11
|
+
def initialize(template = '<root></root>')
|
12
12
|
super()
|
13
|
-
@template =
|
13
|
+
@template = template
|
14
14
|
@doc = Rexle.new(@template)
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
# Creates a new registry document from scratch. Optional param: string XML template
|
18
|
+
# example: initialise_registry('<root><app/></root>')
|
19
|
+
#
|
20
|
+
def initialise_registry(new_template=nil)
|
21
|
+
@doc = Rexle.new(new_template || @template)
|
19
22
|
end
|
20
23
|
|
21
24
|
alias :reset_registry :initialise_registry
|
25
|
+
alias :initialize_registry :initialise_registry
|
22
26
|
|
27
|
+
# Set the key by passing in the path and the value
|
28
|
+
# example: set_key 'app/gtd/funday', 'friday'
|
29
|
+
#
|
23
30
|
def set_key(path, value)
|
24
|
-
|
31
|
+
|
32
|
+
# if the 1st element doesn't exist create it
|
33
|
+
e = path.split('/',2).first
|
34
|
+
@doc.root.add_element Rexle::Element.new(e) unless @doc.root.element e
|
25
35
|
create_path = find_path(path)
|
26
36
|
|
27
37
|
if not create_path.empty? then
|
@@ -31,34 +41,72 @@ class XMLRegistry
|
|
31
41
|
|
32
42
|
add_value(path, value)
|
33
43
|
end
|
34
|
-
|
44
|
+
|
45
|
+
# get the key value by passing the path
|
46
|
+
# example: get_key('app/gtd/funday').value #=> 'friday'
|
47
|
+
#
|
48
|
+
# returns the value as a Rexle::Element
|
49
|
+
#
|
35
50
|
def get_key(path)
|
36
51
|
@doc.root.element path
|
37
52
|
end
|
38
53
|
|
54
|
+
# get several keys using a Rexle XPath
|
55
|
+
# example: get_key('//funday') #=> [<funday>tuesday</funday>,<funday>friday</funday>]
|
56
|
+
#
|
57
|
+
# returns an array of 0 or more Rexle elements
|
58
|
+
#
|
39
59
|
def get_keys(path)
|
40
60
|
@doc.root.xpath path
|
41
61
|
end
|
42
62
|
|
63
|
+
# delete the key at the specified path
|
64
|
+
# example: delete_key 'app/gtd/funday'
|
65
|
+
#
|
66
|
+
#
|
43
67
|
def delete_key(path)
|
44
68
|
@doc.root.delete path
|
45
69
|
end
|
46
70
|
|
71
|
+
# return the registry as an XML document
|
72
|
+
# example: puts reg.to_xml pretty: true
|
73
|
+
#
|
47
74
|
def to_xml(options={})
|
48
75
|
@doc.xml options
|
49
76
|
end
|
50
77
|
|
51
78
|
alias :display_xml :to_xml
|
52
79
|
|
80
|
+
# load a new registry xml document replacing the existing registry
|
81
|
+
#
|
53
82
|
def load_xml(s='')
|
54
83
|
@doc = Rexle.new(read(s))
|
55
84
|
self
|
56
85
|
end
|
57
86
|
|
87
|
+
# save the registry to the specified file path
|
88
|
+
#
|
58
89
|
def save(s)
|
59
90
|
File.open(s, 'w'){|f| f.write @doc.xml}
|
60
91
|
end
|
61
92
|
|
93
|
+
# import a registry hive from a string in registry format
|
94
|
+
#
|
95
|
+
# example:
|
96
|
+
#
|
97
|
+
#s =<<REG
|
98
|
+
#[app/app1]
|
99
|
+
#"admin"="jrobertson"
|
100
|
+
#"pin-no"="1234"
|
101
|
+
#
|
102
|
+
#[app/app2]
|
103
|
+
#"admin"="dsmith"
|
104
|
+
#"pin-no"="4321"
|
105
|
+
#REG
|
106
|
+
#
|
107
|
+
#reg = XMLRegistry.new
|
108
|
+
#reg.import s
|
109
|
+
#
|
62
110
|
def import(s)
|
63
111
|
reg_buffer = read(s)
|
64
112
|
|
@@ -71,6 +119,10 @@ class XMLRegistry
|
|
71
119
|
end
|
72
120
|
end
|
73
121
|
|
122
|
+
# Export the registry to file if the filepath is specified. Regardless,
|
123
|
+
# the registry will be returned as a string in the registry
|
124
|
+
# export format.
|
125
|
+
#
|
74
126
|
def export(s=nil)
|
75
127
|
reg = print_scan(@doc.root).join("\n")
|
76
128
|
File.open(s){|f| f.write reg} if s
|
@@ -132,4 +184,4 @@ class XMLRegistry
|
|
132
184
|
out
|
133
185
|
end
|
134
186
|
|
135
|
-
end
|
187
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml-registry
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.1.11
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.12
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- James Robertson
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
|
-
cert_chain:
|
10
|
+
cert_chain:
|
12
11
|
- |
|
13
12
|
-----BEGIN CERTIFICATE-----
|
14
13
|
MIIDRDCCAiygAwIBAgIBADANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
|
@@ -30,46 +29,36 @@ cert_chain:
|
|
30
29
|
m8++OvC3wZJ60rgKYqxfVYDFYuaMttCZlmtJeF5LerbwGPPIjGwvIeYDLqBJRuA6
|
31
30
|
4KclOqKpfBFvuefX+F9YSO3aO94nnzhV
|
32
31
|
-----END CERTIFICATE-----
|
33
|
-
|
34
|
-
date: 2013-02-06 00:00:00 Z
|
32
|
+
date: 2013-04-08 00:00:00.000000000 Z
|
35
33
|
dependencies: []
|
36
|
-
|
37
34
|
description:
|
38
35
|
email:
|
39
36
|
executables: []
|
40
|
-
|
41
37
|
extensions: []
|
42
|
-
|
43
38
|
extra_rdoc_files: []
|
44
|
-
|
45
|
-
files:
|
39
|
+
files:
|
46
40
|
- lib/xml-registry.rb
|
47
41
|
homepage:
|
48
42
|
licenses: []
|
49
|
-
|
43
|
+
metadata: {}
|
50
44
|
post_install_message:
|
51
45
|
rdoc_options: []
|
52
|
-
|
53
|
-
require_paths:
|
46
|
+
require_paths:
|
54
47
|
- lib
|
55
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: "0"
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
67
58
|
requirements: []
|
68
|
-
|
69
59
|
rubyforge_project:
|
70
|
-
rubygems_version:
|
60
|
+
rubygems_version: 2.0.0.rc.2
|
71
61
|
signing_key:
|
72
|
-
specification_version:
|
62
|
+
specification_version: 4
|
73
63
|
summary: xml-registry
|
74
64
|
test_files: []
|
75
|
-
|
metadata.gz.sig
CHANGED
Binary file
|