dws-registry 0.1.3 → 0.2.0

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
  SHA1:
3
- metadata.gz: 09ef630303c9d819859516f505f1bbe56e64b7d4
4
- data.tar.gz: 074b399bfcbf9fcbfa1134c9d3572c9066addea0
3
+ metadata.gz: 4b4169a56e3e56b6fd66f9b81566834ef41a816d
4
+ data.tar.gz: d09171ac4c5d3146860c395aac9e1fbf691c72e0
5
5
  SHA512:
6
- metadata.gz: 7b562a43a4dc5cbd14a7e7cb67c2e6f97ecdcc3f3080b1b50ac32987a66878aee76cd22a69d20727facb2b17516ad7696792543814eeb01bc491a509e56a38d3
7
- data.tar.gz: e9b564bee4df3584ded7ee947f3d7ecf32623fcb7c3904b7d07972bfff6d754fe1dca88d9977c379592bbccda53c0a15df42a196fd23bf5fd6bd53c61f0ea942
6
+ metadata.gz: 380191f0c98a023a6d8eab0ad7f71ba1e271ea9172c0afb9c3a415b73cacd8b6c5b055b1ddfd616857ddcf53d2518e6ae851071d7051f926c1d7cdb4a2441484
7
+ data.tar.gz: 6d46159964b2fe6f8495e0cc4cb11e49a2a9ebff12298aada0de8bd79b9e50902c9f013df832757bb003d96724461ac12a9ea277ac8d078fcb655ce02ffd3eba
checksums.yaml.gz.sig CHANGED
@@ -1 +1,2 @@
1
- ^�x1��gz��(;��Ӝ}WR�׎�&^�1B|439��8����dZ�4rғ:�`;��g��c����z�n�*�\\�c�/���QAZ/W�����s�!g]�{��"z�ml�o
1
+ !Z o#T���D� m/����0ZI=
2
+ �9����7��m�����qs)��H����]�7�n��J��G�W(d���:>�������F��o16m��wLF�/�����'��mz��0q|�W���0������;˙ʨ!��G�ZY��./I��*.�J���1�DΒ�^oՒ])j�e��y9�v��o��헡�*Ĥs��`t;���QO��SI��
data.tar.gz.sig CHANGED
Binary file
data/lib/dws-registry.rb CHANGED
@@ -2,15 +2,17 @@
2
2
 
3
3
  # file: dws-registry.rb
4
4
 
5
-
5
+ require 'time'
6
6
  require 'xml-registry'
7
7
 
8
8
  class DWSRegistry < XMLRegistry
9
9
 
10
- def initialize(filename=nil)
10
+ def initialize(filename='registry.xml', autosave: true)
11
11
 
12
12
  super()
13
13
 
14
+ @autosave = autosave
15
+
14
16
  if filename then
15
17
 
16
18
  @filename = filename
@@ -23,15 +25,56 @@ class DWSRegistry < XMLRegistry
23
25
 
24
26
  end
25
27
  end
28
+
29
+ def get_key(path)
30
+
31
+ e = super path
32
+ c = e.attributes[:class]
33
+ s = e.text
34
+
35
+ return e if s.nil?
36
+ return s unless c
37
+
38
+ h = {
39
+ string: ->(x) {x},
40
+ boolean: ->(x){
41
+ case x
42
+ when 'true' then true
43
+ when 'false' then false
44
+ else x
45
+ end
46
+ },
47
+ number: ->(x){ x[/^[0-9]+$/] ? x.to_i : x.to_f },
48
+ time: ->(x) {Time.parse x}
49
+ }
50
+
51
+ h[c.to_sym].call s
52
+
53
+ end
26
54
 
27
55
  def set_key(path, value)
28
- super(path, value)
29
- save()
56
+
57
+ value, type = case value.class.to_s.downcase.to_sym
58
+ when :string then value
59
+ when :time then ["#%s#" % value.to_s, :time]
60
+ when :fixnum then [value.to_s, :number]
61
+ when :float then [value.to_s, :number]
62
+ when :falseclass then [value.to_s, :boolean]
63
+ when :trueclass then [value.to_s, :boolean]
64
+ end
65
+
66
+ e = super(path, value)
67
+
68
+ type = find_class value unless type
69
+ e.attributes[:class] = type if type
70
+
71
+ save() if @autosave
72
+ e
30
73
  end
31
74
 
32
75
  def delete_key(path)
33
76
  super(path)
34
- save()
77
+ save() if @autosave
35
78
  end
36
79
 
37
80
  def save(filename=nil)
@@ -41,11 +84,28 @@ class DWSRegistry < XMLRegistry
41
84
 
