loquacious 1.6.3 → 1.6.4

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.
@@ -1,3 +1,9 @@
1
+ == 1.6.4 / 2010-06-08
2
+
3
+ * Bug Fixes
4
+ * Extending a configuration was not working properly
5
+ * Descriptions were being overwritten when extending a configuration
6
+
1
7
  == 1.6.3 / 2010-06-07
2
8
 
3
9
  * Bug Fixes
@@ -27,12 +27,10 @@ module Loquacious
27
27
  return @table.has_key?(name) ? @table[name] : nil
28
28
  end
29
29
 
30
- cfg = DSL.evaluate(&block)
31
-
32
30
  if @table.has_key? name
33
- @table[name].merge! cfg
31
+ DSL.new(@table[name], &block)
34
32
  else
35
- @table[name] = cfg
33
+ @table[name] = DSL.evaluate(&block)
36
34
  end
37
35
  end
38
36
 
@@ -105,7 +103,7 @@ module Loquacious
105
103
  end
106
104
  CODE
107
105
 
108
- __desc[m] = nil
106
+ __desc[m] = nil unless __desc.has_key? m
109
107
 
110
108
  default = (args.empty? and !block) ? Loquacious::Undefined.new(m.to_s) : nil
111
109
  self.__send("#{m}=", default)
@@ -184,6 +182,8 @@ module Loquacious
184
182
  # configuration object.
185
183
  #
186
184
  class DSL
185
+ alias :__instance_eval :instance_eval
186
+
187
187
  instance_methods(true).each do |m|
188
188
  next if m[Keepers]
189
189
  undef_method m
@@ -215,11 +215,10 @@ module Loquacious
215
215
  # Creates a new DSL and evaluates the given _block_ in the context of
216
216
  # the DSL.
217
217
  #
218
- def initialize( &block )
218
+ def initialize( config = nil, &block )
219
219
  @description = nil
220
- @__config = Configuration.new
221
- Object.instance_method(:instance_eval).bind(self).
222
- call(&block) if block
220
+ @__config = config || Configuration.new
221
+ __instance_eval(&block)
223
222
  end
224
223
 
225
224
  # Dynamically adds the given _method_ to the configuration as an
@@ -235,10 +234,10 @@ module Loquacious
235
234
  self.desc(opts[:desc]) if opts.has_key? :desc
236
235
  end
237
236
 
238
- __config.__send(m, *args, &block)
239
- __config.__desc[m] = @description
240
-
237
+ rv = __config.__send(m, *args, &block)
238
+ __config.__desc[m] = @description if @description
241
239
  @description = nil
240
+ rv
242
241
  end
243
242
 
244
243
  # Store the _string_ as the description for the next attribute that
@@ -124,6 +124,56 @@ describe Loquacious::Configuration do
124
124
  obj.third.should == 'Hello World!'
125
125
  end
126
126
 
127
+ it 'should return a value when evaluating inside the DSL' do
128
+ obj = Loquacious::Configuration.new {
129
+ first 'foo'
130
+ second {
131
+ bar nil
132
+ }
133
+ }
134
+
135
+ obj.first.should == 'foo'
136
+ obj.second.bar.should be_nil
137
+
138
+ Loquacious::Configuration::DSL.new(obj) {
139
+ first 'bar'
140
+ second.bar 'no longer nil'
141
+ }
142
+
143
+ obj.first.should == 'bar'
144
+ obj.second.bar.should == 'no longer nil'
145
+ end
146
+
147
+ it 'should not delete descriptions' do
148
+ obj = Loquacious::Configuration.new {
149
+ first 'foo', :desc => 'the first value'
150
+
151
+ desc 'the second value'
152
+ second {
153
+ bar nil, :desc => 'time to go drinking'
154
+ }
155
+ }
156
+
157
+ obj.first.should == 'foo'
158
+ obj.second.bar.should be_nil
159
+
160
+ obj.__desc[:first].should == 'the first value'
161
+ obj.__desc[:second].should == 'the second value'
162
+ obj.second.__desc[:bar].should == 'time to go drinking'
163
+
164
+ Loquacious::Configuration::DSL.new(obj) {
165
+ first 'bar'
166
+ second.bar 'no longer nil'
167
+ }
168
+
169
+ obj.first.should == 'bar'
170
+ obj.second.bar.should == 'no longer nil'
171
+
172
+ obj.__desc[:first].should == 'the first value'
173
+ obj.__desc[:second].should == 'the second value'
174
+ obj.second.__desc[:bar].should == 'time to go drinking'
175
+ end
176
+
127
177
  # -----------------------------------------------------------------------
128
178
  describe 'when merging' do
129
179
 
@@ -1 +1 @@
1
- 1.6.3
1
+ 1.6.4
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 6
8
- - 3
9
- version: 1.6.3
8
+ - 4
9
+ version: 1.6.4
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-06-07 00:00:00 -06:00
17
+ date: 2010-06-08 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency