configliere 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +35 -24
- data/VERSION +1 -1
- data/configliere.gemspec +2 -2
- data/examples/simple_script.rb +11 -4
- data/examples/simple_script.yaml +4 -4
- metadata +2 -2
data/README.textile
CHANGED
@@ -10,32 +10,40 @@ Configliere manages settings from many sources: static constants, simple config
|
|
10
10
|
|
11
11
|
h3. Example
|
12
12
|
|
13
|
-
Here's a simple example, using params from a config file and the command line.
|
14
|
-
|
15
|
-
<pre>
|
16
|
-
:cat: hat
|
17
|
-
:spider: tuffet
|
18
|
-
:sprats:
|
19
|
-
:jack: lean</pre>
|
20
|
-
|
21
|
-
(Note that all simple keys should be symbols, with an exception described below.) A simple script:
|
13
|
+
Here's a simple example, using params from a config file and the command line. In the script:
|
22
14
|
|
23
15
|
<pre>
|
24
16
|
#/usr/bin/env ruby
|
25
17
|
require 'configliere'
|
26
18
|
Settings.use :commandline, :config_file
|
27
19
|
|
28
|
-
Settings
|
20
|
+
Settings({
|
21
|
+
:dest_time => '1955-11-05',
|
22
|
+
:delorean => {
|
23
|
+
:power_source => 'plutonium',
|
24
|
+
:roads_needed => true,
|
25
|
+
},
|
26
|
+
:username => 'marty',
|
27
|
+
})
|
29
28
|
Settings.read 'my_script.yaml' # reads ~/.configliere/my_script.yaml
|
30
29
|
Settings.resolve!
|
31
|
-
|
32
30
|
p Settings</pre>
|
33
31
|
|
32
|
+
We'll override some of the defaults with a config file, in this case ~/.configliere/simple_script.yaml
|
33
|
+
|
34
|
+
<pre>
|
35
|
+
# Settings for return
|
36
|
+
:dest_time: 1985-11-05
|
37
|
+
:delorean:
|
38
|
+
:power_source: 1.21 jiggawatts
|
39
|
+
</pre>
|
40
|
+
|
34
41
|
Output, when run with commandline parameters as shown:
|
35
42
|
|
36
43
|
<pre>
|
37
|
-
./
|
38
|
-
{:
|
44
|
+
./time_machine.rb --username=doc_brown --delorean.roads_needed="" --delorean.power_source="Mr. Fusion"
|
45
|
+
{:dest_time=>"1985-11-05", :username=>"doc_brown", :delorean=>{:power_source=>"Mr. Fusion", :roads_needed=>nil}}
|
46
|
+
</pre>
|
39
47
|
|
40
48
|
For an extensive usage in production, see the "wukong gem.":http://github.com/mrflip/wukong
|
41
49
|
|
@@ -61,7 +69,7 @@ Configliere settings are just a plain old normal hash.
|
|
61
69
|
You can define static defaults in your module
|
62
70
|
|
63
71
|
<pre>
|
64
|
-
Settings
|
72
|
+
Settings({
|
65
73
|
:dest_time => '1955-11-05',
|
66
74
|
:fluxcapacitor => {
|
67
75
|
:speed => 88,
|
@@ -75,7 +83,7 @@ You can define static defaults in your module
|
|
75
83
|
})
|
76
84
|
</pre>
|
77
85
|
|
78
|
-
Retrieve
|
86
|
+
(Note that all simple keys should be symbols, with an exception you're about to see.) Retrieve the settings as:
|
79
87
|
|
80
88
|
<pre>
|
81
89
|
# hash keys
|
@@ -88,7 +96,7 @@ Retrieve them as:
|
|
88
96
|
Settings['delorean.power_source'] #=> 'plutonium'
|
89
97
|
Settings['delorean.missing'] #=> nil
|
90
98
|
Settings['delorean.missing.fail'] #=> nil
|
91
|
-
# method-like (no deep keys tho)
|
99
|
+
# method-like (no deep keys tho, and you have to @#define@ the param; see below)
|
92
100
|
Settings.dest_time #=> '1955-11-05'
|
93
101
|
</pre>
|
94
102
|
|
@@ -193,9 +201,10 @@ h2. Command-line parameters
|
|
193
201
|
|
194
202
|
<pre>
|
195
203
|
# Head back
|
196
|
-
time_machine --delorean
|
204
|
+
time_machine --delorean.power_source='1.21 gigawatt lightning strike' --dest_time=1985-11-05
|
197
205
|
# (in the time_machine script:)
|
198
206
|
Settings.use :commandline
|
207
|
+
Settings.resolve!
|
199
208
|
</pre>
|
200
209
|
|
201
210
|
Interpretation of command-line parameters:
|
@@ -224,7 +233,7 @@ You don't have to pre-define parameters, but you can:
|
|
224
233
|
|
225
234
|
<pre>
|
226
235
|
Settings.use :define
|
227
|
-
Settings.define :dest_time, :type =>
|
236
|
+
Settings.define :dest_time, :type => DateTime, :description => 'Arrival time'
|
228
237
|
Settings.define 'delorean.power_source', :env_var => 'POWER_SOURCE', :description => 'Delorean subsytem supplying power to the Flux Capacitor.'
|
229
238
|
Settings.define :password, :required => true, :encrypted => true
|
230
239
|
</pre>
|
@@ -235,7 +244,7 @@ You don't have to pre-define parameters, but you can:
|
|
235
244
|
* *:encrypted*: marks params to be obscured when saved to disk. See [#Encrypted Parameters] below for caveats.
|
236
245
|
* *:env_var*: take param from given environment variable if set.
|
237
246
|
|
238
|
-
Defined parameters are demonstrated in most of the
|
247
|
+
Defined parameters are demonstrated in most of the "example scripts":http://github.com/mrflip/configliere/tree/master/examples
|
239
248
|
|
240
249
|
h3. Type Conversion
|
241
250
|
|
@@ -302,15 +311,17 @@ h2. Independent Settings
|
|
302
311
|
All of the above examples use the global variable @Settings@, defined in configliere.rb. You're free to define your own settings universe though:
|
303
312
|
|
304
313
|
<pre>
|
305
|
-
|
314
|
+
class Wolfman
|
306
315
|
cattr_accessor :config
|
307
316
|
self.config = Configliere.new({
|
308
|
-
:
|
309
|
-
:
|
317
|
+
:moon => 'full',
|
318
|
+
:nards => true,
|
310
319
|
})
|
311
320
|
end
|
312
|
-
|
313
|
-
|
321
|
+
teen_wolf = proj.new
|
322
|
+
teen_wolf.config.defaults(:give_me => 'keg of beer')
|
323
|
+
teen_wolf.config #=> {:moon=>"full", :nards=>true, :give_me=>"keg of beer" }
|
324
|
+
Settings #=> {}
|
314
325
|
</pre>
|
315
326
|
|
316
327
|
Values in here don't overlap with the Settings object or any other settings universe. However, every one that pulls in commandline params gets a full copy of the commandline params.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/configliere.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{configliere}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["mrflip"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-20}
|
13
13
|
s.default_executable = %q{configliere}
|
14
14
|
s.description = %q{ You've got a script. It's got some settings. Some settings are for this module, some are for that module. Most of them don't change. Except on your laptop, where the paths are different. Or when you're in production mode. Or when you're testing from the command line.
|
15
15
|
|
data/examples/simple_script.rb
CHANGED
@@ -3,21 +3,28 @@ $: << File.dirname(__FILE__)+'/../lib'
|
|
3
3
|
require 'configliere'
|
4
4
|
|
5
5
|
puts "This is a demo of Configliere in a simple script."
|
6
|
-
Settings.use :commandline, :config_file
|
6
|
+
Settings.use :commandline, :config_file, :define
|
7
7
|
|
8
8
|
puts "You can set default values:"
|
9
|
-
Settings
|
9
|
+
Settings({
|
10
|
+
:dest_time => '1955-11-05',
|
11
|
+
:delorean => {
|
12
|
+
:power_source => 'plutonium',
|
13
|
+
:roads_needed => true,
|
14
|
+
},
|
15
|
+
})
|
10
16
|
puts " #{Settings.inspect}"
|
11
17
|
|
12
18
|
config_filename = File.dirname(__FILE__)+'/simple_script.yaml'
|
13
19
|
puts "\nYou can load values from a file -- in this case, #{config_filename} -- which overrides the defaults:"
|
14
20
|
Settings.read config_filename
|
21
|
+
Settings.resolve!
|
15
22
|
puts " #{Settings.inspect}"
|
16
23
|
|
17
24
|
puts %Q{\nTry running the script with commandline parameters, for example
|
18
|
-
#{$0} --
|
25
|
+
#{$0} --dest_time=2015-11-05 --delorean.roads_needed="" --delorean.power_source="Mr. Fusion"
|
19
26
|
In this case, you used
|
20
|
-
#{$0} #{ARGV.join(" ")}
|
27
|
+
#{$0} #{ARGV.map{|argv| "'#{argv}'"}.join(" ")}
|
21
28
|
and so the final parameter values are}
|
22
29
|
Settings.resolve!
|
23
30
|
puts " #{Settings.inspect}"
|
data/examples/simple_script.yaml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
:
|
4
|
-
:
|
5
|
-
:
|
2
|
+
# Settings for return
|
3
|
+
:dest_time: 1985-11-05
|
4
|
+
:delorean:
|
5
|
+
:power_source: 1.21 jiggawatts
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configliere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mrflip
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-20 00:00:00 -06:00
|
13
13
|
default_executable: configliere
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|