42
85
  def import(s)
43
86
  super(s)
44
- save()
87
+ save() if @autosave
45
88
  end
46
89
 
47
90
  def refresh()
48
91
  load_xml(@filename)
92
+ end
93
+
94
+ private
95
+
96
+ def add_value(key, value)
97
+ e = @doc.root.element(key)
98
+ e.text = value
99
+ return e
100
+ end
101
+
102
+ def find_class(v)
103
+
104
+ if v.to_i.to_s.length == v.length then :number
105
+ elsif v.to_f.to_s.length == v.length then :number
106
+ elsif v.downcase[/^(?:true|false|on|off|yes|no)$/] then :boolean
107
+ elsif v[/^\#.*\#$/] then :time
108
+ end
49
109
  end
50
110
 
51
111
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dws-registry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,41 +10,49 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDRDCCAiygAwIBAgIBADANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
14
  YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTEzMDIwNjIwNTU0MFoXDTE0MDIwNjIwNTU0MFowSDESMBAG
15
+ 8ixkARkWAmV1MB4XDTE1MDMwMzIxNDAwMFoXDTE2MDMwMjIxNDAwMFowSDESMBAG
16
16
  A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
17
  EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
- ggEBAKSBHbbVt+S9YIgCSNN9GThs4F287v7xL580tWa/N47QiNaQ1yIXw98fKa17
19
- T8VvwSin667IkvXiOteBwBlz0Z75wsKQKKpwVbND3zhOlTytomxlL4xjlf9z7s/K
20
- D/mcYE9AbUB/k5X6sI1s0Vkz9MoztkckuAjzwgJ76o72poufH8QxkZ/SM8YQzeZ4
21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DAdBgNVHQ4EFgQUEY2Vnky5jA27FRzvpeB9L++lHKMwJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAdKB/IaEH
27
+ qpvl3WidraocIXd7j7Gq/U9Uq+PPwCwi2Y4mfXjpV8XFIlsFfgbXTo/P2UixgRyk
28
+ 2TcMb/mvSGE1JAhhXzGKcrEkTubZf9zByzxISGM57kGkxWPQhMZ8WhdY4Rpd9KhF
29
+ 4Egen1p8Wc319qZBrlrMm0W4niZzPJ9EwlOvyYS2iU95EnoAwvhx6CnIiYaSEFAW
30
+ dxgstjPYSSEfrbsZiYXY0r6inHIqfU9KJuQ1Zarci4pykJT0fKNLn8ihGSvb/MmH
31
+ PGZIlz7FJwJ4++0ZB4E5454Xa7aPv5k3PP+urajaDnG0vSBYhI76SWHkG0+PBDau
32
+ 8P/40FmSZqbOtg==
31
33
  -----END CERTIFICATE-----
32
- date: 2013-07-27 00:00:00.000000000 Z
34
+ date: 2015-03-03 00:00:00.000000000 Z
33
35
  dependencies:
34
36
  - !ruby/object:Gem::Dependency
35
37
  name: xml-registry
36
38
  requirement: !ruby/object:Gem::Requirement
37
39
  requirements:
38
- - - '>='
40
+ - - "~>"
39
41
  - !ruby/object:Gem::Version
40
- version: '0'
42
+ version: '0.3'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.3.1
41
46
  type: :runtime
42
47
  prerelease: false
43
48
  version_requirements: !ruby/object:Gem::Requirement
44
49
  requirements:
45
- - - '>='
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '0.3'
53
+ - - ">="
46
54
  - !ruby/object:Gem::Version
47
- version: '0'
55
+ version: 0.3.1
48
56
  description:
49
57
  email: james@r0bertson.co.uk
50
58
  executables: []
@@ -62,17 +70,17 @@ require_paths:
62
70
  - lib
63
71
  required_ruby_version: !ruby/object:Gem::Requirement
64
72
  requirements:
65
- - - '>='
73
+ - - ">="
66
74
  - !ruby/object:Gem::Version
67
- version: '0'
75
+ version: 2.1.2
68
76
  required_rubygems_version: !ruby/object:Gem::Requirement
69
77
  requirements:
70
- - - '>='
78
+ - - ">="
71
79
  - !ruby/object:Gem::Version
72
80
  version: '0'
73
81
  requirements: []
74
82
  rubyforge_project:
75
- rubygems_version: 2.0.0.rc.2
83
+ rubygems_version: 2.2.2
76
84
  signing_key:
77
85
  specification_version: 4
78
86
  summary: dws-registry
metadata.gz.sig CHANGED
Binary file