simple-config 0.4.2 → 0.5.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: 55c903999f63fda86117d56cde5c29b21602a2ae
4
- data.tar.gz: 8cdc62b5eba092b4db60ab1c359c874c6f9b211a
3
+ metadata.gz: dce3c2ab92ee77d32c17b1c3abe116e4d4cba0f9
4
+ data.tar.gz: 9b254b3f942de43f03ff643bac88fcd703357d82
5
5
  SHA512:
6
- metadata.gz: 756bdf86272c60c1caf23c76559db8f8d3217b3ac66ce7c0cb5e1b2057414efe436466a2a3a5f3a542518354d075bf5a47e97c6ca0a7c0e13b0be49553c7e894
7
- data.tar.gz: ef7914457cdcaf8f12e2bc8fd48f51f5dfd0185daafe19ce7bfc71e34c9e748c6e3b7d1709eaf9af292ebac53a010e7facc56736ee0e9ad966d2fdfa8d68d7b5
6
+ metadata.gz: 0634a4869c480a9eb2e72cec6e2bba51f1855b2bc3b906e2c474200fe40fe45c7f89557e4787d1bea720cb020722dfca906efe3b6a057f48ee0d5f63ac86c51a
7
+ data.tar.gz: 6e75f0a78aac472b5f670347c96dd9844a4dc04548105a9ff7444ad7fb7f7d98d01322c490341b4ba5bfbb78336a9f0256ee48b34bf9276a8d37f0fd21ccecc2
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/simple-config.rb CHANGED
@@ -2,27 +2,23 @@
2
2
 
3
3
  # file: simple-config.rb
4
4
 
5
- require 'line-tree'
6
- require 'rxfhelper'
5
+ require 'kvx'
7
6
 
8
7
 
9
- class SimpleConfig
8
+ class SimpleConfig < Kvx
10
9
 
11
10
  attr_reader :to_h, :to_s
12
11
 
13
- def initialize(x=nil, attributes: {})
12
+ def initialize(x, attributes: {})
14
13
 
15
- @header = false
16
- @attributes = attributes
17
- m = {:String => :parse_to_h, :Hash => :write, :SimpleConfig => :passthru}
14
+ if x.is_a? SimpleConfig then
15
+ @to_h = x.to_h
16
+ elsif x
17
+ super(x, attributes: attributes)
18
+ end
18
19
 
19
- method(m[x.class.to_s.to_sym]).call(x) if x
20
20
  end
21
-
22
- def parse(t=nil)
23
- parse_to_h(t || @to_s)
24
- end
25
-
21
+
26
22
  def write(h=nil, header: @header)
27
23
 
28
24
  @to_h = h || @to_h
@@ -38,122 +34,13 @@ class SimpleConfig
38
34
 
39
35
  @to_s = header + scan_to_s(@to_h)
40
36
 
41
- end
42
-
43
- def to_xml(options={pretty: true})
44
-
45
- make_xml(@to_h)
46
-
47
- a = ['simpleconfig', @attributes, '', *make_xml(@to_h)]
48
- Rexle.new(a).xml(options)
49
-
50
- end
37
+ end
51
38
 
52
39
  private
53
40
 
54
- def make_xml(h)
55
-
56
- h.map do |name, x|
57
-
58
- value = x.is_a?(Hash) ? make_xml(x) : x
59
- [name, {}, *value]
60
- end
61
- end
62
-
63
-
64
41
  def parse_to_h(s)
65
-
66
- raw_txt, _ = RXFHelper.read(s)
67
-
68
- # does the raw_txt contain header information?
69
- a = s.strip.lines
70
-
71
- txt = if a[0][/^<\?simple-?config /] then
72
- raw_header = a.shift
73
- @attributes.merge! type: raw_header[/type=["']([^"']+)/,1]
74
- @header = true
75
- a.join
76
- else
77
- raw_txt
78
- end
79
-
80
- scan_to_h(txt)
81
- end
82
-
83
- def passthru(x)
84
- initialize x.to_h
85
- end
86
-
87
- def pretty_print(a, indent='')
88
-
89
- a.map {|x| (x.is_a?(String) or x.nil?) ? x.to_s : pretty_print(x, indent + ' ')}\
90
- .join("\n" + indent)
91
- end
92
-
93
-
94
- def scan_to_h(txt)
95
-
96
- raw_a = LineTree.new(txt.gsub(/(^-*$)|(#.*)/,'').strip,
97
- ignore_blank_lines: false).to_a
98
-
99
- # if there are any orphan lines which aren't nested underneath a
100
- # label, they will be fixed using the following statement
101
-
102
- a = raw_a.chunk {|x| x[0][/^\w+:|.*/]}.inject([]) do |r,y|
103
- if r.last and !y.first[/\w+:/] then
104
- r.last << y.last[-1]
105
- else
106
- r << y.last[-1]
107
- end
108
- r
109
- end
110
-
111
-
112
- @to_h = a.inject({}) do |r, line|
113
-
114
- s = line.shift
115
-
116
-
117
- if line.join.length > 0 then
118
-
119
- r2 = if line[0][0][/^\w+: /] then
120
-
121
- scan_to_h(line.join("\n"))
122
-
123
- else
124
-
125
- desc = pretty_print(line).split(/\n(?=\w+: )/)
126
-
127
- txt2, remaining = desc
128
-
129
- h = txt2.lines.inject([]) do |r, x|
130
- x.chomp!
131
- x.length > 0 ? r << x : r
132
- end
133
-
134
- r3 = {description: txt2, items: h}
135
-
136
- if remaining then
137
-
138
- r3.merge!(scan_to_h remaining + "\n ")
139
- end
140
-
141
- r3
142
- end
143
-
144
- r.merge({s[/[^:]+/].to_sym => r2})
145
-
146
- else
147
-
148
- value, name = s.split(': ',2).reverse
149
- name ||= 'description'
150
-
151
- r.merge({name.to_sym => value.to_s})
152
- end
153
-
154
- end
155
-
156
- end
42
+ super(s, header_pattern: %r(^<\?simple-?config ))
43
+ end
157
44
 
158
45
  def scan_to_s(h, indent='')
159
46
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,28 +31,28 @@ cert_chain:
31
31
  GOyi72Dr1XTvfW8Vje543EzUeJP4EjrtsoS0tbx5hs2J8Ey8zv39aU4aNyM1h0Fv
32
32
  1BzvTQ2PY7IAEQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-04-23 00:00:00.000000000 Z
34
+ date: 2015-04-24 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
- name: line-tree
37
+ name: kvx
38
38
  requirement: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '0.5'
42
+ version: '0.1'
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: 0.5.0
45
+ version: 0.1.2
46
46
  type: :runtime
47
47
  prerelease: false
48
48
  version_requirements: !ruby/object:Gem::Requirement
49
49
  requirements:
50
50
  - - "~>"
51
51
  - !ruby/object:Gem::Version
52
- version: '0.5'
52
+ version: '0.1'
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 0.5.0
55
+ version: 0.1.2
56
56
  description:
57
57
  email: james@r0bertson.co.uk
58
58
  executables: []
@@ -83,5 +83,6 @@ rubyforge_project:
83
83
  rubygems_version: 2.4.6
84
84
  signing_key:
85
85
  specification_version: 4
86
- summary: simple-config
86
+ summary: Simple-config makes it convenient to read or write a config file as simple
87
+ as possible
87
88
  test_files: []
metadata.gz.sig CHANGED
Binary file