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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cdda9756d722c65fc10d9daef86b1a8b24b6f0b3
4
- data.tar.gz: bbba39ce6a30c45b3bd8bd736486b65702337be3
3
+ metadata.gz: ea686c0c69488500b5a99766adb8d47a71415a7d
4
+ data.tar.gz: 22c502b78fe24a6c29c0b7e2f24a556cf15bb4a1
5
5
  SHA512:
6
- metadata.gz: 265346355eecc8119e2f900e2f21aff8decd862987f967d33b4cbf2cedd4e60171728be8fd6017f5d0cf8de78680cfd48e1696a04b71c0b11b694bc99f696d10
7
- data.tar.gz: cbc94bf49fad752417c23295a1c8df00d01158f510ae38527f32e9b3577aa32eadc741163969d6c77e8d1f24555ca388560231015ac6a19169e698c833945bb3
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/deferredconfig.rb
13
+ lib/configurability/deferred_config.rb
14
+ lib/configurability/setting_installer.rb
14
15
  spec/configurability/config_spec.rb
15
- spec/configurability/deferredconfig_spec.rb
16
+ spec/configurability/deferred_config_spec.rb
16
17
  spec/configurability_spec.rb
17
18
  spec/helpers.rb
@@ -21,9 +21,9 @@ module Configurability
21
21
  VERSION = '3.0.0'
22
22
 
23
23
  # Version-control revision constant
24
- REVISION = %q$Revision: 09ad0e4eb93c $
24
+ REVISION = %q$Revision: 5d62053ab7f8 $
25
25
 
26
- require 'configurability/deferredconfig'
26
+ require 'configurability/deferred_config'
27
27
 
28
28
  autoload :Config, 'configurability/config'
29
29
  autoload :SettingInstaller, 'configurability/setting_installer'
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby -wKU
2
2
 
3
- require 'configurability'
3
+ require 'configurability' unless defined?( Configurability )
4
4
 
5
5
 
6
6
  # Mixin that can be applied to classes to cause them to configure themselves
@@ -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
+
@@ -8,7 +8,7 @@ require 'fileutils'
8
8
  require 'rspec'
9
9
 
10
10
  require 'configurability'
11
- require 'configurability/deferredconfig'
11
+ require 'configurability/deferred_config'
12
12
 
13
13
 
14
14
  #####################################################################
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.pre20161130173417
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/deferredconfig.rb
181
+ - lib/configurability/deferred_config.rb
182
+ - lib/configurability/setting_installer.rb
182
183
  - spec/configurability/config_spec.rb
183
- - spec/configurability/deferredconfig_spec.rb
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