configuration 1.2.0 → 1.3.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/README.rdoc +221 -0
- data/Rakefile +170 -40
- data/config/f.rb +12 -0
- data/configuration.gemspec +28 -8
- data/lib/configuration.rb +6 -2
- data/samples/f.rb +11 -0
- metadata +14 -13
- data/README +0 -197
- data/README.erb +0 -69
data/README.rdoc
ADDED
@@ -0,0 +1,221 @@
|
|
1
|
+
= configuration.rb
|
2
|
+
pure ruby scoped configuration files
|
3
|
+
|
4
|
+
== Description
|
5
|
+
configuration.rb provides a mechanism for configuring ruby programs with
|
6
|
+
ruby configuration files. a configuration.rb file, for example
|
7
|
+
'config/app.rb', can be written simply as
|
8
|
+
|
9
|
+
Configuration.for('app') {
|
10
|
+
key 'value'
|
11
|
+
foo 'bar'
|
12
|
+
port 42
|
13
|
+
}
|
14
|
+
|
15
|
+
and loaded via the normal ruby require/load mechanism
|
16
|
+
|
17
|
+
Kernel.load 'config/app.rb'
|
18
|
+
|
19
|
+
or with a slightly augmented loading mechnanism which simply searches an
|
20
|
+
extra set of paths in *addition* to the standard ones
|
21
|
+
|
22
|
+
Configuration.path = %w( config configuration )
|
23
|
+
|
24
|
+
Configuration.load 'app'
|
25
|
+
|
26
|
+
configurations are completely open
|
27
|
+
|
28
|
+
Configuration.for('app') {
|
29
|
+
object_id 'very open'
|
30
|
+
}
|
31
|
+
|
32
|
+
support arbitrarily nested values
|
33
|
+
|
34
|
+
Configuration.for('app') {
|
35
|
+
a { b { c { d 42 } } }
|
36
|
+
}
|
37
|
+
|
38
|
+
c = Configuration.for 'app'
|
39
|
+
|
40
|
+
p c.a.b.c.d #=> 42
|
41
|
+
|
42
|
+
allow POLS scoped lookup of vars
|
43
|
+
|
44
|
+
Configuration.for('config') {
|
45
|
+
outer 'bar'
|
46
|
+
|
47
|
+
inner {
|
48
|
+
value 42
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
c = Configuration.for 'config'
|
53
|
+
|
54
|
+
p c.outer #=> 'bar'
|
55
|
+
p c.inner.value #=> 42
|
56
|
+
p c.inner.outer #=> 'bar'
|
57
|
+
|
58
|
+
allow default values
|
59
|
+
|
60
|
+
default = Configuration.for( 'default' ) {
|
61
|
+
a 1
|
62
|
+
b 2
|
63
|
+
}
|
64
|
+
|
65
|
+
c = Configuration.for( 'config', default ) {
|
66
|
+
a 10
|
67
|
+
}
|
68
|
+
|
69
|
+
p c.a #=> 10
|
70
|
+
p c.b #=> 2
|
71
|
+
|
72
|
+
and not a whole lot else - configuration.rb is s very small library
|
73
|
+
consisting of one file and < 150 loc
|
74
|
+
|
75
|
+
== Samples
|
76
|
+
|
77
|
+
=== samples/a.rb
|
78
|
+
~ > cat samples/a.rb
|
79
|
+
|
80
|
+
#
|
81
|
+
# basic usage is quite, simple, load the config and use it's values. the
|
82
|
+
# config syntax is fairly obvious, i think, but note that it *is* ruby and any
|
83
|
+
# ruby can be included. also note that each config is named, allowing
|
84
|
+
# multiple configs to be places in one file
|
85
|
+
#
|
86
|
+
require 'configuration'
|
87
|
+
|
88
|
+
c = Configuration.load 'a'
|
89
|
+
|
90
|
+
p c.a + c.b - c.c
|
91
|
+
|
92
|
+
~ > ruby samples/a.rb
|
93
|
+
|
94
|
+
42
|
95
|
+
|
96
|
+
|
97
|
+
=== samples/b.rb
|
98
|
+
~ > cat samples/b.rb
|
99
|
+
|
100
|
+
#
|
101
|
+
# configuration.rb supports a very natural nesting syntax. note how values
|
102
|
+
# are scoped in a POLS fashion
|
103
|
+
#
|
104
|
+
require 'configuration'
|
105
|
+
|
106
|
+
c = Configuration.for 'b'
|
107
|
+
|
108
|
+
p c.www.url
|
109
|
+
p c.db.url
|
110
|
+
p c.mail.url
|
111
|
+
|
112
|
+
~ > ruby samples/b.rb
|
113
|
+
|
114
|
+
"http://codeforpeople.com:80"
|
115
|
+
"db://codeforpeople.com:5342"
|
116
|
+
"mail://gmail.com:25"
|
117
|
+
|
118
|
+
|
119
|
+
=== samples/c.rb
|
120
|
+
~ > cat samples/c.rb
|
121
|
+
|
122
|
+
#
|
123
|
+
# configuration.rb let's you keep code very dry.
|
124
|
+
#
|
125
|
+
|
126
|
+
require 'configuration'
|
127
|
+
|
128
|
+
Configuration.load 'c'
|
129
|
+
|
130
|
+
p Configuration.for('development').db
|
131
|
+
p Configuration.for('production').db
|
132
|
+
p Configuration.for('testing').db
|
133
|
+
|
134
|
+
~ > ruby samples/c.rb
|
135
|
+
|
136
|
+
"db/development"
|
137
|
+
"db/production"
|
138
|
+
"db/testing"
|
139
|
+
|
140
|
+
|
141
|
+
=== samples/d.rb
|
142
|
+
~ > cat samples/d.rb
|
143
|
+
|
144
|
+
#
|
145
|
+
# configuration.rb makes use of an external blank slate dsl, this means that
|
146
|
+
# you Configuration objects do, in fact, have all built-in ruby methods such
|
147
|
+
# as #inspect, etc, *unless* you configure over the top of them. the effect
|
148
|
+
# is a configuration object that behaves like a nice ruby object, but which
|
149
|
+
# allows *any* key to be configured
|
150
|
+
#
|
151
|
+
require 'configuration'
|
152
|
+
|
153
|
+
c = Configuration.for 'd'
|
154
|
+
|
155
|
+
p c.object_id
|
156
|
+
p c.inspect
|
157
|
+
p c.p
|
158
|
+
|
159
|
+
~ > ruby samples/d.rb
|
160
|
+
|
161
|
+
config/d.rb:2:in `object_id': wrong number of arguments (1 for 0) (ArgumentError)
|
162
|
+
from config/d.rb:2
|
163
|
+
from ./lib/configuration.rb:159:in `instance_eval'
|
164
|
+
from ./lib/configuration.rb:159:in `call'
|
165
|
+
from ./lib/configuration.rb:159:in `method_missing'
|
166
|
+
from ./lib/configuration.rb:105:in `evaluate'
|
167
|
+
from ./lib/configuration.rb:68:in `initialize'
|
168
|
+
from ./lib/configuration.rb:29:in `new'
|
169
|
+
from ./lib/configuration.rb:29:in `for'
|
170
|
+
from config/d.rb:1
|
171
|
+
from ./lib/configuration.rb:53:in `load'
|
172
|
+
from ./lib/configuration.rb:53:in `load'
|
173
|
+
from ./lib/configuration.rb:31:in `for'
|
174
|
+
from samples/d.rb:10
|
175
|
+
|
176
|
+
|
177
|
+
=== samples/e.rb
|
178
|
+
~ > cat samples/e.rb
|
179
|
+
|
180
|
+
#
|
181
|
+
# configuration.rb uses a totally clean slate dsl for the block. if you need
|
182
|
+
# to access base Object methods you can do this
|
183
|
+
#
|
184
|
+
|
185
|
+
require 'configuration'
|
186
|
+
|
187
|
+
c = Configuration.for 'e'
|
188
|
+
|
189
|
+
p c.foo
|
190
|
+
p c.bar
|
191
|
+
p c.foobar
|
192
|
+
|
193
|
+
~ > ruby samples/e.rb
|
194
|
+
|
195
|
+
42
|
196
|
+
"forty-two"
|
197
|
+
42.0
|
198
|
+
|
199
|
+
=== samples/f.rb
|
200
|
+
~ > cat samples/f.rb
|
201
|
+
|
202
|
+
#
|
203
|
+
# configuration.rb let's you inherit values from another configuration.
|
204
|
+
# Like this, you keep your code very dry.
|
205
|
+
#
|
206
|
+
|
207
|
+
require 'configuration'
|
208
|
+
|
209
|
+
Configuration.load 'f'
|
210
|
+
|
211
|
+
p c.a
|
212
|
+
p c.b
|
213
|
+
|
214
|
+
~ > ruby samples/f.rb
|
215
|
+
|
216
|
+
10
|
217
|
+
2
|
218
|
+
|
219
|
+
|
220
|
+
== Author
|
221
|
+
ara.t.howard@gmail.com
|
data/Rakefile
CHANGED
@@ -1,23 +1,66 @@
|
|
1
|
+
This.rubyforge_project = 'codeforpeople'
|
1
2
|
This.author = "Ara T. Howard"
|
2
3
|
This.email = "ara.t.howard@gmail.com"
|
3
|
-
This.homepage = "
|
4
|
-
|
4
|
+
This.homepage = "https://github.com/ahoward/#{ This.lib }"
|
5
|
+
|
5
6
|
|
6
7
|
task :default do
|
7
|
-
puts(Rake::Task.tasks.map{|task| task.name} - ['default'])
|
8
|
+
puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
|
9
|
+
end
|
10
|
+
|
11
|
+
task :test do
|
12
|
+
run_tests!
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :test do
|
16
|
+
task(:unit){ run_tests!(:unit) }
|
17
|
+
task(:functional){ run_tests!(:functional) }
|
18
|
+
task(:integration){ run_tests!(:integration) }
|
8
19
|
end
|
9
20
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
21
|
+
def run_tests!(which = nil)
|
22
|
+
which ||= '**'
|
23
|
+
test_dir = File.join(This.dir, "test")
|
24
|
+
test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
|
25
|
+
test_rbs = Dir.glob(test_glob).sort
|
26
|
+
|
27
|
+
div = ('=' * 119)
|
28
|
+
line = ('-' * 119)
|
29
|
+
|
30
|
+
test_rbs.each_with_index do |test_rb, index|
|
31
|
+
testno = index + 1
|
32
|
+
command = "#{ This.ruby } -I ./lib -I ./test/lib #{ test_rb }"
|
33
|
+
|
34
|
+
puts
|
35
|
+
say(div, :color => :cyan, :bold => true)
|
36
|
+
say("@#{ testno } => ", :bold => true, :method => :print)
|
37
|
+
say(command, :color => :cyan, :bold => true)
|
38
|
+
say(line, :color => :cyan, :bold => true)
|
39
|
+
|
40
|
+
system(command)
|
41
|
+
|
42
|
+
say(line, :color => :cyan, :bold => true)
|
43
|
+
|
44
|
+
status = $?.exitstatus
|
45
|
+
|
46
|
+
if status.zero?
|
47
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
48
|
+
say("SUCCESS", :color => :green, :bold => true)
|
49
|
+
else
|
50
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
51
|
+
say("FAILURE", :color => :red, :bold => true)
|
52
|
+
end
|
53
|
+
say(line, :color => :cyan, :bold => true)
|
54
|
+
|
55
|
+
exit(status) unless status.zero?
|
14
56
|
end
|
15
57
|
end
|
16
58
|
|
59
|
+
|
17
60
|
task :gemspec do
|
18
|
-
ignore_extensions = 'git', 'svn', 'tmp', /sw./, 'bak', 'gem'
|
19
|
-
ignore_directories = 'pkg'
|
20
|
-
ignore_files = 'test/log'
|
61
|
+
ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
|
62
|
+
ignore_directories = ['pkg']
|
63
|
+
ignore_files = ['test/log']
|
21
64
|
|
22
65
|
shiteless =
|
23
66
|
lambda do |list|
|
@@ -39,14 +82,18 @@ task :gemspec do
|
|
39
82
|
end
|
40
83
|
|
41
84
|
lib = This.lib
|
85
|
+
object = This.object
|
42
86
|
version = This.version
|
43
87
|
files = shiteless[Dir::glob("**/**")]
|
44
88
|
executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
|
45
|
-
has_rdoc = true #File.exist?('doc')
|
89
|
+
#has_rdoc = true #File.exist?('doc')
|
46
90
|
test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
|
91
|
+
summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
|
92
|
+
description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
|
47
93
|
|
48
|
-
|
49
|
-
|
94
|
+
if This.extensions.nil?
|
95
|
+
This.extensions = []
|
96
|
+
extensions = This.extensions
|
50
97
|
%w( Makefile configure extconf.rb ).each do |ext|
|
51
98
|
extensions << ext if File.exists?(ext)
|
52
99
|
end
|
@@ -67,18 +114,17 @@ task :gemspec do
|
|
67
114
|
spec.version = #{ version.inspect }
|
68
115
|
spec.platform = Gem::Platform::RUBY
|
69
116
|
spec.summary = #{ lib.inspect }
|
117
|
+
spec.description = #{ description.inspect }
|
70
118
|
|
71
|
-
spec.files
|
119
|
+
spec.files =\n#{ files.sort.pretty_inspect }
|
72
120
|
spec.executables = #{ executables.inspect }
|
73
121
|
|
74
|
-
<% if test(?d, 'lib') %>
|
75
122
|
spec.require_path = "lib"
|
76
|
-
<% end %>
|
77
123
|
|
78
|
-
spec.has_rdoc = #{ has_rdoc.inspect }
|
79
124
|
spec.test_files = #{ test_files.inspect }
|
80
|
-
|
81
|
-
|
125
|
+
|
126
|
+
### spec.add_dependency 'lib', '>= version'
|
127
|
+
#### spec.add_dependency 'map'
|
82
128
|
|
83
129
|
spec.extensions.push(*#{ extensions.inspect })
|
84
130
|
|
@@ -91,19 +137,21 @@ task :gemspec do
|
|
91
137
|
}
|
92
138
|
end
|
93
139
|
|
94
|
-
|
95
|
-
|
140
|
+
Fu.mkdir_p(This.pkgdir)
|
141
|
+
gemspec = "#{ lib }.gemspec"
|
142
|
+
open(gemspec, "w"){|fd| fd.puts(template)}
|
143
|
+
This.gemspec = gemspec
|
96
144
|
end
|
97
145
|
|
98
146
|
task :gem => [:clean, :gemspec] do
|
99
|
-
Fu.mkdir_p
|
147
|
+
Fu.mkdir_p(This.pkgdir)
|
100
148
|
before = Dir['*.gem']
|
101
149
|
cmd = "gem build #{ This.gemspec }"
|
102
150
|
`#{ cmd }`
|
103
151
|
after = Dir['*.gem']
|
104
152
|
gem = ((after - before).first || after.first) or abort('no gem!')
|
105
|
-
Fu.mv
|
106
|
-
This.gem = File.basename(gem)
|
153
|
+
Fu.mv(gem, This.pkgdir)
|
154
|
+
This.gem = File.join(This.pkgdir, File.basename(gem))
|
107
155
|
end
|
108
156
|
|
109
157
|
task :readme do
|
@@ -122,7 +170,7 @@ task :readme do
|
|
122
170
|
cmd = "ruby #{ sample }"
|
123
171
|
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
124
172
|
|
125
|
-
cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -
|
173
|
+
cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
|
126
174
|
samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
|
127
175
|
end
|
128
176
|
|
@@ -159,9 +207,18 @@ task :release => [:clean, :gemspec, :gem] do
|
|
159
207
|
gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
|
160
208
|
raise "which one? : #{ gems.inspect }" if gems.size > 1
|
161
209
|
raise "no gems?" if gems.size < 1
|
162
|
-
|
210
|
+
|
211
|
+
cmd = "gem push #{ This.gem }"
|
212
|
+
puts cmd
|
213
|
+
puts
|
214
|
+
system(cmd)
|
215
|
+
abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
|
216
|
+
|
217
|
+
cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }"
|
163
218
|
puts cmd
|
164
|
-
|
219
|
+
puts
|
220
|
+
system(cmd)
|
221
|
+
abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
|
165
222
|
end
|
166
223
|
|
167
224
|
|
@@ -169,44 +226,63 @@ end
|
|
169
226
|
|
170
227
|
|
171
228
|
BEGIN {
|
229
|
+
# support for this rakefile
|
230
|
+
#
|
172
231
|
$VERBOSE = nil
|
173
232
|
|
174
233
|
require 'ostruct'
|
175
234
|
require 'erb'
|
176
235
|
require 'fileutils'
|
236
|
+
require 'rbconfig'
|
237
|
+
require 'pp'
|
177
238
|
|
239
|
+
# fu shortcut
|
240
|
+
#
|
178
241
|
Fu = FileUtils
|
179
242
|
|
243
|
+
# cache a bunch of stuff about this rakefile/environment
|
244
|
+
#
|
180
245
|
This = OpenStruct.new
|
181
246
|
|
182
247
|
This.file = File.expand_path(__FILE__)
|
183
248
|
This.dir = File.dirname(This.file)
|
184
249
|
This.pkgdir = File.join(This.dir, 'pkg')
|
185
250
|
|
251
|
+
# grok lib
|
252
|
+
#
|
186
253
|
lib = ENV['LIB']
|
187
254
|
unless lib
|
188
|
-
lib = File.basename(Dir.pwd)
|
255
|
+
lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
|
189
256
|
end
|
190
257
|
This.lib = lib
|
191
258
|
|
259
|
+
# grok version
|
260
|
+
#
|
192
261
|
version = ENV['VERSION']
|
193
262
|
unless version
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
require library
|
199
|
-
version = eval(name).send(:version)
|
200
|
-
elsif test(?e, program)
|
201
|
-
version = `#{ program } --version`.strip
|
202
|
-
end
|
203
|
-
abort('no version') if(version.nil? or version.empty?)
|
263
|
+
require "./lib/#{ This.lib }"
|
264
|
+
This.name = lib.capitalize
|
265
|
+
This.object = eval(This.name)
|
266
|
+
version = This.object.send(:version)
|
204
267
|
end
|
205
268
|
This.version = version
|
206
269
|
|
270
|
+
# we need to know the name of the lib an it's version
|
271
|
+
#
|
207
272
|
abort('no lib') unless This.lib
|
208
273
|
abort('no version') unless This.version
|
209
274
|
|
275
|
+
# discover full path to this ruby executable
|
276
|
+
#
|
277
|
+
c = Config::CONFIG
|
278
|
+
bindir = c["bindir"] || c['BINDIR']
|
279
|
+
ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
|
280
|
+
ruby_ext = c['EXEEXT'] || ''
|
281
|
+
ruby = File.join(bindir, (ruby_install_name + ruby_ext))
|
282
|
+
This.ruby = ruby
|
283
|
+
|
284
|
+
# some utils
|
285
|
+
#
|
210
286
|
module Util
|
211
287
|
def indent(s, n = 2)
|
212
288
|
s = unindent(s)
|
@@ -216,7 +292,7 @@ BEGIN {
|
|
216
292
|
|
217
293
|
def unindent(s)
|
218
294
|
indent = nil
|
219
|
-
s.
|
295
|
+
s.each_line do |line|
|
220
296
|
next if line =~ %r/^\s*$/
|
221
297
|
indent = line[%r/^\s*/] and break
|
222
298
|
end
|
@@ -225,17 +301,71 @@ BEGIN {
|
|
225
301
|
extend self
|
226
302
|
end
|
227
303
|
|
304
|
+
# template support
|
305
|
+
#
|
228
306
|
class Template
|
229
307
|
def initialize(&block)
|
230
308
|
@block = block
|
231
309
|
@template = block.call.to_s
|
232
310
|
end
|
233
311
|
def expand(b=nil)
|
234
|
-
ERB.new(Util.unindent(@template)).result(b||@block)
|
312
|
+
ERB.new(Util.unindent(@template)).result((b||@block).binding)
|
235
313
|
end
|
236
314
|
alias_method 'to_s', 'expand'
|
237
315
|
end
|
238
316
|
def Template(*args, &block) Template.new(*args, &block) end
|
239
317
|
|
318
|
+
# colored console output support
|
319
|
+
#
|
320
|
+
This.ansi = {
|
321
|
+
:clear => "\e[0m",
|
322
|
+
:reset => "\e[0m",
|
323
|
+
:erase_line => "\e[K",
|
324
|
+
:erase_char => "\e[P",
|
325
|
+
:bold => "\e[1m",
|
326
|
+
:dark => "\e[2m",
|
327
|
+
:underline => "\e[4m",
|
328
|
+
:underscore => "\e[4m",
|
329
|
+
:blink => "\e[5m",
|
330
|
+
:reverse => "\e[7m",
|
331
|
+
:concealed => "\e[8m",
|
332
|
+
:black => "\e[30m",
|
333
|
+
:red => "\e[31m",
|
334
|
+
:green => "\e[32m",
|
335
|
+
:yellow => "\e[33m",
|
336
|
+
:blue => "\e[34m",
|
337
|
+
:magenta => "\e[35m",
|
338
|
+
:cyan => "\e[36m",
|
339
|
+
:white => "\e[37m",
|
340
|
+
:on_black => "\e[40m",
|
341
|
+
:on_red => "\e[41m",
|
342
|
+
:on_green => "\e[42m",
|
343
|
+
:on_yellow => "\e[43m",
|
344
|
+
:on_blue => "\e[44m",
|
345
|
+
:on_magenta => "\e[45m",
|
346
|
+
:on_cyan => "\e[46m",
|
347
|
+
:on_white => "\e[47m"
|
348
|
+
}
|
349
|
+
def say(phrase, *args)
|
350
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
351
|
+
options[:color] = args.shift.to_s.to_sym unless args.empty?
|
352
|
+
keys = options.keys
|
353
|
+
keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
|
354
|
+
|
355
|
+
color = options[:color]
|
356
|
+
bold = options.has_key?(:bold)
|
357
|
+
|
358
|
+
parts = [phrase]
|
359
|
+
parts.unshift(This.ansi[color]) if color
|
360
|
+
parts.unshift(This.ansi[:bold]) if bold
|
361
|
+
parts.push(This.ansi[:clear]) if parts.size > 1
|
362
|
+
|
363
|
+
method = options[:method] || :puts
|
364
|
+
|
365
|
+
Kernel.send(method, parts.join)
|
366
|
+
end
|
367
|
+
|
368
|
+
# always run out of the project dir
|
369
|
+
#
|
240
370
|
Dir.chdir(This.dir)
|
241
371
|
}
|
data/config/f.rb
ADDED
data/configuration.gemspec
CHANGED
@@ -3,26 +3,46 @@
|
|
3
3
|
|
4
4
|
Gem::Specification::new do |spec|
|
5
5
|
spec.name = "configuration"
|
6
|
-
spec.version = "1.
|
6
|
+
spec.version = "1.3.1"
|
7
7
|
spec.platform = Gem::Platform::RUBY
|
8
8
|
spec.summary = "configuration"
|
9
|
+
spec.description = "description: configuration kicks the ass"
|
10
|
+
|
11
|
+
spec.files =
|
12
|
+
["LICENSE",
|
13
|
+
"README.rdoc",
|
14
|
+
"Rakefile",
|
15
|
+
"config",
|
16
|
+
"config/a.rb",
|
17
|
+
"config/b.rb",
|
18
|
+
"config/c.rb",
|
19
|
+
"config/d.rb",
|
20
|
+
"config/e.rb",
|
21
|
+
"config/f.rb",
|
22
|
+
"configuration.gemspec",
|
23
|
+
"lib",
|
24
|
+
"lib/configuration.rb",
|
25
|
+
"samples",
|
26
|
+
"samples/a.rb",
|
27
|
+
"samples/b.rb",
|
28
|
+
"samples/c.rb",
|
29
|
+
"samples/d.rb",
|
30
|
+
"samples/e.rb",
|
31
|
+
"samples/f.rb"]
|
9
32
|
|
10
|
-
spec.files = ["config", "config/a.rb", "config/b.rb", "config/c.rb", "config/d.rb", "config/e.rb", "configuration.gemspec", "lib", "lib/configuration.rb", "LICENSE", "Rakefile", "README", "README.erb", "samples", "samples/a.rb", "samples/b.rb", "samples/c.rb", "samples/d.rb", "samples/e.rb"]
|
11
33
|
spec.executables = []
|
12
34
|
|
13
|
-
|
14
35
|
spec.require_path = "lib"
|
15
|
-
|
16
36
|
|
17
|
-
spec.has_rdoc = true
|
18
37
|
spec.test_files = nil
|
19
|
-
|
20
|
-
|
38
|
+
|
39
|
+
### spec.add_dependency 'lib', '>= version'
|
40
|
+
#### spec.add_dependency 'map'
|
21
41
|
|
22
42
|
spec.extensions.push(*[])
|
23
43
|
|
24
44
|
spec.rubyforge_project = "codeforpeople"
|
25
45
|
spec.author = "Ara T. Howard"
|
26
46
|
spec.email = "ara.t.howard@gmail.com"
|
27
|
-
spec.homepage = "
|
47
|
+
spec.homepage = "https://github.com/ahoward/configuration"
|
28
48
|
end
|
data/lib/configuration.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Configuration
|
2
|
-
Configuration::Version = '1.
|
2
|
+
Configuration::Version = '1.3.1'
|
3
3
|
def Configuration.version() Configuration::Version end
|
4
4
|
|
5
5
|
Path = [
|
@@ -16,6 +16,8 @@ class Configuration
|
|
16
16
|
module ClassMethods
|
17
17
|
def for name, options = nil, &block
|
18
18
|
name = name.to_s
|
19
|
+
options = options.to_hash if options.is_a?( Configuration )
|
20
|
+
|
19
21
|
if Table.has_key?(name)
|
20
22
|
if options or block
|
21
23
|
configuration = Table[name]
|
@@ -132,8 +134,10 @@ class Configuration
|
|
132
134
|
|
133
135
|
def self.evaluate configuration, options = {}, &block
|
134
136
|
dsl = new configuration
|
135
|
-
|
137
|
+
|
136
138
|
options.each{|key, value| Pure[dsl].send key, value}
|
139
|
+
Pure[dsl].instance_eval(&block) if block
|
140
|
+
|
137
141
|
Pure[dsl].instance_eval{ @__configuration }
|
138
142
|
end
|
139
143
|
|
data/samples/f.rb
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configuration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 3
|
9
|
+
- 1
|
10
|
+
version: 1.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ara T. Howard
|
@@ -15,11 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-06-20 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
22
|
-
description:
|
22
|
+
description: "description: configuration kicks the ass"
|
23
23
|
email: ara.t.howard@gmail.com
|
24
24
|
executables: []
|
25
25
|
|
@@ -28,24 +28,25 @@ extensions: []
|
|
28
28
|
extra_rdoc_files: []
|
29
29
|
|
30
30
|
files:
|
31
|
+
- LICENSE
|
32
|
+
- README.rdoc
|
33
|
+
- Rakefile
|
31
34
|
- config/a.rb
|
32
35
|
- config/b.rb
|
33
36
|
- config/c.rb
|
34
37
|
- config/d.rb
|
35
38
|
- config/e.rb
|
39
|
+
- config/f.rb
|
36
40
|
- configuration.gemspec
|
37
41
|
- lib/configuration.rb
|
38
|
-
- LICENSE
|
39
|
-
- Rakefile
|
40
|
-
- README
|
41
|
-
- README.erb
|
42
42
|
- samples/a.rb
|
43
43
|
- samples/b.rb
|
44
44
|
- samples/c.rb
|
45
45
|
- samples/d.rb
|
46
46
|
- samples/e.rb
|
47
|
+
- samples/f.rb
|
47
48
|
has_rdoc: true
|
48
|
-
homepage:
|
49
|
+
homepage: https://github.com/ahoward/configuration
|
49
50
|
licenses: []
|
50
51
|
|
51
52
|
post_install_message:
|
@@ -74,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
75
|
requirements: []
|
75
76
|
|
76
77
|
rubyforge_project: codeforpeople
|
77
|
-
rubygems_version: 1.
|
78
|
+
rubygems_version: 1.4.2
|
78
79
|
signing_key:
|
79
80
|
specification_version: 3
|
80
81
|
summary: configuration
|
data/README
DELETED
@@ -1,197 +0,0 @@
|
|
1
|
-
NAME
|
2
|
-
configuration.rb
|
3
|
-
|
4
|
-
SYNOPSIS
|
5
|
-
pure ruby scoped configuration files
|
6
|
-
|
7
|
-
DESCRIPTION
|
8
|
-
configuration.rb provides a mechanism for configuring ruby programs with
|
9
|
-
ruby configuration files. a configuration.rb file, for example
|
10
|
-
'config/app.rb', can be written simply as
|
11
|
-
|
12
|
-
Configuration.for('app'){
|
13
|
-
key 'value'
|
14
|
-
foo 'bar'
|
15
|
-
port 42
|
16
|
-
}
|
17
|
-
|
18
|
-
and loaded via the normal ruby require/load mechanism
|
19
|
-
|
20
|
-
Kernel.load 'config/app.rb'
|
21
|
-
|
22
|
-
or with a slightly augmented loading mechnanism which simply searches an
|
23
|
-
extra set of paths in *addition* to the standard ones
|
24
|
-
|
25
|
-
Configuration.path = %w( config configuration )
|
26
|
-
|
27
|
-
Configuration.load 'app'
|
28
|
-
|
29
|
-
configurations are completely open
|
30
|
-
|
31
|
-
Configuration.for('app'){
|
32
|
-
object_id 'very open'
|
33
|
-
}
|
34
|
-
|
35
|
-
support arbitrarily nested values
|
36
|
-
|
37
|
-
Configuration.for('app'){
|
38
|
-
a { b { c { d 42 } } }
|
39
|
-
}
|
40
|
-
|
41
|
-
c = Configuration.for 'app'
|
42
|
-
|
43
|
-
p c.a.b.c.d #=> 42
|
44
|
-
|
45
|
-
allow POLS scoped lookup of vars
|
46
|
-
|
47
|
-
Configuration.for('config'){
|
48
|
-
outer 'bar'
|
49
|
-
|
50
|
-
inner {
|
51
|
-
value 42
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
c = Configuration.for 'config'
|
56
|
-
|
57
|
-
p c.outer #=> 'bar'
|
58
|
-
p c.inner.value #=> 42
|
59
|
-
p c.inner.outer #=> 'bar'
|
60
|
-
|
61
|
-
|
62
|
-
and not a whole lot else - configuration.rb is s very small library
|
63
|
-
consisting of one file and < 150 loc
|
64
|
-
|
65
|
-
SAMPLES
|
66
|
-
|
67
|
-
<========< samples/a.rb >========>
|
68
|
-
|
69
|
-
~ > cat samples/a.rb
|
70
|
-
|
71
|
-
#
|
72
|
-
# basic usage is quite, simple, load the config and use it's values. the
|
73
|
-
# config syntax is fairly obvious, i think, but note that it *is* ruby and any
|
74
|
-
# ruby can be included. also note that each config is named, allowing
|
75
|
-
# multiple configs to be places in one file
|
76
|
-
#
|
77
|
-
require 'configuration'
|
78
|
-
|
79
|
-
c = Configuration.load 'a'
|
80
|
-
|
81
|
-
p c.a + c.b - c.c
|
82
|
-
|
83
|
-
~ > ruby samples/a.rb
|
84
|
-
|
85
|
-
42
|
86
|
-
|
87
|
-
|
88
|
-
<========< samples/b.rb >========>
|
89
|
-
|
90
|
-
~ > cat samples/b.rb
|
91
|
-
|
92
|
-
#
|
93
|
-
# configuration.rb supports a very natural nesting syntax. note how values
|
94
|
-
# are scoped in a POLS fashion
|
95
|
-
#
|
96
|
-
require 'configuration'
|
97
|
-
|
98
|
-
c = Configuration.for 'b'
|
99
|
-
|
100
|
-
p c.www.url
|
101
|
-
p c.db.url
|
102
|
-
p c.mail.url
|
103
|
-
|
104
|
-
~ > ruby samples/b.rb
|
105
|
-
|
106
|
-
"http://codeforpeople.com:80"
|
107
|
-
"db://codeforpeople.com:5342"
|
108
|
-
"mail://gmail.com:25"
|
109
|
-
|
110
|
-
|
111
|
-
<========< samples/c.rb >========>
|
112
|
-
|
113
|
-
~ > cat samples/c.rb
|
114
|
-
|
115
|
-
#
|
116
|
-
# configuration.rb let's you keep code very dry.
|
117
|
-
#
|
118
|
-
|
119
|
-
require 'configuration'
|
120
|
-
|
121
|
-
Configuration.load 'c'
|
122
|
-
|
123
|
-
p Configuration.for('development').db
|
124
|
-
p Configuration.for('production').db
|
125
|
-
p Configuration.for('testing').db
|
126
|
-
|
127
|
-
~ > ruby samples/c.rb
|
128
|
-
|
129
|
-
"db/development"
|
130
|
-
"db/production"
|
131
|
-
"db/testing"
|
132
|
-
|
133
|
-
|
134
|
-
<========< samples/d.rb >========>
|
135
|
-
|
136
|
-
~ > cat samples/d.rb
|
137
|
-
|
138
|
-
#
|
139
|
-
# configuration.rb makes use of an external blank slate dsl, this means that
|
140
|
-
# you Configuration objects do, in fact, have all built-in ruby methods such
|
141
|
-
# as #inspect, etc, *unless* you configure over the top of them. the effect
|
142
|
-
# is a configuration object that behaves like a nice ruby object, but which
|
143
|
-
# allows *any* key to be configured
|
144
|
-
#
|
145
|
-
require 'configuration'
|
146
|
-
|
147
|
-
c = Configuration.for 'd'
|
148
|
-
|
149
|
-
p c.object_id
|
150
|
-
p c.inspect
|
151
|
-
p c.p
|
152
|
-
|
153
|
-
~ > ruby samples/d.rb
|
154
|
-
|
155
|
-
config/d.rb:2:in `object_id': wrong number of arguments (1 for 0) (ArgumentError)
|
156
|
-
from config/d.rb:2
|
157
|
-
from ./lib/configuration.rb:159:in `instance_eval'
|
158
|
-
from ./lib/configuration.rb:159:in `call'
|
159
|
-
from ./lib/configuration.rb:159:in `method_missing'
|
160
|
-
from ./lib/configuration.rb:105:in `evaluate'
|
161
|
-
from ./lib/configuration.rb:68:in `initialize'
|
162
|
-
from ./lib/configuration.rb:29:in `new'
|
163
|
-
from ./lib/configuration.rb:29:in `for'
|
164
|
-
from config/d.rb:1
|
165
|
-
from ./lib/configuration.rb:53:in `load'
|
166
|
-
from ./lib/configuration.rb:53:in `load'
|
167
|
-
from ./lib/configuration.rb:31:in `for'
|
168
|
-
from samples/d.rb:10
|
169
|
-
|
170
|
-
|
171
|
-
<========< samples/e.rb >========>
|
172
|
-
|
173
|
-
~ > cat samples/e.rb
|
174
|
-
|
175
|
-
#
|
176
|
-
# configuration.rb uses a totally clean slate dsl for the block. if you need
|
177
|
-
# to access base Object methods you can do this
|
178
|
-
#
|
179
|
-
|
180
|
-
require 'configuration'
|
181
|
-
|
182
|
-
c = Configuration.for 'e'
|
183
|
-
|
184
|
-
p c.foo
|
185
|
-
p c.bar
|
186
|
-
p c.foobar
|
187
|
-
|
188
|
-
~ > ruby samples/e.rb
|
189
|
-
|
190
|
-
42
|
191
|
-
"forty-two"
|
192
|
-
42.0
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
AUTHOR
|
197
|
-
ara.t.howard@gmail.com
|
data/README.erb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
NAME
|
2
|
-
configuration.rb
|
3
|
-
|
4
|
-
SYNOPSIS
|
5
|
-
pure ruby scoped configuration files
|
6
|
-
|
7
|
-
DESCRIPTION
|
8
|
-
configuration.rb provides a mechanism for configuring ruby programs with
|
9
|
-
ruby configuration files. a configuration.rb file, for example
|
10
|
-
'config/app.rb', can be written simply as
|
11
|
-
|
12
|
-
Configuration.for('app'){
|
13
|
-
key 'value'
|
14
|
-
foo 'bar'
|
15
|
-
port 42
|
16
|
-
}
|
17
|
-
|
18
|
-
and loaded via the normal ruby require/load mechanism
|
19
|
-
|
20
|
-
Kernel.load 'config/app.rb'
|
21
|
-
|
22
|
-
or with a slightly augmented loading mechnanism which simply searches an
|
23
|
-
extra set of paths in *addition* to the standard ones
|
24
|
-
|
25
|
-
Configuration.path = %w( config configuration )
|
26
|
-
|
27
|
-
Configuration.load 'app'
|
28
|
-
|
29
|
-
configurations are completely open
|
30
|
-
|
31
|
-
Configuration.for('app'){
|
32
|
-
object_id 'very open'
|
33
|
-
}
|
34
|
-
|
35
|
-
support arbitrarily nested values
|
36
|
-
|
37
|
-
Configuration.for('app'){
|
38
|
-
a { b { c { d 42 } } }
|
39
|
-
}
|
40
|
-
|
41
|
-
c = Configuration.for 'app'
|
42
|
-
|
43
|
-
p c.a.b.c.d #=> 42
|
44
|
-
|
45
|
-
allow POLS scoped lookup of vars
|
46
|
-
|
47
|
-
Configuration.for('config'){
|
48
|
-
outer 'bar'
|
49
|
-
|
50
|
-
inner {
|
51
|
-
value 42
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
c = Configuration.for 'config'
|
56
|
-
|
57
|
-
p c.outer #=> 'bar'
|
58
|
-
p c.inner.value #=> 42
|
59
|
-
p c.inner.outer #=> 'bar'
|
60
|
-
|
61
|
-
|
62
|
-
and not a whole lot else - configuration.rb is s very small library
|
63
|
-
consisting of one file and < 150 loc
|
64
|
-
|
65
|
-
SAMPLES
|
66
|
-
<%= samples %>
|
67
|
-
|
68
|
-
AUTHOR
|
69
|
-
ara.t.howard@gmail.com
|