ahoward-configuration 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +14 -3
- data/config/e.rb +1 -1
- data/configuration.gemspec +1 -1
- data/lib/configuration.rb +31 -8
- metadata +1 -1
data/README
CHANGED
@@ -152,9 +152,20 @@ SAMPLES
|
|
152
152
|
|
153
153
|
~ > ruby samples/d.rb
|
154
154
|
|
155
|
-
|
156
|
-
|
157
|
-
|
155
|
+
config/d.rb:2:in `object_id': wrong number of arguments (1 for 0) (ArgumentError)
|
156
|
+
from config/d.rb:2
|
157
|
+
from ./lib/configuration.rb:159:in `instance_eval'
|
158
|
+
from ./lib/configuration.rb:159:in `call'
|
159
|
+
from ./lib/configuration.rb:159:in `method_missing'
|
160
|
+
from ./lib/configuration.rb:105:in `evaluate'
|
161
|
+
from ./lib/configuration.rb:68:in `initialize'
|
162
|
+
from ./lib/configuration.rb:29:in `new'
|
163
|
+
from ./lib/configuration.rb:29:in `for'
|
164
|
+
from config/d.rb:1
|
165
|
+
from ./lib/configuration.rb:53:in `load'
|
166
|
+
from ./lib/configuration.rb:53:in `load'
|
167
|
+
from ./lib/configuration.rb:31:in `for'
|
168
|
+
from samples/d.rb:10
|
158
169
|
|
159
170
|
|
160
171
|
<========< samples/e.rb >========>
|
data/config/e.rb
CHANGED
data/configuration.gemspec
CHANGED
data/lib/configuration.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Configuration
|
2
|
-
Configuration::Version = '1.
|
2
|
+
Configuration::Version = '1.1.0'
|
3
3
|
def Configuration.version() Configuration::Version end
|
4
4
|
|
5
5
|
Path = [
|
@@ -75,14 +75,15 @@ class Configuration
|
|
75
75
|
end
|
76
76
|
send :include, InstanceMethods
|
77
77
|
|
78
|
-
|
79
78
|
class DSL
|
79
|
+
Protected = %r/^__|^object_id$/
|
80
|
+
|
80
81
|
instance_methods.each do |m|
|
81
|
-
undef_method m unless m[
|
82
|
+
undef_method m unless m[Protected]
|
82
83
|
end
|
83
84
|
|
84
85
|
Kernel.methods.each do |m|
|
85
|
-
next if m[
|
86
|
+
next if m[Protected]
|
86
87
|
module_eval <<-code
|
87
88
|
def #{ m }(*a, &b)
|
88
89
|
method_missing '#{ m }', *a, &b
|
@@ -100,7 +101,7 @@ class Configuration
|
|
100
101
|
|
101
102
|
def self.evaluate configuration, options = {}, &block
|
102
103
|
dsl = new configuration
|
103
|
-
Pure[dsl].instance_eval
|
104
|
+
Pure[dsl].instance_eval(&block) if block
|
104
105
|
options.each{|key, value| Pure[dsl].send key, value}
|
105
106
|
Pure[dsl].instance_eval{ @__configuration }
|
106
107
|
end
|
@@ -117,7 +118,8 @@ class Configuration
|
|
117
118
|
@__configuration
|
118
119
|
end
|
119
120
|
|
120
|
-
|
121
|
+
undef_method(:method_missing) rescue nil
|
122
|
+
def method_missing(m, *a, &b)
|
121
123
|
if(a.empty? and b.nil?)
|
122
124
|
return Pure[@__configuration].send(m, *a, &b)
|
123
125
|
end
|
@@ -142,14 +144,35 @@ class Configuration
|
|
142
144
|
define_method(m){ value }
|
143
145
|
end
|
144
146
|
end
|
147
|
+
|
148
|
+
verbose = $VERBOSE
|
149
|
+
begin
|
150
|
+
$VERBOSE = nil
|
151
|
+
def object_id(*args)
|
152
|
+
unless args.empty?
|
153
|
+
verbose = $VERBOSE
|
154
|
+
begin
|
155
|
+
$VERBOSE = nil
|
156
|
+
define_method(:object_id){ args.first }
|
157
|
+
ensure
|
158
|
+
$VERBOSE = verbose
|
159
|
+
end
|
160
|
+
else
|
161
|
+
return Pure[@__configuration].object_id
|
162
|
+
end
|
163
|
+
end
|
164
|
+
ensure
|
165
|
+
$VERBOSE = verbose
|
166
|
+
end
|
145
167
|
end
|
146
168
|
|
147
|
-
class Pure
|
169
|
+
class Pure
|
148
170
|
Instance_Methods = Hash.new
|
171
|
+
Protected = %r/^__|^object_id$/
|
149
172
|
|
150
173
|
::Object.instance_methods.each do |m|
|
151
174
|
Instance_Methods[m.to_s] = ::Object.instance_method m
|
152
|
-
undef_method m unless m[
|
175
|
+
undef_method m unless m[Protected]
|
153
176
|
end
|
154
177
|
|
155
178
|
def method_missing m, *a, &b
|