loquacious 1.5.2 → 1.6.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 +17 -17
- data/lib/loquacious.rb +1 -0
- data/lib/loquacious/configuration.rb +4 -2
- data/lib/loquacious/configuration/iterator.rb +5 -1
- data/lib/loquacious/undefined.rb +86 -0
- data/spec/spec_helper.rb +4 -0
- data/version.txt +1 -1
- metadata +5 -4
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -58,31 +58,31 @@ they can appear above the attribute and value on their own line.
|
|
58
58
|
# A simple example that configures three options (a b c) along with
|
59
59
|
# descriptions for each option. The descriptions along with the
|
60
60
|
# values for the configuration options are printed to the terminal.
|
61
|
-
|
61
|
+
|
62
62
|
require 'loquacious'
|
63
63
|
include Loquacious
|
64
|
-
|
64
|
+
|
65
65
|
Configuration.for(:simple) {
|
66
66
|
desc 'Your first configuration option'
|
67
67
|
a "value for 'a'"
|
68
|
-
|
68
|
+
|
69
69
|
desc 'To be or not to be'
|
70
70
|
b "William Shakespeare"
|
71
|
-
|
71
|
+
|
72
72
|
desc 'The underpinings of Ruby'
|
73
73
|
c 42
|
74
74
|
}
|
75
|
-
|
75
|
+
|
76
76
|
help = Configuration.help_for :simple
|
77
77
|
help.show :values => true
|
78
78
|
|
79
79
|
====== output ======
|
80
80
|
Your first configuration option
|
81
81
|
- a => "value for 'a'"
|
82
|
-
|
82
|
+
|
83
83
|
To be or not to be
|
84
84
|
- b => "William Shakespeare"
|
85
|
-
|
85
|
+
|
86
86
|
The underpinings of Ruby
|
87
87
|
- c => 42
|
88
88
|
|
@@ -138,25 +138,25 @@ they can appear above the attribute and value on their own line.
|
|
138
138
|
====== output ======
|
139
139
|
Configuration options for ActiveRecord::Base.
|
140
140
|
- active_record
|
141
|
-
|
141
|
+
|
142
142
|
Determines whether to use ANSI codes to colorize the logging statements committed
|
143
143
|
by the connection adapter. These colors make it much easier to overview things
|
144
144
|
during debugging (when used through a reader like +tail+ and on a black background),
|
145
145
|
but may complicate matters if you use software like syslog. This is true, by default.
|
146
146
|
- active_record.colorize_logging => true
|
147
|
-
|
147
|
+
|
148
148
|
Determines whether to use Time.local (using :local) or Time.utc (using :utc)
|
149
149
|
when pulling dates and times from the database. This is set to :local by default.
|
150
150
|
- active_record.default_timezone => :local
|
151
|
-
|
151
|
+
|
152
152
|
The log level to use for the default Rails logger. In production mode,
|
153
153
|
this defaults to :info. In development mode, it defaults to :debug.
|
154
154
|
- log_level => :info
|
155
|
-
|
155
|
+
|
156
156
|
The path to the log file to use. Defaults to log/#{environment}.log
|
157
157
|
(e.g. log/development.log or log/production.log).
|
158
158
|
- log_path => "log/development.log"
|
159
|
-
|
159
|
+
|
160
160
|
The application's base directory.
|
161
161
|
- root_path => "."
|
162
162
|
|
@@ -195,17 +195,17 @@ they can appear above the attribute and value on their own line.
|
|
195
195
|
====== output ======
|
196
196
|
The log level to use for the default Rails logger. In production mode,
|
197
197
|
this defaults to :info. In development mode, it defaults to :debug.
|
198
|
-
|
198
|
+
|
199
199
|
config.log_level = 'debug'
|
200
200
|
config.log_level = :warn
|
201
|
-
|
201
|
+
|
202
202
|
- log_level => :warn
|
203
|
-
|
203
|
+
|
204
204
|
The path to the log file to use. Defaults to log/#{environment}.log
|
205
205
|
(e.g. log/development.log or log/production.log).
|
206
|
-
|
206
|
+
|
207
207
|
config.log_path = File.join(ROOT, "log", "#{environment}.log
|
208
|
-
|
208
|
+
|
209
209
|
- log_path => "log/development.log"
|
210
210
|
|
211
211
|
== LICENSE:
|
data/lib/loquacious.rb
CHANGED
@@ -110,7 +110,9 @@ module Loquacious
|
|
110
110
|
CODE
|
111
111
|
|
112
112
|
__desc[m]
|
113
|
-
|
113
|
+
|
114
|
+
default = (args.empty? and !block) ? Loquacious::Undefined.new(m.to_s) : nil
|
115
|
+
self.__send("#{m}=", default)
|
114
116
|
self.__send("#{m}", *args, &block)
|
115
117
|
end
|
116
118
|
|
@@ -180,6 +182,7 @@ module Loquacious
|
|
180
182
|
self.__send(key, value)
|
181
183
|
end
|
182
184
|
|
185
|
+
|
183
186
|
# Implementation of a doman specific language for creating configuration
|
184
187
|
# objects. Blocks of code are evaluted by the DSL which returns a new
|
185
188
|
# configuration object.
|
@@ -258,4 +261,3 @@ module Loquacious
|
|
258
261
|
end # class Configuration
|
259
262
|
end # module Loquacious
|
260
263
|
|
261
|
-
# EOF
|
@@ -144,9 +144,13 @@ class Loquacious::Configuration
|
|
144
144
|
# single configuration attribute.
|
145
145
|
#
|
146
146
|
Node = Struct.new( :config, :name, :desc, :key ) {
|
147
|
-
def obj() config.__send__(key); end
|
148
147
|
def config?() obj.kind_of? ::Loquacious::Configuration; end
|
148
|
+
def obj()
|
149
|
+
o = config.__send__(key)
|
150
|
+
o.kind_of?(::Loquacious::Undefined) ? nil : o
|
151
|
+
end
|
149
152
|
}
|
150
153
|
|
151
154
|
end # class Iterator
|
152
155
|
end # class Loquacious::Configuration
|
156
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
|
2
|
+
module Loquacious
|
3
|
+
|
4
|
+
# Represents an undefined configuration value. An undefined value is
|
5
|
+
# assigned to each configuration propery by default. Any method can be
|
6
|
+
# invoked on an undefined value, and a warning message will be printed to
|
7
|
+
# the IO stream (defaulting to $stderr).
|
8
|
+
#
|
9
|
+
# The purpose of this class is to provide the user with a helpful message
|
10
|
+
# that the configuration values they are trying to use have not been setup
|
11
|
+
# correctly.
|
12
|
+
#
|
13
|
+
class Undefined
|
14
|
+
|
15
|
+
Keepers = %r/^__|^object_id$|^initialize$|^kind_of\?$|^respond_to\?$|^call$/
|
16
|
+
instance_methods(true).each do |m|
|
17
|
+
next if m[Keepers]
|
18
|
+
undef_method m
|
19
|
+
end
|
20
|
+
private_instance_methods(true).each do |m|
|
21
|
+
next if m[Keepers]
|
22
|
+
undef_method m
|
23
|
+
end
|
24
|
+
Kernel.methods.each do |m|
|
25
|
+
next if m[Keepers]
|
26
|
+
module_eval <<-CODE
|
27
|
+
def #{m}( *args, &block )
|
28
|
+
self.method_missing('#{m}', *args, &block)
|
29
|
+
end
|
30
|
+
CODE
|
31
|
+
end
|
32
|
+
|
33
|
+
@io = $stderr
|
34
|
+
@first_time = true
|
35
|
+
|
36
|
+
class << self
|
37
|
+
attr_accessor :io
|
38
|
+
|
39
|
+
# Write a warning message to the Undefined class IO stream. By default,
|
40
|
+
# this IO stream is set to the Ruby $stderr output.
|
41
|
+
#
|
42
|
+
def warn( key )
|
43
|
+
if @first_time
|
44
|
+
@io.puts <<-__
|
45
|
+
---------------------------------------------------------------------------
|
46
|
+
The Loquacious configuration system has detected that one or moe
|
47
|
+
settings have an undefined value. An attempt is being made to reference
|
48
|
+
sub-properties of these undefined settings. Messages will follow containing
|
49
|
+
information about the undefined properties.
|
50
|
+
---------------------------------------------------------------------------
|
51
|
+
__
|
52
|
+
@first_time = false
|
53
|
+
end
|
54
|
+
|
55
|
+
@io.puts "Access to undefined value #{key.first.inspect}: #{key.join('.')}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Creates a new undefined value returned from the lookup _key_ in some
|
60
|
+
# configuration object. The _key_ is used to alert the user where the
|
61
|
+
# undefined value came from.
|
62
|
+
#
|
63
|
+
def initialize( key )
|
64
|
+
@key = Kernel.Array(key)
|
65
|
+
end
|
66
|
+
|
67
|
+
# An undefined value acts like a +nil+ in that it has no value of its own.
|
68
|
+
# This method always returns +true+.
|
69
|
+
#
|
70
|
+
def nil?() true; end
|
71
|
+
|
72
|
+
# For every method invoked on an undefined object, generate a warning
|
73
|
+
# message describing the undefined value and the method that was called.
|
74
|
+
#
|
75
|
+
# Returns a new undefined object with the most recent method included in
|
76
|
+
# the key name.
|
77
|
+
#
|
78
|
+
def method_missing( method, *args, &block )
|
79
|
+
key = @key.dup << method.to_s
|
80
|
+
Undefined.warn key
|
81
|
+
return Undefined.new key
|
82
|
+
end
|
83
|
+
|
84
|
+
end # class Undefined
|
85
|
+
end # module Loquacious
|
86
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -12,7 +12,11 @@ Spec::Runner.configure do |config|
|
|
12
12
|
# config.mock_with :flexmock
|
13
13
|
# config.mock_with :rr
|
14
14
|
|
15
|
+
Loquacious::Undefined.io = StringIO.new
|
16
|
+
|
15
17
|
config.before :each do
|
18
|
+
Loquacious::Undefined.io.clear
|
19
|
+
|
16
20
|
table = Loquacious::Configuration.instance_variable_get(:@table)
|
17
21
|
table.clear
|
18
22
|
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.6.0
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
7
|
+
- 6
|
8
|
+
- 0
|
9
|
+
version: 1.6.0
|
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-05-18 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/loquacious/configuration/help.rb
|
97
97
|
- lib/loquacious/configuration/iterator.rb
|
98
98
|
- lib/loquacious/core_ext/string.rb
|
99
|
+
- lib/loquacious/undefined.rb
|
99
100
|
- spec/configuration_spec.rb
|
100
101
|
- spec/help_spec.rb
|
101
102
|
- spec/iterator_spec.rb
|