fun_with_configurations 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/fun_with/configurations/config.rb +44 -25
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -92,43 +92,62 @@ module FunWith
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def try( *keys )
|
95
|
-
t = TryObject.new( self )
|
96
|
-
|
97
|
-
|
98
|
-
|
95
|
+
(t = TryObject.new( self )).tap do
|
96
|
+
for key in keys
|
97
|
+
t[key]
|
98
|
+
end
|
99
99
|
end
|
100
|
-
|
101
|
-
t
|
102
100
|
end
|
103
101
|
|
104
102
|
def to_ruby_code( indent = 0 )
|
105
|
-
code = ""
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
103
|
+
(code = "").tap do
|
104
|
+
if indent == 0
|
105
|
+
code << "FunWith::Configurations::Config.new do\n"
|
106
|
+
code << self.to_ruby_code( 2 )
|
107
|
+
code << "end\n"
|
108
|
+
else
|
109
|
+
for k, v in @config_vars
|
110
|
+
if v.is_a?( Config )
|
111
|
+
code << (" " * indent) + "#{k} do\n"
|
112
|
+
code << v.to_ruby_code( indent + 2 )
|
113
|
+
code << (" " * indent) + "end\n"
|
114
|
+
else
|
115
|
+
code << (" " * indent) + "#{k} #{v.inspect}\n"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def each( *args, &block )
|
123
|
+
@config_vars.each( *args, &block )
|
124
|
+
end
|
125
|
+
|
126
|
+
def to_s( style = :hash )
|
127
|
+
case style
|
128
|
+
when :hash
|
129
|
+
self.to_hash.inspect
|
130
|
+
when :ruby
|
131
|
+
self.to_ruby_code
|
110
132
|
else
|
133
|
+
super
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def to_hash
|
138
|
+
(hash = {}).tap do
|
111
139
|
for k, v in @config_vars
|
112
|
-
|
113
|
-
code << (" " * indent) + "#{k} do\n"
|
114
|
-
code << v.to_ruby_code( indent + 2 )
|
115
|
-
code << (" " * indent) + "end\n"
|
116
|
-
else
|
117
|
-
code << (" " * indent) + "#{k} #{v.inspect}\n"
|
118
|
-
end
|
140
|
+
hash[k] = v.is_a?(Config) ? v.to_hash : v
|
119
141
|
end
|
120
142
|
end
|
121
|
-
|
122
|
-
code
|
123
143
|
end
|
124
144
|
|
125
145
|
def self.from_hash( hash )
|
126
|
-
config = self.new
|
127
|
-
|
128
|
-
|
129
|
-
|
146
|
+
(config = self.new).tap do
|
147
|
+
for k, v in hash
|
148
|
+
config.send( k, v.is_a?( Hash ) ? self.from_hash( v ) : v )
|
149
|
+
end
|
130
150
|
end
|
131
|
-
|
132
151
|
config
|
133
152
|
end
|
134
153
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fun_with_configurations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fun_with_files
|
@@ -144,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
segments:
|
146
146
|
- 0
|
147
|
-
hash: -
|
147
|
+
hash: -502379231947070580
|
148
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|