configer 1.2.1 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/config/sample.yml +2 -0
- data/example/lazy_load.rb +6 -0
- data/lib/configer/object.rb +30 -19
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc6e971366b16d5faf5576b7fee7084d473f8092
|
4
|
+
data.tar.gz: aa4fbb43a210fe45f0c06f9be4d0610bd459b418
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df4c63893bfc618cdfc8d639251e47ac057b31f9d83a08472b524c17f5c525706d2747a98ca2cdaef92cada172e64ae101111d5a5c8c7e2701a3c5e0542661ff
|
7
|
+
data.tar.gz: 487abd626b7aac75e10590d881a5c368cf2abbfec18dff9c92066f202cc32ecf315a490f2ec77c127befd27176b480a6b0903c41aaf178726e5251154118837f
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.3
|
data/config/sample.yml
ADDED
data/lib/configer/object.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Configer
|
2
2
|
|
3
|
-
class Object <
|
3
|
+
class Object < Hash
|
4
4
|
|
5
5
|
self.instance_methods.each do |sym|
|
6
6
|
self.__send__ :protected, sym
|
@@ -8,24 +8,27 @@ module Configer
|
|
8
8
|
|
9
9
|
def method_missing( method_name, *args )
|
10
10
|
|
11
|
-
if method_name
|
12
|
-
self[method_name
|
13
|
-
return self[method_name
|
14
|
-
else
|
11
|
+
if method_name[-1] == '='
|
12
|
+
self[method_name[0..-2]]= *args
|
13
|
+
return self[method_name[0..-2]]
|
15
14
|
|
15
|
+
else
|
16
|
+
#> respond to method only if no value present
|
16
17
|
if self[method_name.to_s].nil? && self.respond_to?(method_name)
|
17
18
|
return self.__send__(method_name)
|
19
|
+
|
18
20
|
else
|
19
21
|
return self[method_name.to_s]
|
22
|
+
|
20
23
|
end
|
21
24
|
|
22
25
|
end
|
23
26
|
|
24
27
|
end
|
25
28
|
|
26
|
-
public :__send__,:respond_to?
|
29
|
+
public :__send__,:public_send,:respond_to?
|
27
30
|
|
28
|
-
#> allowed Hash methods
|
31
|
+
#> some allowed Hash methods
|
29
32
|
public :to_s,:inspect,:delete,:delete_if,
|
30
33
|
:merge!,:merge,:keys,:values,:freeze
|
31
34
|
|
@@ -42,26 +45,30 @@ module Configer
|
|
42
45
|
public
|
43
46
|
|
44
47
|
def [] key
|
45
|
-
key = key.to_s
|
46
|
-
super
|
48
|
+
key = key.to_s if key.class <= Symbol
|
49
|
+
super || super(key.to_sym)
|
47
50
|
end
|
48
51
|
|
49
52
|
def []= key,value
|
50
|
-
key = key.to_s
|
53
|
+
key = key.to_s if key.class <= Symbol
|
51
54
|
super
|
52
55
|
end
|
53
56
|
|
54
57
|
#> parse object
|
55
|
-
def self.parse
|
56
|
-
raise(ArgumentError,"input must be Hash") unless obj.is_a? ::Hash
|
58
|
+
def self.parse(obj)
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
return case
|
61
|
+
|
62
|
+
when obj.class <= Hash
|
63
|
+
obj.reduce(self.new){|m,h| m.merge!( (h[0].class <= Symbol ? h[0].to_s : h[0] ) => self.parse(h[1]) ) ;m}
|
64
|
+
|
65
|
+
when obj.class <= Array
|
66
|
+
obj.map{|o| self.parse(o) }
|
67
|
+
|
68
|
+
else
|
69
|
+
obj
|
70
|
+
|
71
|
+
end
|
65
72
|
|
66
73
|
end
|
67
74
|
|
@@ -81,6 +88,10 @@ module Configer
|
|
81
88
|
|
82
89
|
alias :init :new
|
83
90
|
|
91
|
+
def parse(obj)
|
92
|
+
self::Object.parse(obj)
|
93
|
+
end
|
94
|
+
|
84
95
|
end
|
85
96
|
|
86
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -51,7 +51,9 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- VERSION
|
54
|
+
- config/sample.yml
|
54
55
|
- configer.gemspec
|
56
|
+
- example/lazy_load.rb
|
55
57
|
- example/sample.rb
|
56
58
|
- lib/configer.rb
|
57
59
|
- lib/configer/dsl.rb
|