TwP-loquacious 1.0.0

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 ADDED
@@ -0,0 +1,4 @@
1
+ == 1.0.0 / 2009-04-04
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
data/README.rdoc ADDED
@@ -0,0 +1,234 @@
1
+ = Loquacious
2
+ by Tim Pease
3
+ http://codeforpeople.rubyforge.org/loquacious
4
+
5
+ == DESCRIPTION:
6
+
7
+ Descriptive configuration files for Ruby written in Ruby.
8
+
9
+ Loquacious provides a very open configuration system written in ruby and
10
+ descriptions for each configuration attribute. The attributes and descriptions
11
+ can be iterated over allowing for helpful information about those attributes to
12
+ be displayed to the user.
13
+
14
+ In the simple case we have a file something like
15
+
16
+ Loquacious.configuration_for('app') {
17
+ name 'value', :desc => "Defines the name"
18
+ foo 'bar', :desc => "FooBar"
19
+ id 42, :desc => "Ara T. Howard"
20
+ }
21
+
22
+ Which can be loaded via the standard Ruby loading mechanisms
23
+
24
+ Kernel.load 'config/app.rb'
25
+
26
+ The attributes and their descriptions can be printed by using a Help object
27
+
28
+ help = Loquacious.help_for('app')
29
+ help.show :values => true # show the values for the attributes, too
30
+
31
+ Descriptions are optional, and configurations can be nested arbitrarily deep.
32
+
33
+ Loquacious.configuration_for('nested') {
34
+ desc "The outermost level"
35
+ a {
36
+ desc "One more level in"
37
+ b {
38
+ desc "Finally, a real value"
39
+ c 'value'
40
+ }
41
+ }
42
+ }
43
+
44
+ config = Loquacious.configuration_for('nested')
45
+
46
+ p config.a.b.c #=> "value"
47
+
48
+ And as you can see, descriptions can either be given inline after the value or
49
+ they can appear above the attribute and value on their own line.
50
+
51
+ == INSTALL:
52
+
53
+ * sudo gem install loquacious
54
+
55
+ == EXAMPLES:
56
+
57
+ ==== example/simple.rb
58
+ # A simple example that configures three options (a b c) along with
59
+ # descriptions for each option. The descriptions along with the
60
+ # values for the configuration options are printed to the terminal.
61
+
62
+ require 'loquacious'
63
+ include Loquacious
64
+
65
+ Configuration.for(:simple) {
66
+ desc 'Your first configuration option'
67
+ a "value for 'a'"
68
+
69
+ desc 'To be or not to be'
70
+ b "William Shakespeare"
71
+
72
+ desc 'The underpinings of Ruby'
73
+ c 42
74
+ }
75
+
76
+ help = Configuration.help_for :simple
77
+ help.show :values => true
78
+
79
+ ====== output ======
80
+ Your first configuration option
81
+ - a => "value for 'a'"
82
+
83
+ To be or not to be
84
+ - b => "William Shakespeare"
85
+
86
+ The underpinings of Ruby
87
+ - c => 42
88
+
89
+ ==== examples/nested.rb
90
+ # Here we show how to used nested configuration options by taking a subset
91
+ # of some common Rails configuration options. Also, descriptions can be give
92
+ # before the option or they can be given inline using Ruby hash notation. If
93
+ # both are present, then the inline description takes precedence.
94
+ #
95
+ # Multiline descriptions are provided using Ruby heredocs. Leading
96
+ # whitespace is stripped and line breaks are preserved when descriptions
97
+ # are printed using the help object.
98
+
99
+ require 'loquacious'
100
+ include Loquacious
101
+
102
+ Configuration.for(:nested) {
103
+ root_path '.', :desc => "The application's base directory."
104
+
105
+ desc "Configuration options for ActiveRecord::Base."
106
+ active_record {
107
+ desc <<-__
108
+ Determines whether to use ANSI codes to colorize the logging statements committed
109
+ by the connection adapter. These colors make it much easier to overview things
110
+ during debugging (when used through a reader like +tail+ and on a black background),
111
+ but may complicate matters if you use software like syslog. This is true, by default.
112
+ __
113
+ colorize_logging true
114
+
115
+ desc <<-__
116
+ Determines whether to use Time.local (using :local) or Time.utc (using :utc)
117
+ when pulling dates and times from the database. This is set to :local by default.
118
+ __
119
+ default_timezone :local
120
+ }
121
+
122
+ desc <<-__
123
+ The log level to use for the default Rails logger. In production mode,
124
+ this defaults to :info. In development mode, it defaults to :debug.
125
+ __
126
+ log_level :info
127
+
128
+ desc <<-__
129
+ The path to the log file to use. Defaults to log/\#{environment}.log
130
+ (e.g. log/development.log or log/production.log).
131
+ __
132
+ log_path 'log/development.log'
133
+ }
134
+
135
+ help = Configuration.help_for :nested
136
+ help.show :values => true
137
+
138
+ ====== output ======
139
+ Configuration options for ActiveRecord::Base.
140
+ - active_record
141
+
142
+ Determines whether to use ANSI codes to colorize the logging statements committed
143
+ by the connection adapter. These colors make it much easier to overview things
144
+ during debugging (when used through a reader like +tail+ and on a black background),
145
+ but may complicate matters if you use software like syslog. This is true, by default.
146
+ - active_record.colorize_logging => true
147
+
148
+ Determines whether to use Time.local (using :local) or Time.utc (using :utc)
149
+ when pulling dates and times from the database. This is set to :local by default.
150
+ - active_record.default_timezone => :local
151
+
152
+ The log level to use for the default Rails logger. In production mode,
153
+ this defaults to :info. In development mode, it defaults to :debug.
154
+ - log_level => :info
155
+
156
+ The path to the log file to use. Defaults to log/#{environment}.log
157
+ (e.g. log/development.log or log/production.log).
158
+ - log_path => "log/development.log"
159
+
160
+ The application's base directory.
161
+ - root_path => "."
162
+
163
+ ==== examples/gutters.rb
164
+ # Using Ruby heredocs for descriptions, the Loquacious configuration will
165
+ # strip out leading whitespace but preserve line breaks. Gutter lines can be
166
+ # used to mark where leading whitespace should be preserved. This is useful
167
+ # is you need to provide example code in your descriptions.
168
+
169
+ require 'loquacious'
170
+ include Loquacious
171
+
172
+ Configuration.for(:gutters) {
173
+ desc <<-__
174
+ The path to the log file to use. Defaults to log/\#{environment}.log
175
+ (e.g. log/development.log or log/production.log).
176
+ |
177
+ | config.log_path = File.join(ROOT, "log", "\#{environment}.log
178
+ |
179
+ __
180
+ log_path "log/development.log"
181
+
182
+ log_level :warn, :desc => <<-__
183
+ |The log level to use for the default Rails logger. In production mode,
184
+ |this defaults to :info. In development mode, it defaults to :debug.
185
+ |
186
+ | config.log_level = 'debug'
187
+ | config.log_level = :warn
188
+ |
189
+ __
190
+ }
191
+
192
+ help = Configuration.help_for :gutters
193
+ help.show :values => true
194
+
195
+ ====== output ======
196
+ The log level to use for the default Rails logger. In production mode,
197
+ this defaults to :info. In development mode, it defaults to :debug.
198
+
199
+ config.log_level = 'debug'
200
+ config.log_level = :warn
201
+
202
+ - log_level => :warn
203
+
204
+ The path to the log file to use. Defaults to log/#{environment}.log
205
+ (e.g. log/development.log or log/production.log).
206
+
207
+ config.log_path = File.join(ROOT, "log", "#{environment}.log
208
+
209
+ - log_path => "log/development.log"
210
+
211
+ == LICENSE:
212
+
213
+ (The MIT License)
214
+
215
+ Copyright (c) 2009
216
+
217
+ Permission is hereby granted, free of charge, to any person obtaining
218
+ a copy of this software and associated documentation files (the
219
+ 'Software'), to deal in the Software without restriction, including
220
+ without limitation the rights to use, copy, modify, merge, publish,
221
+ distribute, sublicense, and/or sell copies of the Software, and to
222
+ permit persons to whom the Software is furnished to do so, subject to
223
+ the following conditions:
224
+
225
+ The above copyright notice and this permission notice shall be
226
+ included in all copies or substantial portions of the Software.
227
+
228
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
229
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
230
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
231
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
232
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
233
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
234
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ # Look in the tasks/setup.rb file for the various options that can be
2
+ # configured in this Rakefile. The .rake files in the tasks directory
3
+ # are where the options are used.
4
+
5
+ begin
6
+ require 'bones'
7
+ Bones.setup
8
+ rescue LoadError
9
+ begin
10
+ load 'tasks/setup.rb'
11
+ rescue LoadError
12
+ raise RuntimeError, '### please install the "bones" gem ###'
13
+ end
14
+ end
15
+
16
+ ensure_in_path 'lib'
17
+ require 'loquacious'
18
+
19
+ task :default => 'spec:specdoc'
20
+
21
+ PROJ.name = 'loquacious'
22
+ PROJ.authors = 'Tim Pease'
23
+ PROJ.email = 'tim.pease@gmail.com'
24
+ PROJ.url = 'http://codeforpeople.rubyforge.org/loquacious'
25
+ PROJ.version = Loquacious::VERSION
26
+ PROJ.readme_file = 'README.rdoc'
27
+ PROJ.ignore_file = '.gitignore'
28
+ PROJ.rubyforge.name = 'codeforpeople'
29
+
30
+ PROJ.spec.opts << '--color'
31
+ PROJ.ruby_opts = %w[-W0]
32
+
33
+ PROJ.ann.email[:server] = 'smtp.gmail.com'
34
+ PROJ.ann.email[:port] = 587
35
+ PROJ.ann.email[:from] = 'Tim Pease'
36
+
37
+ task 'ann:prereqs' do
38
+ PROJ.name = 'Loquacious'
39
+ end
40
+
41
+ depend_on 'rspec'
42
+
43
+ # EOF
@@ -0,0 +1,30 @@
1
+ # Using Ruby heredocs for descriptions, the Loquacious configuration will
2
+ # strip out leading whitespace but preserve line breaks. Gutter lines can be
3
+ # used to mark where leading whitespace should be preserved. This is useful
4
+ # is you need to provide example code in your descriptions.
5
+
6
+ require 'loquacious'
7
+ include Loquacious
8
+
9
+ Configuration.for(:gutters) {
10
+ desc <<-__
11
+ The path to the log file to use. Defaults to log/\#{environment}.log
12
+ (e.g. log/development.log or log/production.log).
13
+ |
14
+ | config.log_path = File.join(ROOT, "log", "\#{environment}.log
15
+ |
16
+ __
17
+ log_path "log/development.log"
18
+
19
+ log_level :warn, :desc => <<-__
20
+ |The log level to use for the default Rails logger. In production mode,
21
+ |this defaults to :info. In development mode, it defaults to :debug.
22
+ |
23
+ | config.log_level = 'debug'
24
+ | config.log_level = :warn
25
+ |
26
+ __
27
+ }
28
+
29
+ help = Configuration.help_for :gutters
30
+ help.show :values => true
@@ -0,0 +1,47 @@
1
+ # Here we show how to used nested configuration options by taking a subset
2
+ # of some common Rails configuration options. Also, descriptions can be give
3
+ # before the option or they can be given inline using Ruby hash notation. If
4
+ # both are present, then the inline description takes precedence.
5
+ #
6
+ # Multiline descriptions are provided using Ruby heredocs. Leading
7
+ # whitespace is stripped and line breaks are preserved when descriptions
8
+ # are printed using the help object.
9
+
10
+ require 'loquacious'
11
+ include Loquacious
12
+
13
+ Configuration.for(:nested) {
14
+ root_path '.', :desc => "The application's base directory."
15
+
16
+ desc "Configuration options for ActiveRecord::Base."
17
+ active_record {
18
+ desc <<-__
19
+ Determines whether to use ANSI codes to colorize the logging statements committed
20
+ by the connection adapter. These colors make it much easier to overview things
21
+ during debugging (when used through a reader like +tail+ and on a black background),
22
+ but may complicate matters if you use software like syslog. This is true, by default.
23
+ __
24
+ colorize_logging true
25
+
26
+ desc <<-__
27
+ Determines whether to use Time.local (using :local) or Time.utc (using :utc)
28
+ when pulling dates and times from the database. This is set to :local by default.
29
+ __
30
+ default_timezone :local
31
+ }
32
+
33
+ desc <<-__
34
+ The log level to use for the default Rails logger. In production mode,
35
+ this defaults to :info. In development mode, it defaults to :debug.
36
+ __
37
+ log_level :info
38
+
39
+ desc <<-__
40
+ The path to the log file to use. Defaults to log/\#{environment}.log
41
+ (e.g. log/development.log or log/production.log).
42
+ __
43
+ log_path 'log/development.log'
44
+ }
45
+
46
+ help = Configuration.help_for :nested
47
+ help.show :values => true
@@ -0,0 +1,20 @@
1
+ # A simple example that configures three options (a b c) along with
2
+ # descriptions for each option. The descriptions along with the
3
+ # values for the configuration options are printed to the terminal.
4
+
5
+ require 'loquacious'
6
+ include Loquacious
7
+
8
+ Configuration.for(:simple) {
9
+ desc 'Your first configuration option'
10
+ a "value for 'a'"
11
+
12
+ desc 'To be or not to be'
13
+ b "William Shakespeare"
14
+
15
+ desc 'The underpinings of Ruby'
16
+ c 42
17
+ }
18
+
19
+ help = Configuration.help_for :simple
20
+ help.show :values => true
data/lib/loquacious.rb ADDED
@@ -0,0 +1,75 @@
1
+
2
+ module Loquacious
3
+
4
+ # :stopdoc:
5
+ VERSION = '1.0.0'
6
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
+ # :startdoc:
9
+
10
+ class << self
11
+
12
+ # Returns the configuration associated with the given _name_. If a
13
+ # _block_ is given, then it will be used to create the configuration.
14
+ #
15
+ # The same _name_ can be used multiple times with different
16
+ # configuration blocks. Each different block will be used to add to the
17
+ # configuration; i.e. the configurations are additive.
18
+ #
19
+ def configuration_for( name, &block )
20
+ ::Loquacious::Configuration.for(name, &block)
21
+ end
22
+ alias :configuration :configuration_for
23
+ alias :config_for :configuration_for
24
+ alias :config :configuration_for
25
+
26
+ # Returns a Help instance for the configuration associated with the
27
+ # given _name_. See the Help#initialize method for the options that
28
+ # can be used with this method.
29
+ #
30
+ def help_for( name, opts = {} )
31
+ ::Loquacious::Configuration.help_for(name, opts)
32
+ end
33
+ alias :help :help_for
34
+
35
+ # Returns the version string for the library.
36
+ #
37
+ def version
38
+ VERSION
39
+ end
40
+
41
+ # Returns the library path for the module. If any arguments are given,
42
+ # they will be joined to the end of the libray path using
43
+ # <tt>File.join</tt>.
44
+ #
45
+ def libpath( *args )
46
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
47
+ end
48
+
49
+ # Returns the lpath for the module. If any arguments are given, they
50
+ # will be joined to the end of the path using <tt>File.join</tt>.
51
+ #
52
+ def path( *args )
53
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
54
+ end
55
+
56
+ # Utility method used to require all files ending in .rb that lie in the
57
+ # directory below this file that has the same name as the filename
58
+ # passed in. Optionally, a specific _directory_ name can be passed in
59
+ # such that the _filename_ does not have to be equivalent to the
60
+ # directory.
61
+ #
62
+ def require_all_libs_relative_to( fname, dir = nil )
63
+ dir ||= ::File.basename(fname, '.*')
64
+ search_me = ::File.expand_path(
65
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
66
+
67
+ Dir.glob(search_me).sort.each {|rb| require rb}
68
+ end
69
+
70
+ end # class << self
71
+ end # module Loquacious
72
+
73
+ Loquacious.require_all_libs_relative_to(__FILE__)
74
+
75
+ # EOF