simple-config 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/simple-config.rb +30 -25
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5577c4a063185bc438d6087e58833990fc183f4
|
4
|
+
data.tar.gz: 2261d405f7135e9cd244f9f6823ae997e689f9c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8c6bf060bc38ec46d736a0df73c624780680fcf00970ff545a7f54bb8fb3be7b80764f91a01fbab76c4cd1d620d9b4f1814c44a6fc1b26924c588b37b4ab062
|
7
|
+
data.tar.gz: e557f639e6dac142c5052f6bf3af4b7702f8eaaf89aeb12c71f93a151302421ef50bfc46eb828e619cdcca98191ac1b21b9dc130909905abb01df378914f1f2a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/simple-config.rb
CHANGED
@@ -6,16 +6,6 @@ require 'line-tree'
|
|
6
6
|
require 'rxfhelper'
|
7
7
|
|
8
8
|
|
9
|
-
#!/usr/bin/env ruby
|
10
|
-
|
11
|
-
# file: simple-config.rb
|
12
|
-
|
13
|
-
require 'line-tree'
|
14
|
-
require 'requestor'
|
15
|
-
|
16
|
-
eval Requestor.read('http://rorbuilder.info/r/ruby'){|x| x.require 'rxfhelper'}
|
17
|
-
|
18
|
-
|
19
9
|
class SimpleConfig
|
20
10
|
|
21
11
|
attr_reader :to_h, :to_s
|
@@ -35,38 +25,53 @@ class SimpleConfig
|
|
35
25
|
|
36
26
|
private
|
37
27
|
|
28
|
+
|
29
|
+
def pretty_print(a, indent='')
|
30
|
+
|
31
|
+
a.map {|x| x.is_a?(String) ? x : pretty_print(x, indent + ' ')}\
|
32
|
+
.join("\n" + indent)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
38
36
|
def scan_to_h(raw_txt)
|
39
37
|
|
40
38
|
txt, _ = RXFHelper.read(raw_txt)
|
41
|
-
|
42
39
|
raw_a = LineTree.new(txt.gsub(/(^-*$)|(#.*)/,'').strip).to_a
|
43
40
|
|
44
|
-
|
41
|
+
@to_h = raw_a.inject({}) do |r, line|
|
45
42
|
|
46
43
|
s = line.shift
|
47
44
|
|
48
45
|
if line.any? then
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
|
47
|
+
r2 = if line[0][0][/^\w+:/] then
|
48
|
+
scan_to_h(line.join("\n"))
|
49
|
+
else
|
50
|
+
|
51
|
+
desc = pretty_print(line).split(/\n(?=\w+:)/)
|
52
|
+
txt, remaining = desc
|
53
|
+
|
54
|
+
r3 = {description: txt, items: txt.lines.map(&:chomp)}
|
55
|
+
|
56
|
+
if remaining then
|
57
|
+
r3.merge!(scan_to_h remaining + "\n ")
|
58
|
+
end
|
59
|
+
|
60
|
+
r3
|
61
|
+
end
|
62
|
+
|
63
|
+
r.merge({s[/[^:]+/].to_sym => r2})
|
52
64
|
|
53
65
|
else
|
54
66
|
|
55
67
|
value, name = s.split(': ',2).reverse
|
56
68
|
name ||= 'description'
|
57
69
|
|
58
|
-
|
59
|
-
end
|
70
|
+
r.merge({name.to_sym => value.to_s})
|
71
|
+
end
|
60
72
|
|
61
73
|
end
|
62
|
-
|
63
|
-
anonymous_items, remaining = a.partition {|x| x.first == :description }
|
64
|
-
|
65
|
-
if anonymous_items.any? then
|
66
|
-
return {items: anonymous_items.map(&:last)}.merge(Hash[remaining])
|
67
|
-
else
|
68
|
-
@to_h = Hash[a]
|
69
|
-
end
|
74
|
+
|
70
75
|
end
|
71
76
|
|
72
77
|
def scan_to_s(h, indent='')
|
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.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
GOyi72Dr1XTvfW8Vje543EzUeJP4EjrtsoS0tbx5hs2J8Ey8zv39aU4aNyM1h0Fv
|
32
32
|
1BzvTQ2PY7IAEQ==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2014-11-
|
34
|
+
date: 2014-11-05 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: line-tree
|
metadata.gz.sig
CHANGED
Binary file
|