configurability 3.0.0 → 3.1.0.pre20170103085451
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +5 -0
- data/Rakefile +1 -1
- data/lib/configurability/setting_installer.rb +7 -4
- data/spec/configurability_spec.rb +20 -0
- metadata +6 -7
- metadata.gz.sig +0 -0
- data/LICENSE +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d81fc141d010af20dd5d7b78114d0c316f07b240
|
4
|
+
data.tar.gz: 6445f4fbbd81ef3b4fe3e8d4bac88cbad4e86602
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b387ba4d2f378713a7a497d2db633395dc4dcb5d0a9d35dc9b1da5ed5d0ef45e2b3f9419d234e155f93bc33a222805cd589c438585ac74d19d12213f132ed76f
|
7
|
+
data.tar.gz: d3b1fdbed90c63b0e073a372f6ee67ad80f43bd8b97ef1a718c70204b05cbe694fbffece4531a1f014aa4be3e11a085e307dbf2b0548881479dcb12e286ff8e6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -74,6 +74,9 @@ some settings:
|
|
74
74
|
setting :url, default: 'sqlite:/'
|
75
75
|
setting :user
|
76
76
|
setting :password
|
77
|
+
setting :port do |value|
|
78
|
+
Integer( value )
|
79
|
+
end
|
77
80
|
end
|
78
81
|
end
|
79
82
|
|
@@ -82,6 +85,8 @@ three subkey settings under it (with getters and setters) to the class. It also
|
|
82
85
|
adds a `configure` class method that will set whichever of the settings are
|
83
86
|
passed to it, defaulting the `url` to the provided value if it's not given.
|
84
87
|
|
88
|
+
The `setting` can include a block which is given the config value before it's set; from this block you can do validity-checking, cast it to something other than a String, etc. The new value will be set to the return value of the block.
|
89
|
+
|
85
90
|
If your config file (e.g., `config.yml`) looks like this:
|
86
91
|
|
87
92
|
--
|
data/Rakefile
CHANGED
@@ -31,7 +31,7 @@ hoespec = Hoe.spec 'configurability' do |spec|
|
|
31
31
|
spec.developer 'Michael Granger', 'ged@FaerieMUD.org'
|
32
32
|
spec.developer 'Mahlon E. Smith', 'mahlon@martini.nu'
|
33
33
|
|
34
|
-
spec.dependency 'loggability', '~> 0.
|
34
|
+
spec.dependency 'loggability', '~> 0.12'
|
35
35
|
|
36
36
|
spec.dependency 'hoe-deveiate', '~> 0.8', :developer
|
37
37
|
spec.dependency 'simplecov', '~> 0.12', :developer
|
@@ -26,9 +26,9 @@ class Configurability::SettingInstaller
|
|
26
26
|
|
27
27
|
|
28
28
|
### Declare a config setting with the specified +name+.
|
29
|
-
def setting( name, **options )
|
29
|
+
def setting( name, **options, &block )
|
30
30
|
self.log.debug " adding %s setting to %p" % [ name, self.target ]
|
31
|
-
self.add_setting_accessors( name, options )
|
31
|
+
self.add_setting_accessors( name, options, &block )
|
32
32
|
self.add_default( name, options )
|
33
33
|
end
|
34
34
|
|
@@ -38,9 +38,12 @@ class Configurability::SettingInstaller
|
|
38
38
|
#########
|
39
39
|
|
40
40
|
### Add accessors with the specified +name+ to the target.
|
41
|
-
def add_setting_accessors( name, options )
|
41
|
+
def add_setting_accessors( name, options, &writer_hook )
|
42
42
|
reader = lambda { self.instance_variable_get("@#{name}") }
|
43
|
-
writer = lambda
|
43
|
+
writer = lambda do |value|
|
44
|
+
value = writer_hook[ value ] if writer_hook
|
45
|
+
self.instance_variable_set( "@#{name}", value )
|
46
|
+
end
|
44
47
|
|
45
48
|
self.target.define_singleton_method( "#{name}", &reader )
|
46
49
|
self.target.define_singleton_method( "#{name}=", &writer )
|
@@ -630,6 +630,26 @@ describe Configurability do
|
|
630
630
|
expect( mod.apikey ).to eq( 'jofRtkw&QzCoukGwAWDMjyTkQzWnCXhhgEs' )
|
631
631
|
end
|
632
632
|
|
633
|
+
|
634
|
+
it "can declare settings with a block to do writer pre-processing" do
|
635
|
+
mod.configurability( :testconfig ) do
|
636
|
+
setting :data_dir do |dir|
|
637
|
+
Pathname( dir )
|
638
|
+
end
|
639
|
+
setting :apikey do |key|
|
640
|
+
raise "Invalid API key!" unless key.to_s =~ /\A\p{Xdigit}{32}\z/
|
641
|
+
key
|
642
|
+
end
|
643
|
+
end
|
644
|
+
|
645
|
+
expect {
|
646
|
+
mod.data_dir = 'var/data'
|
647
|
+
}.to change { mod.data_dir }.to( Pathname('var/data') )
|
648
|
+
expect {
|
649
|
+
mod.apikey = 'something'
|
650
|
+
}.to raise_error( /Invalid API key/i )
|
651
|
+
end
|
652
|
+
|
633
653
|
end
|
634
654
|
|
635
655
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configurability
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.1.0.pre20170103085451
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Granger
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
w8aNA5re5+Rt/Vvjxj5AcEnZnZiz5x959NaddQocX32Z1unHw44pzRNUur1GInfW
|
37
37
|
p4vpx2kUSFSAGjtCbDGTNV2AH8w9OU4xEmNz8c5lyoA=
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date:
|
39
|
+
date: 2017-01-03 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: loggability
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.12'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.12'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: hoe-mercurial
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -169,7 +169,6 @@ extra_rdoc_files:
|
|
169
169
|
files:
|
170
170
|
- ChangeLog
|
171
171
|
- History.md
|
172
|
-
- LICENSE
|
173
172
|
- Manifest.txt
|
174
173
|
- README.md
|
175
174
|
- Rakefile
|
@@ -203,9 +202,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
203
202
|
version: 2.2.0
|
204
203
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
204
|
requirements:
|
206
|
-
- - "
|
205
|
+
- - ">"
|
207
206
|
- !ruby/object:Gem::Version
|
208
|
-
version:
|
207
|
+
version: 1.3.1
|
209
208
|
requirements: []
|
210
209
|
rubyforge_project:
|
211
210
|
rubygems_version: 2.6.8
|
metadata.gz.sig
CHANGED
Binary file
|
data/LICENSE
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
Copyright (c) 2010-2016 Michael Granger and Mahlon E. Smith
|
2
|
-
All rights reserved.
|
3
|
-
|
4
|
-
Redistribution and use in source and binary forms, with or without
|
5
|
-
modification, are permitted provided that the following conditions are met:
|
6
|
-
|
7
|
-
* Redistributions of source code must retain the above copyright notice,
|
8
|
-
this list of conditions and the following disclaimer.
|
9
|
-
|
10
|
-
* Redistributions in binary form must reproduce the above copyright notice,
|
11
|
-
this list of conditions and the following disclaimer in the documentation
|
12
|
-
and/or other materials provided with the distribution.
|
13
|
-
|
14
|
-
* Neither the name of the author/s, nor the names of the project's
|
15
|
-
contributors may be used to endorse or promote products derived from this
|
16
|
-
software without specific prior written permission.
|
17
|
-
|
18
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
22
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|