configliere 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.textile CHANGED
@@ -1,4 +1,9 @@
1
- h2. Version 0.4.0 2011-05-13: MANY BREAKING CHANGES
1
+ h2. Version 0.4.5
2
+
3
+ * can now ask for @has_definition?(:my_param)@ or @has_definition?(:my_param, :description)@.
4
+ * validate! and define each returns self, so you can chain.
5
+
6
+ h2. Version 0.4.4 2011-05-13: MANY BREAKING CHANGES
2
7
 
3
8
  Killed many features for great justice. Configliere should now be much more predictable and lightweight, and has a much stricter API. Unfortunately, this will break backwards compatibility in some ways.
4
9
 
data/FEATURES.txt ADDED
@@ -0,0 +1,298 @@
1
+ Configliere::Commandline
2
+ with long-format argvs
3
+ accepts --param=val pairs
4
+ accepts --dotted.param.name=val pairs as deep keys
5
+ NO LONGER accepts --dashed-param-name=val pairs as deep keys
6
+ adopts only the last-seen of duplicate commandline flags
7
+ does NOT set a bare parameter (no "=") followed by a non-param to that value
8
+ sets a bare parameter (no "=") to true
9
+ sets an explicit blank to nil
10
+ captures non --param args into Settings.rest
11
+ stops processing args on "--"
12
+ places undefined argvs into #unknown_argvs
13
+ with single-letter flags
14
+ accepts them separately
15
+ accepts them as a group ("-abc")
16
+ accepts a value with -d=new_val
17
+ accepts a space-separated value (-d new_val)
18
+ accepts a space-separated value only if the next arg is not a flag
19
+ stores unknown single-letter flags in unknown_argvs
20
+ the help message
21
+ displays help
22
+ displays the single-letter flags
23
+ displays command line options
24
+ lets me die
25
+ recycling a commandline
26
+ exports dashed flags
27
+ #resolve!
28
+ calls super and returns self
29
+
30
+ Configliere::Commands
31
+ when no commands are defined
32
+ should know that no commands are defined
33
+ should not shift the ARGV when resolving
34
+ should still recognize a git-style-binary command
35
+ a simple command
36
+ should continue to parse flags when the command is given
37
+ should continue to set args when the command is given
38
+ should recognize the command when given
39
+ should recognize when the command is not given
40
+ a complex command
41
+ should still recognize the outer param and the args
42
+ should recognize the inner param
43
+ the help message
44
+ displays a modified usage
45
+ displays the commands and their descriptions
46
+ #resolve!
47
+ calls super and returns self
48
+
49
+ Configliere::ConfigBlock
50
+ resolving
51
+ runs blocks
52
+ resolves blocks last
53
+ #resolve!
54
+ calls super and returns self
55
+
56
+ Configliere::ConfigFile
57
+ is used by default
58
+ loading a config file
59
+ no longer provides a default config file
60
+ warns but does not fail if the file is missing
61
+ successfully
62
+ with an absolute pathname uses it directly
63
+ with a simple filename, references it to the default config dir
64
+ returns the config object for chaining
65
+ with an environment scope
66
+ slices out a subhash given by :env
67
+ slices out a different subhash with a different :env
68
+ does no slicing without the :env option
69
+ has no effect if the key given by :env option is absent
70
+ does not type convert the :env option
71
+ saves to a config file
72
+ with an absolute pathname, as given
73
+ with a simple pathname, in the default config dir
74
+ and ensures the directory exists
75
+ #resolve!
76
+ calls super and returns self
77
+
78
+ Crypter
79
+ encrypts
80
+ decrypts
81
+
82
+ DeepHash
83
+ #initialize
84
+ adopts a Hash when given
85
+ converts all pure Hash values into DeepHashes if param is a Hash
86
+ does not convert Hash subclass values into DeepHashes
87
+ converts all value items if value is an Array
88
+ delegates to superclass constructor if param is not a Hash
89
+ #update
90
+ converts all keys into symbols when param is a Hash
91
+ converts all Hash values into DeepHashes if param is a Hash
92
+ #[]=
93
+ symbolizes keys
94
+ deep-sets dotted vals, replacing values
95
+ deep-sets dotted vals, creating new values
96
+ deep-sets dotted vals, auto-vivifying intermediate hashes
97
+ converts all Hash value into DeepHash
98
+ #[]
99
+ deep-gets dotted vals
100
+ #to_hash
101
+ returns instance of Hash
102
+ preserves keys
103
+ preserves value
104
+ #compact
105
+ removes nils but not empties or falsehoods
106
+ leaves original alone
107
+ #compact!
108
+ removes nils but not empties or falsehoods
109
+ modifies in-place
110
+ #slice
111
+ returns a new hash with only the given keys
112
+ with bang replaces the hash with only the given keys
113
+ ignores an array key
114
+ with bang ignores an array key
115
+ uses splatted keys individually
116
+ with bank uses splatted keys individually
117
+ #extract
118
+ replaces the hash with only the given keys
119
+ leaves the hash empty if all keys are gone
120
+ gets values for all given keys even if missing
121
+ is OK when empty
122
+ returns an instance of the same class
123
+ assert_valid_keys
124
+ is true and does not raise when valid
125
+ fails when invalid
126
+ #delete
127
+ converts Symbol key into String before deleting
128
+ works with String keys as well
129
+ #merge
130
+ returns instance of DeepHash
131
+ merges in give Hash
132
+ #fetch
133
+ converts key before fetching
134
+ returns alternative value if key lookup fails
135
+ #values_at
136
+ is indifferent to whether keys are strings or symbols
137
+ #symbolize_keys
138
+ with bang returns the deep_hash itself
139
+ returns a dup of itself
140
+ #reverse_merge
141
+ merges defaults into options, creating a new hash
142
+ with bang merges! defaults into options, replacing options
143
+ #deep_merge!
144
+ merges two subhashes when they share a key
145
+ merges two subhashes when they share a symbolized key
146
+ preserves values in the original
147
+ replaces values from the given DeepHash
148
+ replaces values from the given DeepHash
149
+ #deep_set
150
+ should set a new value (single arg)
151
+ should set a new value (multiple args)
152
+ should replace an existing value (single arg)
153
+ should replace an existing value (multiple args)
154
+ should auto-vivify intermediate hashes
155
+ #deep_delete
156
+ should remove the key from the array (multiple args)
157
+ should remove the key from the array (multiple args)
158
+ should return the value if present (single args)
159
+ should return the value if present (multiple args)
160
+ should return nil if the key is absent (single arg)
161
+ should return nil if the key is absent (multiple args)
162
+
163
+ Configliere::Define
164
+ takes a description
165
+ defining any aspect of a param
166
+ adopts values
167
+ merges new definitions
168
+ lists params defined as the given aspect
169
+ definition_of
170
+ with a param, gives me the description hash
171
+ with a param and attr, gives me the description hash
172
+ symbolizes the param
173
+ has_definition?
174
+ is true if defined (one arg)
175
+ is false if not defined (one arg)
176
+ is true if defined and attribute is defined
177
+ is false if defined and attribute is defined
178
+ is false if not defined and attribute is given
179
+ type coercion
180
+ for boolean converts "0" to false
181
+ for boolean converts 0 to false
182
+ for boolean converts "" to false
183
+ for boolean converts [] to true
184
+ for boolean converts nil to nil
185
+ for boolean converts "1" to true
186
+ for boolean converts 1 to true
187
+ for boolean converts "5" to true
188
+ for boolean converts "true" to true
189
+ for Integer converts "5" to 5
190
+ for Integer converts 5 to 5
191
+ for Integer converts nil to nil
192
+ for Integer converts "" to nil
193
+ for Integer converts "5" to 5
194
+ for Integer converts 5 to 5
195
+ for Integer converts nil to nil
196
+ for Integer converts "" to nil
197
+ for Float converts "5.2" to 5.2
198
+ for Float converts 5.2 to 5.2
199
+ for Float converts nil to nil
200
+ for Float converts "" to nil
201
+ for Symbol converts "foo" to :foo
202
+ for Symbol converts :foo to :foo
203
+ for Symbol converts nil to nil
204
+ for Symbol converts "" to nil
205
+ for Date converts "1985-11-05" to #<Date: 1985-11-05 (4892749/2,0,2299161)>
206
+ for Date converts nil to nil
207
+ for Date converts "" to nil
208
+ for Date converts "blah" to nil
209
+ for DateTime converts "1985-11-05 11:00:00" to #<DateTime: 1985-11-05T11:00:00+00:00 (58712999/24,0/1,2299161)>
210
+ for DateTime converts nil to nil
211
+ for DateTime converts "" to nil
212
+ for DateTime converts "blah" to nil
213
+ for Array converts ["this", "that", "thother"] to ["this", "that", "thother"]
214
+ for Array converts "this,that,thother" to ["this", "that", "thother"]
215
+ for Array converts "alone" to ["alone"]
216
+ for Array converts "" to []
217
+ for Array converts nil to nil
218
+ for other converts "5" to "5"
219
+ for other converts 5 to 5
220
+ for other converts nil to nil
221
+ for other converts "" to nil
222
+ converts :now to the current moment
223
+ creates magical methods
224
+ answers to a getter if the param is defined
225
+ answers to a setter if the param is defined
226
+ does not answer to a getter if the param is not defined
227
+ does not answer to a setter if the param is not defined
228
+ defining requireds
229
+ lists required params
230
+ counts false values as present
231
+ counts nil-but-set values as missing
232
+ counts never-set values as missing
233
+ lists all missing values when it raises
234
+ defining deep keys
235
+ allows required params
236
+ allows flags
237
+ type converts
238
+ #resolve!
239
+ calls super and returns self
240
+
241
+ Configliere::Encrypted
242
+ defines encrypted params
243
+ with :encrypted => true
244
+ but not if :encrypted => false
245
+ only if :encrypted is given
246
+ the encrypt_pass
247
+ will take an environment variable if any exists
248
+ will take an internal value if given, and remove it
249
+ encrypts
250
+ all params with :encrypted
251
+ fails unless encrypt_pass is set
252
+ decrypts
253
+ all params marked encrypted
254
+ loading a file
255
+ encrypts
256
+ decrypts
257
+ #resolve!
258
+ calls super and returns self
259
+ removes the encrypt_pass from sight
260
+
261
+ Configliere::EnvVar
262
+ environment variables can be defined
263
+ with #env_vars, a simple value like "HOME" uses the corresponding key :home
264
+ with #env_vars, a hash pairs environment variables into the individual params
265
+ with #define
266
+ #resolve!
267
+ calls super and returns self
268
+
269
+ Configliere::Param
270
+ calling #defaults
271
+ deep_merges new params
272
+ returns self, to allow chaining
273
+ adding plugins with #use
274
+ requires the corresponding library
275
+ returns self, to allow chaining
276
+ invokes the on_use handler
277
+ #resolve!
278
+ calls super and returns self
279
+
280
+ Configliere::Prompt
281
+ when the value is already set, #prompt_for
282
+ returns the value
283
+ returns the value even if nil
284
+ returns the value even if nil
285
+ when prompting, #prompt_for
286
+ prompts for a value if missing
287
+ uses an explicit hint
288
+ uses the description as hint if none given
289
+ #resolve!
290
+ calls super and returns self
291
+
292
+ Configliere
293
+ creates a global variable Settings, for universality
294
+ creates a global method Settings, so you can say Settings(:foo => :bar)
295
+ requires corresponding plugins when you call use
296
+
297
+ Finished in 0.26971 seconds
298
+ 214 examples, 0 failures
data/Gemfile CHANGED
@@ -12,8 +12,7 @@ group :development do
12
12
  end
