configurability 3.0.0.pre20161130173417 → 3.0.0.pre20161130174408
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +3 -2
- data/lib/configurability.rb +2 -2
- data/lib/configurability/{deferredconfig.rb → deferred_config.rb} +1 -1
- data/lib/configurability/setting_installer.rb +68 -0
- data/spec/configurability/{deferredconfig_spec.rb → deferred_config_spec.rb} +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea686c0c69488500b5a99766adb8d47a71415a7d
|
4
|
+
data.tar.gz: 22c502b78fe24a6c29c0b7e2f24a556cf15bb4a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa983d829f75746d680966e050c1f7ef76e826439c7892deca3715397f75984cfce0017cc68419d9155fdfee13dad38ad242e096319704383c3600ebd9d8e78f
|
7
|
+
data.tar.gz: e285d94730abc2a40cbc7200136c3bdaf22d359f9185f47072f584576aeb5f094a4b5b1f4449166f804f9a5a2832eb5a17ead825d05ebad56d08d01cf081409d
|
data/Manifest.txt
CHANGED
@@ -10,8 +10,9 @@ examples/config.yml
|
|
10
10
|
lib/configurability.rb
|
11
11
|
lib/configurability/behavior.rb
|
12
12
|
lib/configurability/config.rb
|
13
|
-
lib/configurability/
|
13
|
+
lib/configurability/deferred_config.rb
|
14
|
+
lib/configurability/setting_installer.rb
|
14
15
|
spec/configurability/config_spec.rb
|
15
|
-
spec/configurability/
|
16
|
+
spec/configurability/deferred_config_spec.rb
|
16
17
|
spec/configurability_spec.rb
|
17
18
|
spec/helpers.rb
|
data/lib/configurability.rb
CHANGED
@@ -21,9 +21,9 @@ module Configurability
|
|
21
21
|
VERSION = '3.0.0'
|
22
22
|
|
23
23
|
# Version-control revision constant
|
24
|
-
REVISION = %q$Revision:
|
24
|
+
REVISION = %q$Revision: 5d62053ab7f8 $
|
25
25
|
|
26
|
-
require 'configurability/
|
26
|
+
require 'configurability/deferred_config'
|
27
27
|
|
28
28
|
autoload :Config, 'configurability/config'
|
29
29
|
autoload :SettingInstaller, 'configurability/setting_installer'
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
#encoding: utf-8
|
3
|
+
|
4
|
+
require 'loggability'
|
5
|
+
require 'configurability' unless defined?( Configurability )
|
6
|
+
|
7
|
+
|
8
|
+
# Methods for declaring config methods and constants inside a `configurability`
|
9
|
+
# block.
|
10
|
+
class Configurability::SettingInstaller
|
11
|
+
extend Loggability
|
12
|
+
|
13
|
+
log_to :configurability
|
14
|
+
|
15
|
+
|
16
|
+
### Create a new Generator that can be used to add configuration methods and
|
17
|
+
### constants to the specified +target+ object.
|
18
|
+
def initialize( target )
|
19
|
+
@target = target
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
##
|
24
|
+
# The target object
|
25
|
+
attr_reader :target
|
26
|
+
|
27
|
+
|
28
|
+
### Declare a config setting with the specified +name+.
|
29
|
+
def setting( name, **options )
|
30
|
+
self.log.debug " adding %s setting to %p" % [ name, self.target ]
|
31
|
+
self.add_setting_accessors( name, options )
|
32
|
+
self.add_default( name, options )
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
#########
|
37
|
+
protected
|
38
|
+
#########
|
39
|
+
|
40
|
+
### Add accessors with the specified +name+ to the target.
|
41
|
+
def add_setting_accessors( name, options )
|
42
|
+
reader = lambda { self.instance_variable_get("@#{name}") }
|
43
|
+
writer = lambda {|value| self.instance_variable_set("@#{name}", value) }
|
44
|
+
|
45
|
+
self.target.define_singleton_method( "#{name}", &reader )
|
46
|
+
self.target.define_singleton_method( "#{name}=", &writer )
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
### Add a default for +name+ to the CONFIG_DEFAULTS constant of the target, creating
|
51
|
+
### it if necessary.
|
52
|
+
def add_default( name, options )
|
53
|
+
default_value = options[ :default ]
|
54
|
+
|
55
|
+
self.target.instance_variable_set( "@#{name}", default_value )
|
56
|
+
if self.target.respond_to?( :const_defined? )
|
57
|
+
defaults = if self.target.const_defined?( :CONFIG_DEFAULTS )
|
58
|
+
self.target.const_get( :CONFIG_DEFAULTS )
|
59
|
+
else
|
60
|
+
self.target.const_set( :CONFIG_DEFAULTS, {} )
|
61
|
+
end
|
62
|
+
|
63
|
+
defaults.store( name, default_value )
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end # module Configurability::SettingInstaller
|
68
|
+
|
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.0.
|
4
|
+
version: 3.0.0.pre20161130174408
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Granger
|
@@ -178,9 +178,10 @@ files:
|
|
178
178
|
- lib/configurability.rb
|
179
179
|
- lib/configurability/behavior.rb
|
180
180
|
- lib/configurability/config.rb
|
181
|
-
- lib/configurability/
|
181
|
+
- lib/configurability/deferred_config.rb
|
182
|
+
- lib/configurability/setting_installer.rb
|
182
183
|
- spec/configurability/config_spec.rb
|
183
|
-
- spec/configurability/
|
184
|
+
- spec/configurability/deferred_config_spec.rb
|
184
185
|
- spec/configurability_spec.rb
|
185
186
|
- spec/helpers.rb
|
186
187
|
homepage: http://deveiate.org/projects/configurability
|