configurability 1.0.5 → 1.0.6
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.tar.gz.sig +3 -1
- data/History.md +8 -0
- data/Rakefile +2 -1
- data/lib/configurability.rb +2 -2
- data/lib/configurability/config.rb +4 -2
- data/spec/configurability/config_spec.rb +40 -18
- data/spec/lib/helpers.rb +4 -0
- metadata +22 -7
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
data/History.md
CHANGED
data/Rakefile
CHANGED
data/lib/configurability.rb
CHANGED
@@ -9,10 +9,10 @@ require 'yaml'
|
|
9
9
|
module Configurability
|
10
10
|
|
11
11
|
# Library version constant
|
12
|
-
VERSION = '1.0.
|
12
|
+
VERSION = '1.0.6'
|
13
13
|
|
14
14
|
# Version-control revision constant
|
15
|
-
REVISION = %q$Revision:
|
15
|
+
REVISION = %q$Revision: 631fd470522c $
|
16
16
|
|
17
17
|
require 'configurability/logformatter'
|
18
18
|
require 'configurability/deferredconfig'
|
@@ -458,8 +458,10 @@ class Configurability::Config
|
|
458
458
|
### Returns +true+ if the given +name+ is the name of a member of
|
459
459
|
### the receiver.
|
460
460
|
def member?( name )
|
461
|
-
|
461
|
+
name = name.to_sym if name.respond_to?( :to_sym )
|
462
|
+
return @hash.key?( name )
|
462
463
|
end
|
464
|
+
alias_method :has_member?, :member?
|
463
465
|
|
464
466
|
|
465
467
|
### Merge the specified +other+ object with this config struct. The
|
@@ -544,7 +546,7 @@ class Configurability::Config
|
|
544
546
|
### @param [Symbol] key the config key to create the predicate method body for
|
545
547
|
### @return [Proc] the body of the new method
|
546
548
|
def create_member_predicate( key )
|
547
|
-
return lambda { self[key] ? true : false }
|
549
|
+
return lambda { self.member?( key ) && self[key] ? true : false }
|
548
550
|
end
|
549
551
|
|
550
552
|
|
@@ -93,25 +93,47 @@ describe Configurability::Config do
|
|
93
93
|
config[:section]['subsection'][:subsubsection].should == 'value'
|
94
94
|
end
|
95
95
|
|
96
|
+
it "autoloads predicates for its members" do
|
97
|
+
config = Configurability::Config.new( TEST_CONFIG )
|
98
|
+
config.mergekey?.should be_true()
|
99
|
+
config.mergemonkey?.should be_false()
|
100
|
+
config.section?.should be_true()
|
101
|
+
config.section.subsection?.should be_true()
|
102
|
+
config.section.subsection.subsubsection?.should be_true()
|
103
|
+
config.section.monkeysubsection?.should be_false()
|
104
|
+
end
|
96
105
|
|
97
|
-
NIL_KEY_CONFIG = %{
|
98
|
-
---
|
99
|
-
trap_on:
|
100
|
-
"low disk space alert":
|
101
|
-
~:
|
102
|
-
notepad:
|
103
|
-
patterns:
|
104
|
-
- pattern1
|
105
|
-
- pattern2
|
106
|
-
}.gsub(/^\t/, '')
|
107
106
|
|
108
|
-
|
109
|
-
|
110
|
-
|
107
|
+
context "a config with nil keys" do
|
108
|
+
|
109
|
+
NIL_KEY_CONFIG = %{
|
110
|
+
---
|
111
|
+
trap_on:
|
112
|
+
"low disk space alert":
|
113
|
+
~:
|
114
|
+
notepad:
|
115
|
+
patterns:
|
116
|
+
- pattern1
|
117
|
+
- pattern2
|
118
|
+
}.gsub(/^\t{2}/, '')
|
119
|
+
|
120
|
+
before( :each ) do
|
121
|
+
@config = Configurability::Config.new( NIL_KEY_CONFIG )
|
122
|
+
end
|
123
|
+
|
124
|
+
it "doesn't raise a NoMethodError when loading (issue #1)" do
|
125
|
+
@config[:trap_on]['low disk space alert'][nil][:notepad][:patterns].
|
126
|
+
should == [ 'pattern1', 'pattern2' ]
|
127
|
+
end
|
128
|
+
|
129
|
+
it "knows that it has a nil member" do
|
130
|
+
@config[:trap_on]['low disk space alert'].should have_member( nil )
|
131
|
+
end
|
132
|
+
|
111
133
|
end
|
112
134
|
|
113
135
|
|
114
|
-
|
136
|
+
context "created with in-memory YAML source" do
|
115
137
|
|
116
138
|
before(:each) do
|
117
139
|
@config = Configurability::Config.new( TEST_CONFIG )
|
@@ -183,7 +205,7 @@ describe Configurability::Config do
|
|
183
205
|
|
184
206
|
|
185
207
|
# saving if changed since loaded
|
186
|
-
|
208
|
+
context " whose internal values have been changed since loaded" do
|
187
209
|
before(:each) do
|
188
210
|
@config = Configurability::Config.new( TEST_CONFIG )
|
189
211
|
@config.section.subsection.anothersection = 11451
|
@@ -203,7 +225,7 @@ describe Configurability::Config do
|
|
203
225
|
|
204
226
|
|
205
227
|
# loading from a file
|
206
|
-
|
228
|
+
context " loaded from a file" do
|
207
229
|
before(:all) do
|
208
230
|
@tmpfile = Tempfile.new( 'test.conf', '.' )
|
209
231
|
@tmpfile.print( TEST_CONFIG )
|
@@ -265,7 +287,7 @@ describe Configurability::Config do
|
|
265
287
|
|
266
288
|
|
267
289
|
# reload if file changes
|
268
|
-
|
290
|
+
context " whose file changes after loading" do
|
269
291
|
before(:all) do
|
270
292
|
@tmpfile = Tempfile.new( 'test.conf', '.' )
|
271
293
|
@tmpfile.print( TEST_CONFIG )
|
@@ -310,7 +332,7 @@ describe Configurability::Config do
|
|
310
332
|
|
311
333
|
|
312
334
|
# merging
|
313
|
-
|
335
|
+
context " created by merging two other configs" do
|
314
336
|
before(:each) do
|
315
337
|
@config1 = Configurability::Config.new
|
316
338
|
@config2 = Configurability::Config.new( TEST_CONFIG )
|
data/spec/lib/helpers.rb
CHANGED
@@ -10,12 +10,16 @@ BEGIN {
|
|
10
10
|
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
11
11
|
}
|
12
12
|
|
13
|
+
require 'simplecov'
|
13
14
|
require 'rspec'
|
14
15
|
|
15
16
|
require 'logger'
|
16
17
|
require 'erb'
|
17
18
|
require 'yaml'
|
18
19
|
|
20
|
+
SimpleCov.start do
|
21
|
+
add_filter '/spec/'
|
22
|
+
end
|
19
23
|
require 'configurability'
|
20
24
|
|
21
25
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configurability
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 6
|
10
|
+
version: 1.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Granger
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
cmlhXe46pZNJgWKbxZah85jIjx95hR8vOI+NAM5iH9kOqK13DrxacTKPhqj5PjwF
|
36
36
|
-----END CERTIFICATE-----
|
37
37
|
|
38
|
-
date: 2011-
|
38
|
+
date: 2011-03-03 00:00:00 -08:00
|
39
39
|
default_executable:
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -86,9 +86,24 @@ dependencies:
|
|
86
86
|
type: :development
|
87
87
|
version_requirements: *id003
|
88
88
|
- !ruby/object:Gem::Dependency
|
89
|
-
name:
|
89
|
+
name: simplecov
|
90
90
|
prerelease: false
|
91
91
|
requirement: &id004 !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 13
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
- 3
|
100
|
+
version: "0.3"
|
101
|
+
type: :development
|
102
|
+
version_requirements: *id004
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: hoe
|
105
|
+
prerelease: false
|
106
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
92
107
|
none: false
|
93
108
|
requirements:
|
94
109
|
- - ">="
|
@@ -100,7 +115,7 @@ dependencies:
|
|
100
115
|
- 0
|
101
116
|
version: 2.9.0
|
102
117
|
type: :development
|
103
|
-
version_requirements: *
|
118
|
+
version_requirements: *id005
|
104
119
|
description: |-
|
105
120
|
Configurability is a mixin that allows you to add configurability to one or
|
106
121
|
more objects or classes. You can assign them each a subsection of the
|
@@ -168,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
183
|
requirements: []
|
169
184
|
|
170
185
|
rubyforge_project: configurability
|
171
|
-
rubygems_version: 1.
|
186
|
+
rubygems_version: 1.6.0
|
172
187
|
signing_key:
|
173
188
|
specification_version: 3
|
174
189
|
summary: Configurability is a mixin that allows you to add configurability to one or more objects or classes
|
metadata.gz.sig
CHANGED
Binary file
|