loquacious 1.5.0 → 1.5.1
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.
- data/History.txt +5 -0
- data/lib/loquacious/configuration.rb +29 -11
- data/spec/configuration_spec.rb +12 -0
- data/version.txt +1 -1
- metadata +3 -3
data/History.txt
CHANGED
@@ -49,8 +49,12 @@ module Loquacious
|
|
49
49
|
alias :help :help_for
|
50
50
|
end
|
51
51
|
|
52
|
+
# Internal alias for the respond_to? method.
|
53
|
+
#
|
54
|
+
alias :__respond_to? :respond_to?
|
55
|
+
|
52
56
|
Keepers = %r/^__|^object_id$|^instance_of\?$|^kind_of\?$|^equal\?$/
|
53
|
-
instance_methods.each do |m|
|
57
|
+
instance_methods(true).each do |m|
|
54
58
|
next if m[Keepers]
|
55
59
|
undef_method m
|
56
60
|
end
|
@@ -106,8 +110,18 @@ module Loquacious
|
|
106
110
|
CODE
|
107
111
|
|
108
112
|
__desc[m]
|
109
|
-
self.
|
110
|
-
self.
|
113
|
+
self.__send("#{m}=", nil)
|
114
|
+
self.__send("#{m}", *args, &block)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Only invoke public methods on the Configuration instances.
|
118
|
+
#
|
119
|
+
def __send( symbol, *args, &block )
|
120
|
+
if self.__respond_to? symbol
|
121
|
+
self.__send__(symbol, *args, &block)
|
122
|
+
else
|
123
|
+
self.method_missing(symbol, *args, &block)
|
124
|
+
end
|
111
125
|
end
|
112
126
|
|
113
127
|
# Evaluate the given _code_ string in the context of this object's
|
@@ -132,11 +146,11 @@ module Loquacious
|
|
132
146
|
Kernel.raise Error, "can only merge another Configuration" unless other.kind_of?(Configuration)
|
133
147
|
|
134
148
|
other.__desc.each do |key,desc|
|
135
|
-
value = other.
|
136
|
-
if self.
|
137
|
-
self.
|
149
|
+
value = other.__send(key)
|
150
|
+
if self.__send(key).kind_of?(Configuration)
|
151
|
+
self.__send(key).merge! value
|
138
152
|
else
|
139
|
-
self.
|
153
|
+
self.__send("#{key}=", value)
|
140
154
|
end
|
141
155
|
__desc[key] = desc
|
142
156
|
end
|
@@ -153,7 +167,7 @@ module Loquacious
|
|
153
167
|
# config.port #=> 1234
|
154
168
|
#
|
155
169
|
def []( key )
|
156
|
-
self.
|
170
|
+
self.__send(key)
|
157
171
|
end
|
158
172
|
|
159
173
|
# Provides hash accessor notation for configuration values.
|
@@ -163,7 +177,7 @@ module Loquacious
|
|
163
177
|
# config.port #=> 8808
|
164
178
|
#
|
165
179
|
def []=( key, value )
|
166
|
-
self.
|
180
|
+
self.__send(key, value)
|
167
181
|
end
|
168
182
|
|
169
183
|
# Implementation of a doman specific language for creating configuration
|
@@ -172,7 +186,11 @@ module Loquacious
|
|
172
186
|
#
|
173
187
|
class DSL
|
174
188
|
Keepers = %r/^__|^object_id$/
|
175
|
-
instance_methods.each do |m|
|
189
|
+
instance_methods(true).each do |m|
|
190
|
+
next if m[Keepers]
|
191
|
+
undef_method m
|
192
|
+
end
|
193
|
+
private_instance_methods(true).each do |m|
|
176
194
|
next if m[Keepers]
|
177
195
|
undef_method m
|
178
196
|
end
|
@@ -219,7 +237,7 @@ module Loquacious
|
|
219
237
|
self.desc(opts[:desc]) if opts.has_key? :desc
|
220
238
|
end
|
221
239
|
|
222
|
-
__config.
|
240
|
+
__config.__send(m, *args, &block)
|
223
241
|
__config.__desc[m] = @description
|
224
242
|
|
225
243
|
@description = nil
|
data/spec/configuration_spec.rb
CHANGED
@@ -95,6 +95,18 @@ describe Loquacious::Configuration do
|
|
95
95
|
cfg.puts.should == 'not what you think'
|
96
96
|
end
|
97
97
|
|
98
|
+
it 'should not be affected by loading other modules like timeout' do
|
99
|
+
require 'timeout'
|
100
|
+
cfg = Loquacious::Configuration.new {
|
101
|
+
timeout 10
|
102
|
+
foo 'bar'
|
103
|
+
baz 'buz'
|
104
|
+
}
|
105
|
+
cfg.timeout.should == 10
|
106
|
+
cfg.foo.should == 'bar'
|
107
|
+
cfg.baz.should == 'buz'
|
108
|
+
end
|
109
|
+
|
98
110
|
it 'should evaluate Proc objects when fetching values' do
|
99
111
|
obj = Loquacious::Configuration.new {
|
100
112
|
first 'foo'
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.1
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 1.5.
|
8
|
+
- 1
|
9
|
+
version: 1.5.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Tim Pease
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-06 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|