loquacious 1.7.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/README.rdoc +7 -12
- data/Rakefile +2 -3
- data/examples/gutters.rb +2 -3
- data/examples/nested.rb +4 -8
- data/lib/loquacious.rb +13 -0
- data/lib/loquacious/configuration.rb +102 -28
- data/spec/configuration_spec.rb +149 -12
- data/spec/spec_helper.rb +1 -2
- data/version.txt +1 -1
- metadata +11 -12
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Loquacious
|
2
2
|
by Tim Pease
|
3
|
-
http://
|
3
|
+
http://rubygems.org/gems/loquacious
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
@@ -104,32 +104,28 @@ they can appear above the attribute and value on their own line.
|
|
104
104
|
|
105
105
|
desc "Configuration options for ActiveRecord::Base."
|
106
106
|
active_record {
|
107
|
-
desc <<-__
|
107
|
+
colorize_logging true, :desc => <<-__
|
108
108
|
Determines whether to use ANSI codes to colorize the logging statements committed
|
109
109
|
by the connection adapter. These colors make it much easier to overview things
|
110
110
|
during debugging (when used through a reader like +tail+ and on a black background),
|
111
111
|
but may complicate matters if you use software like syslog. This is true, by default.
|
112
112
|
__
|
113
|
-
colorize_logging true
|
114
113
|
|
115
|
-
desc <<-__
|
114
|
+
default_timezone :local, :desc => <<-__
|
116
115
|
Determines whether to use Time.local (using :local) or Time.utc (using :utc)
|
117
116
|
when pulling dates and times from the database. This is set to :local by default.
|
118
117
|
__
|
119
|
-
default_timezone :local
|
120
118
|
}
|
121
119
|
|
122
|
-
desc <<-__
|
120
|
+
log_level :info, :desc => <<-__
|
123
121
|
The log level to use for the default Rails logger. In production mode,
|
124
122
|
this defaults to :info. In development mode, it defaults to :debug.
|
125
123
|
__
|
126
|
-
log_level :info
|
127
124
|
|
128
|
-
desc <<-__
|
125
|
+
log_path 'log/development.log', :desc => <<-__
|
129
126
|
The path to the log file to use. Defaults to log/\#{environment}.log
|
130
127
|
(e.g. log/development.log or log/production.log).
|
131
128
|
__
|
132
|
-
log_path 'log/development.log'
|
133
129
|
}
|
134
130
|
|
135
131
|
help = Configuration.help_for :nested
|
@@ -170,14 +166,13 @@ they can appear above the attribute and value on their own line.
|
|
170
166
|
include Loquacious
|
171
167
|
|
172
168
|
Configuration.for(:gutters) {
|
173
|
-
desc <<-__
|
169
|
+
log_path "log/development.log", :desc => <<-__
|
174
170
|
The path to the log file to use. Defaults to log/\#{environment}.log
|
175
171
|
(e.g. log/development.log or log/production.log).
|
176
172
|
|
|
177
173
|
| config.log_path = File.join(ROOT, "log", "\#{environment}.log
|
178
174
|
|
|
179
175
|
__
|
180
|
-
log_path "log/development.log"
|
181
176
|
|
182
177
|
log_level :warn, :desc => <<-__
|
183
178
|
|The log level to use for the default Rails logger. In production mode,
|
@@ -212,7 +207,7 @@ they can appear above the attribute and value on their own line.
|
|
212
207
|
|
213
208
|
(The MIT License)
|
214
209
|
|
215
|
-
Copyright (c) 2009-
|
210
|
+
Copyright (c) 2009-2011
|
216
211
|
|
217
212
|
Permission is hereby granted, free of charge, to any person obtaining
|
218
213
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
@@ -12,13 +12,12 @@ Bones {
|
|
12
12
|
name 'loquacious'
|
13
13
|
authors 'Tim Pease'
|
14
14
|
email 'tim.pease@gmail.com'
|
15
|
-
url 'http://
|
15
|
+
url 'http://rubygems.org/gems/loquacious'
|
16
16
|
readme_file 'README.rdoc'
|
17
|
-
ignore_file '.gitignore'
|
18
17
|
spec.opts << '--color'
|
19
18
|
use_gmail
|
20
19
|
|
21
|
-
depend_on 'rspec', :development => true
|
20
|
+
depend_on 'rspec', '~> 2.6', :development => true
|
22
21
|
}
|
23
22
|
|
24
23
|
task 'ann:prereqs' do
|
data/examples/gutters.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
# Using Ruby heredocs for descriptions, the Loquacious configuration will
|
2
2
|
# strip out leading whitespace but preserve line breaks. Gutter lines can be
|
3
3
|
# used to mark where leading whitespace should be preserved. This is useful
|
4
|
-
#
|
4
|
+
# if you need to provide example code in your descriptions.
|
5
5
|
|
6
6
|
require 'loquacious'
|
7
7
|
include Loquacious
|
8
8
|
|
9
9
|
Configuration.for(:gutters) {
|
10
|
-
desc <<-__
|
10
|
+
log_path "log/development.log", :desc => <<-__
|
11
11
|
The path to the log file to use. Defaults to log/\#{environment}.log
|
12
12
|
(e.g. log/development.log or log/production.log).
|
13
13
|
|
|
14
14
|
| config.log_path = File.join(ROOT, "log", "\#{environment}.log
|
15
15
|
|
|
16
16
|
__
|
17
|
-
log_path "log/development.log"
|
18
17
|
|
19
18
|
log_level :warn, :desc => <<-__
|
20
19
|
|The log level to use for the default Rails logger. In production mode,
|
data/examples/nested.rb
CHANGED
@@ -15,32 +15,28 @@ Configuration.for(:nested) {
|
|
15
15
|
|
16
16
|
desc "Configuration options for ActiveRecord::Base."
|
17
17
|
active_record {
|
18
|
-
desc <<-__
|
18
|
+
colorize_logging true, :desc => <<-__
|
19
19
|
Determines whether to use ANSI codes to colorize the logging statements committed
|
20
20
|
by the connection adapter. These colors make it much easier to overview things
|
21
21
|
during debugging (when used through a reader like +tail+ and on a black background),
|
22
22
|
but may complicate matters if you use software like syslog. This is true, by default.
|
23
23
|
__
|
24
|
-
colorize_logging true
|
25
24
|
|
26
|
-
desc <<-__
|
25
|
+
default_timezone :local, :desc => <<-__
|
27
26
|
Determines whether to use Time.local (using :local) or Time.utc (using :utc)
|
28
27
|
when pulling dates and times from the database. This is set to :local by default.
|
29
28
|
__
|
30
|
-
default_timezone :local
|
31
29
|
}
|
32
30
|
|
33
|
-
desc <<-__
|
31
|
+
log_level :info, :desc => <<-__
|
34
32
|
The log level to use for the default Rails logger. In production mode,
|
35
33
|
this defaults to :info. In development mode, it defaults to :debug.
|
36
34
|
__
|
37
|
-
log_level :info
|
38
35
|
|
39
|
-
desc <<-__
|
36
|
+
log_path 'log/development.log', :desc => <<-__
|
40
37
|
The path to the log file to use. Defaults to log/\#{environment}.log
|
41
38
|
(e.g. log/development.log or log/production.log).
|
42
39
|
__
|
43
|
-
log_path 'log/development.log'
|
44
40
|
}
|
45
41
|
|
46
42
|
help = Configuration.help_for :nested
|
data/lib/loquacious.rb
CHANGED
@@ -25,6 +25,18 @@ module Loquacious
|
|
25
25
|
alias :config_for :configuration_for
|
26
26
|
alias :config :configuration_for
|
27
27
|
|
28
|
+
# Set the default properties for the configuration associated with the
|
29
|
+
# given _name_. A _block_ must be provided to this method.
|
30
|
+
#
|
31
|
+
# The same _name_ can be used multiple times with different configuration
|
32
|
+
# blocks. Each block will add or modify the configuration; i.e. the
|
33
|
+
# configurations are additive.
|
34
|
+
#
|
35
|
+
def defaults_for( name, &block )
|
36
|
+
::Loquacious::Configuration.defaults_for(name, &block)
|
37
|
+
end
|
38
|
+
alias :defaults :defaults_for
|
39
|
+
|
28
40
|
# Returns a Help instance for the configuration associated with the
|
29
41
|
# given _name_. See the Help#initialize method for the options that
|
30
42
|
# can be used with this method.
|
@@ -82,6 +94,7 @@ module Loquacious
|
|
82
94
|
# Loquacious.remove :gem # courtesy of rubygems
|
83
95
|
# Loquacious.remove :test, :file # courtesy of rake
|
84
96
|
# Loquacious.remove :main # courtesy of main
|
97
|
+
# Loquacious.remove :timeout # courtesy of timeout
|
85
98
|
#
|
86
99
|
def remove( *args )
|
87
100
|
args.each { |name|
|
@@ -1,7 +1,20 @@
|
|
1
1
|
|
2
2
|
module Loquacious
|
3
3
|
|
4
|
+
# A Configuration provides a "blank slate" for storing configuration
|
5
|
+
# properties along with descriptions and default values. Configurations are
|
6
|
+
# accessed by name, and hence, the configuration properties can be retrieved
|
7
|
+
# from any location in your code.
|
4
8
|
#
|
9
|
+
# Each property has an associated description that can be displayed to the
|
10
|
+
# user via the Configuration::Help class. This is the main point of the
|
11
|
+
# Loquacious library - tell the user what all yoru configruation properties
|
12
|
+
# actually do!
|
13
|
+
#
|
14
|
+
# Each configurationp property can also have a default value that is
|
15
|
+
# returned if no value has been set for that property. Each property should
|
16
|
+
# hae a sensible default - the user should not have to configure every
|
17
|
+
# property in order to use a piece of code.
|
5
18
|
#
|
6
19
|
class Configuration
|
7
20
|
|
@@ -28,12 +41,36 @@ module Loquacious
|
|
28
41
|
end
|
29
42
|
|
30
43
|
if @table.has_key? name
|
31
|
-
DSL.
|
44
|
+
DSL.evaluate(:config => @table[name], &block)
|
32
45
|
else
|
33
46
|
@table[name] = DSL.evaluate(&block)
|
34
47
|
end
|
35
48
|
end
|
36
49
|
|
50
|
+
# call-seq:
|
51
|
+
# Configuration.defaults_for( name ) { block }
|
52
|
+
#
|
53
|
+
# Set the default values for the configuration associated with the given
|
54
|
+
# _name_. A _block_ is required by this method.
|
55
|
+
#
|
56
|
+
# Default values do not interfere with normal configuration values. If
|
57
|
+
# both are defined for a particualr configruation setting, then the
|
58
|
+
# regular configuration value will be returned.
|
59
|
+
#
|
60
|
+
# Defaults allow the user to define configuration values before the
|
61
|
+
# library defaults have been loaded. They prevent library defaults from
|
62
|
+
# overriding user settings.
|
63
|
+
#
|
64
|
+
def defaults_for( name, &block )
|
65
|
+
raise "defaults require a block" if block.nil?
|
66
|
+
|
67
|
+
if @table.has_key? name
|
68
|
+
DSL.evaluate(:config => @table[name], :defaults_mode => true, &block)
|
69
|
+
else
|
70
|
+
@table[name] = DSL.evaluate(:defaults_mode => true, &block)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
37
74
|
# call-seq:
|
38
75
|
# Configuration.help_for( name, opts = {} )
|
39
76
|
#
|
@@ -64,12 +101,25 @@ module Loquacious
|
|
64
101
|
# Accessor for the description hash.
|
65
102
|
attr_reader :__desc
|
66
103
|
|
104
|
+
# Accessor for configuration values
|
105
|
+
attr_reader :__values
|
106
|
+
|
107
|
+
# Accessor for configuration defaults
|
108
|
+
attr_reader :__defaults
|
109
|
+
|
110
|
+
# Flag to switch the configuration object into defaults mode. This allows
|
111
|
+
# default values to be set instead regular values.
|
112
|
+
attr_accessor :__defaults_mode
|
113
|
+
|
67
114
|
# Create a new configuration object and initialize it using an optional
|
68
115
|
# _block_ of code.
|
69
116
|
#
|
70
117
|
def initialize( &block )
|
71
118
|
@__desc = Hash.new
|
72
|
-
|
119
|
+
@__values = Hash.new
|
120
|
+
@__defaults = Hash.new
|
121
|
+
@__defaults_mode = false
|
122
|
+
DSL.evaluate(:config => self, &block) if block
|
73
123
|
end
|
74
124
|
|
75
125
|
# When invoked, an attribute reader and writer are defined for the
|
@@ -81,31 +131,40 @@ module Loquacious
|
|
81
131
|
def method_missing( method, *args, &block )
|
82
132
|
m = method.to_s.delete('=').to_sym
|
83
133
|
|
84
|
-
__eigenclass_eval "
|
85
|
-
__eigenclass_eval <<-CODE
|
134
|
+
__eigenclass_eval "def #{m}=( value ) @__values[#{m.inspect}] = value; end", __FILE__, __LINE__
|
135
|
+
__eigenclass_eval <<-CODE, __FILE__, __LINE__+1
|
86
136
|
def #{m}( *args, &block )
|
137
|
+
value = @__values[#{m.inspect}]
|
138
|
+
|
87
139
|
if args.empty? and !block
|
88
|
-
return
|
89
|
-
|
140
|
+
return value if value.kind_of?(Configuration)
|
141
|
+
value = @__defaults[#{m.inspect}] if value.kind_of?(Loquacious::Undefined) and @__defaults.has_key? #{m.inspect}
|
142
|
+
return value.respond_to?(:call) ? value.call : value
|
90
143
|
end
|
91
144
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
145
|
+
if block
|
146
|
+
v = DSL.evaluate(:defaults_mode => __defaults_mode, &block)
|
147
|
+
if value.kind_of?(Configuration)
|
148
|
+
value.merge! v
|
149
|
+
else
|
150
|
+
@__values[#{m.inspect}] = v
|
151
|
+
end
|
97
152
|
else
|
98
|
-
|
153
|
+
v = (1 == args.length ? args.first : args)
|
154
|
+
if __defaults_mode
|
155
|
+
@__defaults[#{m.inspect}] = v
|
156
|
+
else
|
157
|
+
@__values[#{m.inspect}] = v
|
158
|
+
end
|
99
159
|
end
|
100
160
|
|
101
|
-
return
|
102
|
-
return @#{m}.respond_to?(:call) ? @#{m}.call : @#{m}
|
161
|
+
return self.#{m}
|
103
162
|
end
|
104
163
|
CODE
|
105
164
|
|
106
165
|
__desc[m] = nil unless __desc.has_key? m
|
107
166
|
|
108
|
-
default = (args.empty? and !block) ? Loquacious::Undefined.new(m.to_s) : nil
|
167
|
+
default = ((__defaults_mode or args.empty?) and !block) ? Loquacious::Undefined.new(m.to_s) : nil
|
109
168
|
self.__send("#{m}=", default)
|
110
169
|
self.__send("#{m}", *args, &block)
|
111
170
|
end
|
@@ -123,9 +182,9 @@ module Loquacious
|
|
123
182
|
# Evaluate the given _code_ string in the context of this object's
|
124
183
|
# eigenclass (singleton class).
|
125
184
|
#
|
126
|
-
def __eigenclass_eval( code )
|
185
|
+
def __eigenclass_eval( code, file, line )
|
127
186
|
ec = class << self; self; end
|
128
|
-
ec.module_eval code
|
187
|
+
ec.module_eval code, file, line
|
129
188
|
rescue StandardError
|
130
189
|
Kernel.raise Error, "cannot evalutate this code:\n#{code}\n"
|
131
190
|
end
|
@@ -141,14 +200,26 @@ module Loquacious
|
|
141
200
|
return self if other.equal? self
|
142
201
|
Kernel.raise Error, "can only merge another Configuration" unless other.kind_of?(Configuration)
|
143
202
|
|
203
|
+
other_values = other.__values
|
204
|
+
other_defaults = other.__defaults
|
205
|
+
|
144
206
|
other.__desc.each do |key,desc|
|
145
|
-
value =
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
207
|
+
value = @__values[key]
|
208
|
+
other_value = other_values[key]
|
209
|
+
|
210
|
+
if value.kind_of?(Configuration) and other_value.kind_of?(Configuration)
|
211
|
+
value.merge! other_value
|
212
|
+
elsif !other_value.kind_of?(Loquacious::Undefined)
|
213
|
+
@__values[key] = other_value
|
214
|
+
end
|
215
|
+
|
216
|
+
if other_defaults.has_key? key
|
217
|
+
@__defaults[key] = other_defaults[key]
|
218
|
+
end
|
219
|
+
|
220
|
+
if desc
|
221
|
+
__desc[key] = desc
|
150
222
|
end
|
151
|
-
__desc[key] = desc
|
152
223
|
end
|
153
224
|
|
154
225
|
self
|
@@ -192,7 +263,7 @@ module Loquacious
|
|
192
263
|
end
|
193
264
|
Kernel.methods.each do |m|
|
194
265
|
next if m[::Loquacious::KEEPERS]
|
195
|
-
module_eval <<-CODE
|
266
|
+
module_eval <<-CODE, __FILE__, __LINE__+1
|
196
267
|
def #{m}( *args, &block )
|
197
268
|
self.method_missing('#{m}', *args, &block)
|
198
269
|
end
|
@@ -203,8 +274,8 @@ module Loquacious
|
|
203
274
|
# Create a new DSL and evaluate the given _block_ in the context of
|
204
275
|
# the DSL. Returns a newly created configuration object.
|
205
276
|
#
|
206
|
-
def self.evaluate( &block )
|
207
|
-
dsl = self.new(&block)
|
277
|
+
def self.evaluate( opts = {}, &block )
|
278
|
+
dsl = self.new(opts, &block)
|
208
279
|
dsl.__config
|
209
280
|
end
|
210
281
|
|
@@ -214,10 +285,13 @@ module Loquacious
|
|
214
285
|
# Creates a new DSL and evaluates the given _block_ in the context of
|
215
286
|
# the DSL.
|
216
287
|
#
|
217
|
-
def initialize(
|
288
|
+
def initialize( opts = {}, &block )
|
218
289
|
@description = nil
|
219
|
-
@__config = config || Configuration.new
|
290
|
+
@__config = opts[:config] || Configuration.new
|
291
|
+
@__config.__defaults_mode = opts.key?(:defaults_mode) ? opts[:defaults_mode] : false
|
220
292
|
instance_eval(&block)
|
293
|
+
ensure
|
294
|
+
@__config.__defaults_mode = false
|
221
295
|
end
|
222
296
|
|
223
297
|
# Dynamically adds the given _method_ to the configuration as an
|
data/spec/configuration_spec.rb
CHANGED
@@ -2,10 +2,6 @@
|
|
2
2
|
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
3
3
|
|
4
4
|
describe Loquacious::Configuration do
|
5
|
-
before(:all) do
|
6
|
-
@respond_to = Object.instance_method(:respond_to?)
|
7
|
-
end
|
8
|
-
|
9
5
|
before(:each) do
|
10
6
|
@obj = Loquacious::Configuration.new
|
11
7
|
end
|
@@ -30,13 +26,12 @@ describe Loquacious::Configuration do
|
|
30
26
|
end
|
31
27
|
|
32
28
|
it 'should deine attribute accessors when first used' do
|
33
|
-
|
34
|
-
|
35
|
-
m.call(:foo=).should == false
|
29
|
+
@obj.respond_to?(:foo).should == false
|
30
|
+
@obj.respond_to?(:foo=).should == false
|
36
31
|
|
37
32
|
@obj.foo
|
38
|
-
|
39
|
-
|
33
|
+
@obj.respond_to?(:foo).should == true
|
34
|
+
@obj.respond_to?(:foo=).should == true
|
40
35
|
end
|
41
36
|
|
42
37
|
it 'should provide a hash object for storing method descriptions' do
|
@@ -97,6 +92,7 @@ describe Loquacious::Configuration do
|
|
97
92
|
|
98
93
|
it 'should not be affected by loading other modules like timeout' do
|
99
94
|
require 'timeout'
|
95
|
+
Loquacious.remove :timeout
|
100
96
|
cfg = Loquacious::Configuration.new {
|
101
97
|
timeout 10
|
102
98
|
foo 'bar'
|
@@ -135,7 +131,7 @@ describe Loquacious::Configuration do
|
|
135
131
|
obj.first.should == 'foo'
|
136
132
|
obj.second.bar.should be_nil
|
137
133
|
|
138
|
-
Loquacious::Configuration::DSL.
|
134
|
+
Loquacious::Configuration::DSL.evaluate(:config => obj) {
|
139
135
|
first 'bar'
|
140
136
|
second.bar 'no longer nil'
|
141
137
|
}
|
@@ -161,7 +157,7 @@ describe Loquacious::Configuration do
|
|
161
157
|
obj.__desc[:second].should == 'the second value'
|
162
158
|
obj.second.__desc[:bar].should == 'time to go drinking'
|
163
159
|
|
164
|
-
Loquacious::Configuration::DSL.
|
160
|
+
Loquacious::Configuration::DSL.evaluate(:config => obj) {
|
165
161
|
first 'bar'
|
166
162
|
second.bar 'no longer nil'
|
167
163
|
}
|
@@ -275,8 +271,149 @@ describe Loquacious::Configuration do
|
|
275
271
|
other.__desc[:first].should == " This is the first thing we are defining in this config.\n It has a multiline comment."
|
276
272
|
other.__desc[:second].should == "This is a short explanation\n\nExample:\n do this then that\n followed by this line"
|
277
273
|
end
|
274
|
+
end
|
275
|
+
|
276
|
+
# -----------------------------------------------------------------------
|
277
|
+
describe 'when working with defaults' do
|
278
|
+
before :each do
|
279
|
+
Loquacious::Configuration.instance_variable_get(:@table).clear
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'returns default values when no other value exists' do
|
283
|
+
Loquacious::Configuration.defaults_for('test') {
|
284
|
+
first 'foo', :desc => 'the first value'
|
285
|
+
desc 'the second value'
|
286
|
+
second {
|
287
|
+
bar nil, :desc => 'time to go drinking'
|
288
|
+
}
|
289
|
+
}
|
290
|
+
|
291
|
+
c = Loquacious::Configuration.for 'test'
|
292
|
+
c.first.should == 'foo'
|
293
|
+
c.second.bar.should be_nil
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'does not overwrite existing configuration values' do
|
297
|
+
c = Loquacious::Configuration.for('test') {
|
298
|
+
first 1
|
299
|
+
thrid 3
|
300
|
+
}
|
301
|
+
|
302
|
+
Loquacious::Configuration.defaults_for('test') {
|
303
|
+
first 'foo', :desc => 'the first value'
|
304
|
+
desc 'the second value'
|
305
|
+
second {
|
306
|
+
bar nil, :desc => 'time to go drinking'
|
307
|
+
}
|
308
|
+
}
|
309
|
+
|
310
|
+
c.first.should == 1
|
311
|
+
c.third.should == 3
|
312
|
+
c.second.bar.should be_nil
|
313
|
+
|
314
|
+
c.__desc[:first].should == 'the first value'
|
315
|
+
c.__desc[:second].should == 'the second value'
|
316
|
+
c.second.__desc[:bar].should == 'time to go drinking'
|
317
|
+
c.__desc[:thrid].should be_nil
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'does not overwrite nested configuration values' do
|
321
|
+
c = Loquacious::Configuration.for('test') {
|
322
|
+
first 1
|
323
|
+
second {
|
324
|
+
bar 'pub'
|
325
|
+
baz {
|
326
|
+
buz 'random text'
|
327
|
+
boo 'who'
|
328
|
+
}
|
329
|
+
}
|
330
|
+
thrid 3
|
331
|
+
}
|
278
332
|
|
333
|
+
Loquacious::Configuration.defaults_for('test') {
|
334
|
+
first 'foo', :desc => 'the first value'
|
335
|
+
desc 'the second value'
|
336
|
+
second {
|
337
|
+
bar 'h-bar', :desc => 'time to go drinking'
|
338
|
+
desc 'getting weird'
|
339
|
+
baz {
|
340
|
+
buz 'buz', :desc => 'post drinking feeling'
|
341
|
+
boo nil, :desc => 'no need to cry about it'
|
342
|
+
}
|
343
|
+
}
|
344
|
+
}
|
345
|
+
|
346
|
+
c.first.should == 1
|
347
|
+
c.third.should == 3
|
348
|
+
c.second.bar.should == 'pub'
|
349
|
+
c.second.baz.buz.should == 'random text'
|
350
|
+
c.second.baz.boo.should == 'who'
|
351
|
+
|
352
|
+
c.second.bar = Loquacious::Undefined.new('second.bar')
|
353
|
+
c.second.bar.should == 'h-bar'
|
354
|
+
|
355
|
+
c.__desc[:first].should == 'the first value'
|
356
|
+
c.__desc[:second].should == 'the second value'
|
357
|
+
c.second.__desc[:bar].should == 'time to go drinking'
|
358
|
+
c.second.__desc[:baz].should == 'getting weird'
|
359
|
+
c.second.baz.__desc[:buz].should == 'post drinking feeling'
|
360
|
+
c.second.baz.__desc[:boo].should == 'no need to cry about it'
|
361
|
+
c.__desc[:thrid].should be_nil
|
362
|
+
end
|
363
|
+
|
364
|
+
it 'supports differing default type' do
|
365
|
+
c = Loquacious::Configuration.for('test') {
|
366
|
+
first 1
|
367
|
+
second {
|
368
|
+
bar 'pub'
|
369
|
+
desc 'overwrite me'
|
370
|
+
baz {
|
371
|
+
buz 'random text'
|
372
|
+
boo 'who'
|
373
|
+
}
|
374
|
+
}
|
375
|
+
thrid 3
|
376
|
+
}
|
377
|
+
|
378
|
+
Loquacious::Configuration.defaults_for('test') {
|
379
|
+
first 'foo', :desc => 'the first value'
|
380
|
+
desc 'the second value'
|
381
|
+
second {
|
382
|
+
bar 'h-bar', :desc => 'time to go drinking'
|
383
|
+
baz nil, :desc => 'deprecated'
|
384
|
+
}
|
385
|
+
}
|
386
|
+
|
387
|
+
c.second.baz.buz.should == 'random text'
|
388
|
+
c.second.baz.boo.should == 'who'
|
389
|
+
|
390
|
+
c.second.baz = Loquacious::Undefined.new('second.bar')
|
391
|
+
c.second.baz.should be_nil
|
392
|
+
c.second.__desc[:baz].should == 'deprecated'
|
393
|
+
end
|
394
|
+
|
395
|
+
it 'properly handles Proc default values' do
|
396
|
+
c = Loquacious::Configuration.for('test') {
|
397
|
+
first 1
|
398
|
+
second {
|
399
|
+
bar 'pub'
|
400
|
+
}
|
401
|
+
thrid 3
|
402
|
+
}
|
403
|
+
|
404
|
+
Loquacious::Configuration.defaults_for('test') {
|
405
|
+
first 'foo', :desc => 'the first value'
|
406
|
+
desc 'the second value'
|
407
|
+
second {
|
408
|
+
bar 'h-bar', :desc => 'time to go drinking'
|
409
|
+
baz(Proc.new { c.third * 12 }, :desc => 'proc will be evaluated')
|
410
|
+
}
|
411
|
+
}
|
412
|
+
|
413
|
+
c.second.baz.should == 36
|
414
|
+
c.second.__desc[:baz].should == 'proc will be evaluated'
|
415
|
+
end
|
279
416
|
end
|
417
|
+
|
280
418
|
end
|
281
419
|
|
282
|
-
# EOF
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
require File.expand_path('../lib/loquacious', File.dirname(__FILE__))
|
3
3
|
|
4
|
-
|
4
|
+
RSpec.configure do |config|
|
5
5
|
# == Mock Framework
|
6
6
|
#
|
7
7
|
# RSpec uses it's own mocking framework by default. If you prefer to
|
@@ -59,4 +59,3 @@ class StringIO
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
# EOF
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.8.0
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loquacious
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 55
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
version: 1.8.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tim Pease
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-06-03 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -24,14 +24,13 @@ dependencies:
|
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 15
|
30
30
|
segments:
|
31
|
-
-
|
32
|
-
-
|
33
|
-
|
34
|
-
version: 1.3.1
|
31
|
+
- 2
|
32
|
+
- 6
|
33
|
+
version: "2.6"
|
35
34
|
type: :development
|
36
35
|
version_requirements: *id001
|
37
36
|
description: |-
|
@@ -108,7 +107,7 @@ files:
|
|
108
107
|
- spec/string_spec.rb
|
109
108
|
- version.txt
|
110
109
|
has_rdoc: true
|
111
|
-
homepage: http://
|
110
|
+
homepage: http://rubygems.org/gems/loquacious
|
112
111
|
licenses: []
|
113
112
|
|
114
113
|
post_install_message:
|