13
13
 
14
14
  group :development do
15
- # purely optional, used in the sample scripts
16
- gem 'gorillib', ">= 0.0.4"
15
+ # Only necessary if you want to use Configliere::Prompt
17
16
  gem 'highline', ">= 1.5.2"
18
17
  end
19
18
 
data/Gemfile.lock CHANGED
@@ -4,7 +4,6 @@ GEM
4
4
  RedCloth (4.2.7)
5
5
  diff-lcs (1.1.2)
6
6
  git (1.2.5)
7
- gorillib (0.0.7)
8
7
  highline (1.6.1)
9
8
  jeweler (1.5.2)
10
9
  bundler (~> 1.0.0)
@@ -42,7 +41,6 @@ PLATFORMS
42
41
  DEPENDENCIES
43
42
  RedCloth
44
43
  bundler (~> 1.0.12)
45
- gorillib (>= 0.0.4)
46
44
  highline (>= 1.5.2)
47
45
  jeweler (~> 1.5.2)
48
46
  rcov (>= 0.9.9)
data/README.textile CHANGED
@@ -331,14 +331,13 @@ All of the above examples use the global variable @Settings@, defined in configl
331
331
 
332
332
  <pre>
333
333
  class Wolfman
334
- attr_reader :config
335
- def self.config() @@config ; end
336
- self.config = Configliere::Param.new({
334
+ def config
335
+ @config ||= Configliere::Param.new.use(:commandline).defaults({
337
336
  :moon => 'full',
338
337
  :nards => true,
339
338
  })
339
+ end
340
340
  end
341
- Wolfman.use :commandline
342
341
 
343
342
  teen_wolf = Wolfman.new
344
343
  teen_wolf.config.defaults(:give_me => 'keg of beer')
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.4
1
+ 0.4.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.4.4"
8
+ s.version = "0.4.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["infochimps", "mrflip"]
12
- s.date = %q{2011-05-16}
12
+ s.date = %q{2011-05-18}
13
13
  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.
14
14
 
15
15
  "" So, Consigliere of mine, I think you should tell your Don what everyone knows. "" -- Don Corleone
@@ -26,6 +26,7 @@ Configliere manage settings from many sources: static constants, simple config f
26
26
  ".document",
27
27
  ".watchr",
28
28
  "CHANGELOG.textile",
29
+ "FEATURES.txt",
29
30
  "Gemfile",
30
31
  "Gemfile.lock",
31
32
  "LICENSE",
@@ -113,7 +114,6 @@ Configliere manage settings from many sources: static constants, simple config f
113
114
  s.add_development_dependency(%q<rspec>, ["~> 2.5.0"])
114
115
  s.add_development_dependency(%q<spork>, ["~> 0.9.0.rc5"])
115
116
  s.add_development_dependency(%q<RedCloth>, [">= 0"])
116
- s.add_development_dependency(%q<gorillib>, [">= 0.0.4"])
117
117
  s.add_development_dependency(%q<highline>, [">= 1.5.2"])
118
118
  else
119
119
  s.add_dependency(%q<bundler>, ["~> 1.0.12"])
@@ -122,7 +122,6 @@ Configliere manage settings from many sources: static constants, simple config f
122
122
  s.add_dependency(%q<rspec>, ["~> 2.5.0"])
123
123
  s.add_dependency(%q<spork>, ["~> 0.9.0.rc5"])
124
124
  s.add_dependency(%q<RedCloth>, [">= 0"])
125
- s.add_dependency(%q<gorillib>, [">= 0.0.4"])
126
125
  s.add_dependency(%q<highline>, [">= 1.5.2"])
127
126
  end
128
127
  else
@@ -132,7 +131,6 @@ Configliere manage settings from many sources: static constants, simple config f
132
131
  s.add_dependency(%q<rspec>, ["~> 2.5.0"])
133
132
  s.add_dependency(%q<spork>, ["~> 0.9.0.rc5"])
134
133
  s.add_dependency(%q<RedCloth>, [">= 0"])
135
- s.add_dependency(%q<gorillib>, [">= 0.0.4"])
136
134
  s.add_dependency(%q<highline>, [">= 1.5.2"])
137
135
  end
138
136
  end
@@ -1,22 +1,23 @@
1
1
  #!/usr/bin/env ruby
2
2
  $: << File.dirname(__FILE__)+'/../lib'
3
3
  require 'configliere'
4
- require 'gorillib/metaprogramming/class_attribute'
5
4
 
6
5
  class Wolfman
7
- class_attribute :config
8
- self.config = Configliere::Param.new.use(:commandline).defaults({
6
+ attr_accessor :config
7
+ def config
8
+ @config || = Configliere::Param.new.use(:commandline).defaults({
9
9
  :moon => 'full',
10
10
  :nards => true,
11
- })
11
+ })
12
+ end
12
13
  end
13
14
 
14
- Wolfman.config.description = 'Run this with commandline args: Wolfman uses them, Settings does not'
15
-
16
15
  teen_wolf = Wolfman.new
16
+
17
+ teen_wolf.config.description = 'Run this with commandline args: Wolfman uses them, Settings does not'
17
18
  teen_wolf.config.defaults(:give_me => 'keg of beer')
18
19
 
19
- Wolfman.config.resolve!
20
+ teen_wolf.config.resolve!
20
21
  Settings.resolve!
21
22
 
22
23
  # run this with ./examples/independent_config.rb --hi=there :
@@ -30,6 +30,7 @@ module Configliere
30
30
  self.env_vars param => pdefs[:env_var] if pdefs.include?(:env_var)
31
31
  self.finally(&pdefs[:finally]) if pdefs.include?(:finally)
32
32
  self.finally(&block) if block
33
+ self
33
34
  end
34
35
 
35
36
  # performs type coercion, continues up the resolve! chain
@@ -58,8 +59,9 @@ module Configliere
58
59
  public
59
60
 
60
61
  # Is the param defined?
61
- def has_definition? param
62
- definitions.has_key?(param.to_sym)
62
+ def has_definition?(param, attr=nil)
63
+ if attr then definitions.has_key?(param.to_sym) && definitions[param].has_key?(attr)
64
+ else definitions.has_key?(param.to_sym) end
63
65
  end
64
66
 
65
67
  # all params with a value for the given aspect
@@ -211,5 +211,13 @@ describe "Configliere::Commandline" do
211
211
  end
212
212
  end
213
213
 
214
- end
214
+ describe '#validate!' do
215
+ it 'calls super and returns self' do
216
+ Configliere::ParamParent.class_eval do def validate!() dummy ; end ; end
217
+ @config.should_receive(:dummy)
218
+ @config.validate!.should equal(@config)
219
+ Configliere::ParamParent.class_eval do def validate!() self ; end ; end
220
+ end
221
+ end
215
222
 
223
+ end
@@ -124,7 +124,6 @@ describe "Configliere::Commands" do
124
124
  end
125
125
  end
126
126
 
127
-
128
127
  describe '#resolve!' do
129
128
  it 'calls super and returns self' do
130
129
  Configliere::ParamParent.class_eval do def resolve!() dummy ; end ; end
@@ -134,5 +133,13 @@ describe "Configliere::Commands" do
134
133
  end
135
134
  end
136
135
 
137
- end
136
+ describe '#validate!' do
137
+ it 'calls super and returns self' do
138
+ Configliere::ParamParent.class_eval do def validate!() dummy ; end ; end
139
+ @config.should_receive(:dummy)
140
+ @config.validate!.should equal(@config)
141
+ Configliere::ParamParent.class_eval do def validate!() self ; end ; end
142
+ end
143
+ end
138
144
 
145
+ end
@@ -21,16 +21,21 @@ describe "Configliere::ConfigBlock" do
21
21
  @config.resolve!
22
22
  end
23
23
 
24
- describe '#resolve!' do
25
- it 'calls super and returns self' do
26
- Configliere::ParamParent.class_eval do def resolve!() dummy ; end ; end
27
- @config.should_receive(:dummy)
28
- @config.resolve!.should equal(@config)
29
- Configliere::ParamParent.class_eval do def resolve!() self ; end ; end
30
- end
24
+ it 'calls super and returns self' do
25
+ Configliere::ParamParent.class_eval do def resolve!() dummy ; end ; end
26
+ @config.should_receive(:dummy)
27
+ @config.resolve!.should equal(@config)
28
+ Configliere::ParamParent.class_eval do def resolve!() self ; end ; end
31
29
  end
32
30
  end
33
31
 
34
- end
35
-
32
+ describe '#validate!' do
33
+ it 'calls super and returns self' do
34
+ Configliere::ParamParent.class_eval do def validate!() dummy ; end ; end
35
+ @config.should_receive(:dummy)
36
+ @config.validate!.should equal(@config)
37
+ Configliere::ParamParent.class_eval do def validate!() self ; end ; end
38
+ end
39
+ end
36
40
 
41
+ end
@@ -17,15 +17,15 @@ describe Configliere::ConfigFile do
17
17
 
18
18
  describe 'successfully' do
19
19
  it 'with an absolute pathname uses it directly' do
20
- File.should_receive(:open).with('/fake/path.yaml').and_return(@fake_file)
20
+ File.should_receive(:open).with(%r{/fake/path.yaml}).and_return(@fake_file)
21
21
  @config.read '/fake/path.yaml'
22
22
  end
23
23
  it 'with a simple filename, references it to the default config dir' do
24
- File.should_receive(:open).with(Configliere::DEFAULT_CONFIG_DIR + '/file.yaml').and_return(@fake_file)
24
+ File.should_receive(:open).with(File.join(Configliere::DEFAULT_CONFIG_DIR, 'file.yaml')).and_return(@fake_file)
25
25
  @config.read 'file.yaml'
26
26
  end
27
27
  it 'returns the config object for chaining' do
28
- File.should_receive(:open).with(Configliere::DEFAULT_CONFIG_DIR + '/file.yaml').and_return(@fake_file)
28
+ File.should_receive(:open).with(File.join(Configliere::DEFAULT_CONFIG_DIR, 'file.yaml')).and_return(@fake_file)
29
29
  @config.defaults :also_a_param => true
30
30
  @config.read('file.yaml').should == { :my_param => 'val_from_file', :also_a_param => true }
31
31
  end
@@ -87,7 +87,7 @@ describe Configliere::ConfigFile do
87
87
  describe 'saves to a config file' do
88
88
  it 'with an absolute pathname, as given' do
89
89
  fake_file = StringIO.new('', 'w')
90
- File.should_receive(:open).with('/fake/path.yaml', 'w').and_yield(fake_file)
90
+ File.should_receive(:open).with(%r{/fake/path.yaml}, 'w').and_yield(fake_file)
91
91
  fake_file.should_receive(:<<).with("--- \n:my_param: default_val\n:also_a_param: true\n")
92
92
  @config.save! '/fake/path.yaml'
93
93
  end
@@ -101,7 +101,7 @@ describe Configliere::ConfigFile do
101
101
 
102
102
  it 'and ensures the directory exists' do
103
103
  fake_file = StringIO.new('', 'w')
104
- File.stub!(:open).with('/fake/path.yaml', 'w').and_yield(fake_file)
104
+ File.stub!(:open).with(%r{/fake/path.yaml}, 'w').and_yield(fake_file)
105
105
  FileUtils.should_receive(:mkdir_p).with('/fake')
106
106
  @config.save! '/fake/path.yaml'
107
107
  end
@@ -116,5 +116,13 @@ describe Configliere::ConfigFile do
116
116
  end
117
117
  end
118
118
 
119
- end
119
+ describe '#validate!' do
120
+ it 'calls super and returns self' do
121
+ Configliere::ParamParent.class_eval do def validate!() dummy ; end ; end
122
+ @config.should_receive(:dummy)
123
+ @config.validate!.should equal(@config)
124
+ Configliere::ParamParent.class_eval do def validate!() self ; end ; end
125
+ end
126
+ end
120
127
 
128
+ end
@@ -11,6 +11,11 @@ describe "Configliere::Define" do
11
11
  @config.definition_of(:simple).should == { :description => 'desc'}
12
12
  end
13
13
 
14
+ it 'returns self' do
15
+ ret_val = @config.define :simple, :description => 'desc'
16
+ ret_val.should equal(@config)
17
+ end
18
+
14
19
  it 'merges new definitions' do
15
20
  @config.define :described_in_steps, :description => 'desc 1'
16
21
  @config.define :described_in_steps, :description => 'desc 2'
@@ -49,12 +54,21 @@ describe "Configliere::Define" do
49
54
  before do
50
55
  @config.define :i_am_defined, :description => 'desc 1'
51
56
  end
52
- it 'is true if defined' do
57
+ it 'is true if defined (one arg)' do
53
58
  @config.has_definition?(:i_am_defined).should == true
54
59
  end
55
- it 'is false if not defined' do
60
+ it 'is false if not defined (one arg)' do
56
61
  @config.has_definition?(:i_am_not_defined).should == false
57
62
  end
63
+ it 'is true if defined and attribute is defined' do
64
+ @config.has_definition?(:i_am_defined, :description).should == true
65
+ end
66
+ it 'is false if defined and attribute is defined' do
67
+ @config.has_definition?(:i_am_defined, :zoink).should == false
68
+ end
69
+ it 'is false if not defined and attribute is given' do
70
+ @config.has_definition?(:i_am_not_defined, :zoink).should == false
71
+ end
58
72
  end
59
73
 
60
74
  it 'takes a description' do
@@ -85,14 +99,14 @@ describe "Configliere::Define" do
85
99
  @config[:has_type] = orig ; @config.resolve! ; @config[:has_type].should == desired
86
100
  end
87
101
  end
88
- # it 'converts :now to the current moment' do
89
- # @config.define :has_type, :type => DateTime
90
- # @config[:has_type] = 'now' ; @config.resolve! ; @config[:has_type].should be_within(4).of(DateTime.now, 4)
91
- # @config[:has_type] = :now ; @config.resolve! ; @config[:has_type].should be_within(4).of(DateTime.now, 4)
92
- # @config.define :has_type, :type => Date
93
- # @config[:has_type] = :now ; @config.resolve! ; @config[:has_type].should be_within(4).of(Date.today, 4)
94
- # @config[:has_type] = 'now' ; @config.resolve! ; @config[:has_type].should be_within(4).of(Date.today, 4)
95
- # end
102
+ it 'converts :now to the current moment' do
103
+ @config.define :has_type, :type => DateTime
104
+ @config[:has_type] = 'now' ; @config.resolve! ; @config[:has_type].should be_within(4).of(DateTime.now)
105
+ @config[:has_type] = :now ; @config.resolve! ; @config[:has_type].should be_within(4).of(DateTime.now)
106
+ @config.define :has_type, :type => Date
107
+ @config[:has_type] = :now ; @config.resolve! ; @config[:has_type].should be_within(4).of(Date.today)
108
+ @config[:has_type] = 'now' ; @config.resolve! ; @config[:has_type].should be_within(4).of(Date.today)
109
+ end
96
110
  end
97
111
 
98
112
  describe 'creates magical methods' do
@@ -182,5 +196,12 @@ describe "Configliere::Define" do
182
196
  end
183
197
  end
184
198
 
199
+ describe '#validate!' do
200
+ it 'calls super and returns self' do
201
+ Configliere::ParamParent.class_eval do def validate!() dummy ; end ; end
202
+ @config.should_receive(:dummy)
203
+ @config.validate!.should equal(@config)
204
+ Configliere::ParamParent.class_eval do def validate!() self ; end ; end
205
+ end
206
+ end
185
207
  end
186
-
@@ -101,4 +101,13 @@ describe "Configliere::Encrypted" do
101
101
  end
102
102
  end
103
103
 
104
+ describe '#validate!' do
105
+ it 'calls super and returns self' do
106
+ Configliere::ParamParent.class_eval do def validate!() dummy ; end ; end
107
+ @config.should_receive(:dummy)
108
+ @config.validate!.should equal(@config)
109
+ Configliere::ParamParent.class_eval do def validate!() self ; end ; end
110
+ end
111
+ end
112
+
104
113
  end
@@ -40,5 +40,14 @@ describe "Configliere::EnvVar" do
40
40
  end
41
41
  end
42
42
 
43
+ describe '#validate!' do
44
+ it 'calls super and returns self' do
45
+ Configliere::ParamParent.class_eval do def validate!() dummy ; end ; end
46
+ @config.should_receive(:dummy)
47
+ @config.validate!.should equal(@config)
48
+ Configliere::ParamParent.class_eval do def validate!() self ; end ; end
49
+ end
50
+ end
51
+
43
52
  end
44
53
 
@@ -47,4 +47,3 @@ describe "Configliere::Prompt" do
47
47
  end
48
48
 
49
49
  end
50
-
data/spec/spec_helper.rb CHANGED
@@ -12,6 +12,8 @@ Spork.prefork do
12
12
 
13
13
  require 'configliere'
14
14
 
15
+ RSpec.configure do |config|
16
+ end
15
17
  end
16
18
 
17
19
  Spork.each_run do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: configliere
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.4
5
+ version: 0.4.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - infochimps
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-05-16 00:00:00 -05:00
14
+ date: 2011-05-18 00:00:00 -05:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -80,20 +80,9 @@ dependencies:
80
80
  type: :development
81
81
  prerelease: false
82
82
  version_requirements: *id006
83
- - !ruby/object:Gem::Dependency
84
- name: gorillib
85
- requirement: &id007 !ruby/object:Gem::Requirement
86
- none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: 0.0.4
91
- type: :development
92
- prerelease: false
93
- version_requirements: *id007
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: highline
96
- requirement: &id008 !ruby/object:Gem::Requirement
85
+ requirement: &id007 !ruby/object:Gem::Requirement
97
86
  none: false
98
87
  requirements:
99
88
  - - ">="
@@ -101,7 +90,7 @@ dependencies:
101
90
  version: 1.5.2
102
91
  type: :development
103
92
  prerelease: false
104
- version_requirements: *id008
93
+ version_requirements: *id007
105
94
  description: " 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.\n\n \"\" So, Consigliere of mine, I think you should tell your Don what everyone knows. \"\" -- Don Corleone\n\n\
106
95
  Configliere manage settings from many sources: static constants, simple config files, environment variables, commandline options, straight ruby. You don't have to predefine anything, but you can ask configliere to type-convert, require, document or password-obscure any of its fields. Modules can define config settings independently of each other and the main program.\n"
107
96
  email: coders@infochimps.org
@@ -122,6 +111,7 @@ files:
122
111
  - .document
123
112
  - .watchr
124
113
  - CHANGELOG.textile
114
+ - FEATURES.txt
125
115
  - Gemfile
126
116
  - Gemfile.lock
127
117
  - LICENSE
@@ -184,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
174
  requirements:
185
175
  - - ">="
186
176
  - !ruby/object:Gem::Version
187
- hash: -4529011985775181084
177
+ hash: -3183115947293832895
188
178
  segments:
189
179
  - 0
190
180
  version: "0"