configurability 2.3.0.pre20161121123955 → 3.0.0.pre20161123172826

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: 470dde9269109d507424b3459e90e86f5dca7bce
4
- data.tar.gz: 8c3ac3e698ab18ff6783c2c0c7afe2b333de8234
3
+ metadata.gz: 312a9f359af2205c1d19680cdbf9d78dccffabbd
4
+ data.tar.gz: 04da93e50487652b33a29533d8bce47bdd6d45eb
5
5
  SHA512:
6
- metadata.gz: 5ba7e4bb087da76a09937c1eb655e02a41aed364c8ead62e95e6d87210143b94d23979c7636ea82c4b31e7391d0da6803093e4b8572a49ae9d6f302414f27312
7
- data.tar.gz: b770a6f29e6703a0c16ccc0c56896e49e34fff4fe5ebc2eacca5533dbbab04e99879c18b65af101b7045a1b891ca77acf98412499e2e3ebd7a92305ee4aeb6b0
6
+ metadata.gz: fa298908a7f0a5c1204397e94e31b9c3292f045133b36e0c61c8f9d94065e371c3b7e7f53ca15f85d4902765f6b43d40f3b35fa71344a6e4edae10082f2a58de
7
+ data.tar.gz: 30c3d90e89cc257107f60d5eb7097508ad820b03caa3c23453f2ed384b5c8efd828d169f440c7f7850a8a9820108d89a5e1ac66fecb85509c946ed9f2f6b280a
@@ -1,3 +1,14 @@
1
+ == v3.0.0 [2016-11-23] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ Enhancement:
4
+
5
+ - Add hierarchical config keys.
6
+
7
+
8
+ == v2.2.2 [2016-09-28] Michael Granger <ged@FaerieMUD.org>
9
+
10
+ - Added signature for changeset 806d1f512f55
11
+
1
12
  == v2.2.2 [2016-09-28] Michael Granger <ged@FaerieMUD.org>
2
13
 
3
14
  - Fix the merge used by Configurability.gather_defaults
data/Manifest.txt CHANGED
@@ -1,8 +1,8 @@
1
1
  ChangeLog
2
- History.rdoc
2
+ History.md
3
3
  LICENSE
4
4
  Manifest.txt
5
- README.rdoc
5
+ README.md
6
6
  Rakefile
7
7
  bin/configurability
8
8
  examples/basicconfig.rb
@@ -1,12 +1,20 @@
1
- = Configurability
1
+ # Configurability
2
2
 
3
- home :: https://bitbucket.org/ged/configurability
4
- code :: https://bitbucket.org/ged/configurability
5
- docs :: http://deveiate.org/code/configurability
6
- github :: https://github.com/ged/configurability
3
+ home
4
+ : https://bitbucket.org/ged/configurability
7
5
 
6
+ code
7
+ : https://bitbucket.org/ged/configurability
8
8
 
9
- == Description
9
+ docs
10
+ : http://deveiate.org/code/configurability
11
+
12
+ github
13
+ : https://github.com/ged/configurability
14
+
15
+
16
+
17
+ ## Description
10
18
 
11
19
  Configurability is a unified, unintrusive, assume-nothing configuration system
12
20
  for Ruby. It lets you keep the configuration for multiple objects in a single
@@ -16,12 +24,12 @@ single action.
16
24
 
17
25
 
18
26
 
19
- == Installation
27
+ ## Installation
20
28
 
21
29
  gem install configurability
22
30
 
23
31
 
24
- == Usage
32
+ ## Usage
25
33
 
26
34
  To add configurability to a class, just require the library and extend
27
35
  the class:
@@ -68,14 +76,20 @@ When the configuration is loaded, an instance variable called `@config` is set
68
76
  to the appropriate section of the config object for each object that has
69
77
  been extended with Configurability.
70
78
 
79
+ As you add more objects to your configuration, it may be useful to group
80
+ related sections together. You can specify that your object's configuration
81
+ is part of a group by prepending the name of the group to your config key
82
+ separated by a double underscore (`__`)
83
+
71
84
 
72
- == Customization
85
+ ## Customization
73
86
 
74
87
  The default behavior above is just provided as a reasonable default; it is
75
88
  expected that you'll want to customize at least one or two things about
76
89
  how configuration is handled in your objects.
77
90
 
78
- === Setting a Custom Config Key
91
+
92
+ ### Setting a Custom Config Key
79
93
 
80
94
  The first thing you might want to do is change the config section that
81
95
  corresponds to your object. You can do that by declaring a different
@@ -96,10 +110,8 @@ as a Symbol:
96
110
  end
97
111
  end
98
112
 
99
- === Changing How an Object Is Configured
100
113
 
101
- [:FIXME:] Explain the 'at least once' configuration call, and how to handle
102
- being called with 'nil'.
114
+ ### Changing How an Object Is Configured
103
115
 
104
116
  You can also change what happens when an object is configured by implementing
105
117
  a `#configure` method that takes the config section as an argument:
@@ -119,7 +131,7 @@ If you still want the `@config` variable to be set, just `super` from your
119
131
  implementation; don't if you don't want it to be set.
120
132
 
121
133
 
122
- == Configuration Objects
134
+ ## Configuration Objects
123
135
 
124
136
  Configurability also includes `Configurability::Config`, a fairly simple
125
137
  configuration object class that can be used to load a YAML configuration file,
@@ -237,15 +249,31 @@ or write it back to the file it was loaded from:
237
249
  config.write
238
250
 
239
251
 
240
- == Configuration Defaults
252
+ ## Configuration Defaults
253
+
254
+ It's a good idea to provide a set of reasonable defaults for any configured
255
+ object. Configurability provides a `defaults` method that will look for a constant
256
+ called either `DEFAULT_CONFIG` or `CONFIG_DEFAULTS` on each object extended with
257
+ Configurability, and will return a dup of the value of this constant if it does.
258
+
259
+ You can also override `defaults` yourself if you wish to provide them via something
260
+ other than a constant.
261
+
262
+ There are also a couple of useful functions built on top of this method:
241
263
 
242
- Configurability also supports an API for generating a new config file with
243
- defaults for all objects with Configurability.
264
+ gather_defaults
265
+ : You can fetch a Hash of the default config values of all objects that have been extended
266
+ with Configurability by calling `Configurabilty.gather_defaults`. You can also pass an
267
+ object that responds to `#merge!` to the method to merge the defaults into an existing
268
+ config.
244
269
 
245
- [:FIXME:] Finish up the documentation
270
+ default_config
271
+ : This will return a Configurability::Config object made from the results of
272
+ `gather_defaults`. This makes it easy to write a config file that contains the default
273
+ configuration: `Configurability.default_config.write( "defaults.yml" )`
246
274
 
247
275
 
248
- == Development
276
+ ## Development
249
277
 
250
278
  You can submit bug reports, suggestions, clone it with Mercurial, and
251
279
  read more about future plans at
@@ -261,9 +289,9 @@ This task will install any missing dependencies, run the tests/specs,
261
289
  and generate the API documentation.
262
290
 
263
291
 
264
- == License
292
+ ## License
265
293
 
266
- Copyright (c) 2010-2016 Michael Granger
294
+ Copyright (c) 2010-2016 Michael Granger and Mahlon E. Smith
267
295
  All rights reserved.
268
296
 
269
297
  Redistribution and use in source and binary forms, with or without
data/Rakefile CHANGED
@@ -17,21 +17,27 @@ Hoe.plugins.delete :rubyforge
17
17
  Encoding.default_internal = Encoding::UTF_8
18
18
 
19
19
  hoespec = Hoe.spec 'configurability' do |spec|
20
- spec.readme_file = 'README.rdoc'
21
- spec.history_file = 'History.rdoc'
22
- spec.extra_rdoc_files = Rake::FileList[ '*.rdoc' ]
20
+ spec.readme_file = 'README.md'
21
+ spec.history_file = 'History.md'
22
+ spec.extra_rdoc_files = FileList[ '*.rdoc', '*.md' ]
23
23
  spec.license 'BSD-3-Clause'
24
+ spec.urls = {
25
+ home: 'http://deveiate.org/projects/configurability',
26
+ code: 'http://bitbucket.org/ged/configurability',
27
+ docs: 'http://deveiate.org/code/configurability',
28
+ github: 'http://github.com/ged/configurability',
29
+ }
24
30
 
25
31
  spec.developer 'Michael Granger', 'ged@FaerieMUD.org'
32
+ spec.developer 'Mahlon E. Smith', 'mahlon@martini.nu'
26
33
 
27
34
  spec.dependency 'loggability', '~> 0.11'
28
35
 
29
- spec.dependency 'hoe-deveiate', '~> 0.5', :developer
30
- spec.dependency 'simplecov', '~> 0.8', :developer
31
- spec.dependency 'hoe-bundler', '~> 1.2', :developer
32
- spec.dependency 'rspec', '~> 3.0', :developer
36
+ spec.dependency 'hoe-deveiate', '~> 0.8', :developer
37
+ spec.dependency 'simplecov', '~> 0.12', :developer
38
+ spec.dependency 'rspec', '~> 3.5', :developer
33
39
 
34
- spec.require_ruby_version( '>= 1.9.2' )
40
+ spec.require_ruby_version( '>= 2.2.0' )
35
41
 
36
42
  spec.hg_sign_tags = true if spec.respond_to?( :hg_sign_tags= )
37
43
  spec.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
@@ -18,10 +18,10 @@ module Configurability
18
18
 
19
19
 
20
20
  # Library version constant
21
- VERSION = '2.2.2'
21
+ VERSION = '3.0.0'
22
22
 
23
23
  # Version-control revision constant
24
- REVISION = %q$Revision: 93764baee5f8 $
24
+ REVISION = %q$Revision: 1932602f7894 $
25
25
 
26
26
  require 'configurability/deferredconfig'
27
27
 
@@ -169,6 +169,15 @@ module Configurability
169
169
  end
170
170
 
171
171
 
172
+ ### Nest the specified +hash+ inside subhashes for each subsection of the given +key+ and
173
+ ### return the result.
174
+ def self::expand_config_hash( key, hash )
175
+ return key.to_s.split( '__' ).reverse.inject( hash ) do |inner_hash, subkey|
176
+ { subkey.to_sym => inner_hash }
177
+ end
178
+ end
179
+
180
+
172
181
  ### Gather defaults from objects with Configurability in the given +collection+
173
182
  ### object. Objects that wish to add a section to the defaults should implement
174
183
  ### a #defaults method in the same scope as #configure that returns the Hash of
@@ -180,10 +189,12 @@ module Configurability
180
189
 
181
190
  self.configurable_objects.each do |obj|
182
191
  next unless obj.respond_to?( :defaults )
183
- if subhash = obj.defaults
184
- section = obj.config_key.to_sym
185
- Configurability.log.debug "Defaults for %p (%p): %p" % [ obj, section, subhash ]
186
- collection.merge!( section => subhash, &mergefunc )
192
+ if defaults_hash = obj.defaults
193
+ nested_hash = self.expand_config_hash( obj.config_key, defaults_hash )
194
+ Configurability.log.debug "Defaults for %p (%p): %p" %
195
+ [ obj, obj.config_key, nested_hash ]
196
+
197
+ collection.merge!( nested_hash, &mergefunc )
187
198
  else
188
199
  Configurability.log.warn "No defaults for %p; skipping" % [ obj ]
189
200
  end
@@ -263,7 +274,7 @@ module Configurability
263
274
  ### Return a Configurability::Config object that contains the configuration
264
275
  ### defaults for the receiver.
265
276
  def default_config
266
- default_values = self.defaults or return Configurability::Config.new( {} )
277
+ default_values = self.defaults or return Configurability::Config::Struct.new( {} )
267
278
  return Configurability::Config::Struct.new( default_values )
268
279
  end
269
280
 
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'ostruct'
3
4
  require 'helpers'
4
5
 
5
6
  require 'rspec'
@@ -55,82 +56,80 @@ describe Configurability do
55
56
  end
56
57
 
57
58
 
58
- it "fetches config sections via a method with the config key name if the config " +
59
- "responds_to? it" do
59
+ it "can use a struct-like object as the config" do
60
60
  klass = Class.new do
61
61
  extend Configurability
62
62
  config_key :testconfig
63
63
  end
64
-
65
- config = double( "configuration object" )
66
- expect( config ).to receive( :respond_to? ).with( :testconfig ).and_return( true )
67
- expect( config ).to receive( :testconfig ).and_return( :a_config_section )
64
+ config = OpenStruct.new( testconfig: :a_config_section )
68
65
 
69
66
  expect( klass ).to receive( :configure ).with( :a_config_section )
67
+
70
68
  Configurability.configure_objects( config )
71
69
  end
72
70
 
73
71
 
74
- it "fetches config subsections via a method chain that corresponds to the config key" do
72
+ it "can use a struct-like object as a config with subsections " do
75
73
  klass = Class.new do
76
74
  extend Configurability
77
75
  config_key "testconfig.subsection"
78
76
  end
79
-
80
- config = double( "configuration object" )
81
- expect( config ).to receive( :respond_to? ).with( :testconfig ).and_return( true )
82
-
83
- section = double( "configuration section" )
84
- expect( config ).to receive( :testconfig ).and_return( section )
85
- expect( section ).to receive( :respond_to? ).with( :subsection ).and_return( true )
86
- expect( section ).to receive( :subsection ).and_return( :the_config_subsection )
77
+ config = OpenStruct.new( testconfig: {subsection: :the_config_subsection} )
87
78
 
88
79
  expect( klass ).to receive( :configure ).with( :the_config_subsection )
80
+
89
81
  Configurability.configure_objects( config )
90
82
  end
91
83
 
92
84
 
93
- it "fetches config sections via the index operator if the config doesn't respond " +
94
- "directly to the section name, but does to the index operator and #key?" do
85
+ it "can use a hash as the config" do
95
86
  klass = Class.new do
96
87
  extend Configurability
97
88
  config_key :testconfig
98
89
  end
99
-
100
- config = double( "configuration object" )
101
- expect( config ).to receive( :respond_to? ).with( :testconfig ).and_return( false )
102
- expect( config ).to receive( :respond_to? ).with( :key? ).and_return( true )
103
- expect( config ).to receive( :respond_to? ).with( :[] ).and_return( true )
104
- expect( config ).to receive( :key? ).with( :testconfig ).and_return( true )
105
- expect( config ).to receive( :[] ).with( :testconfig ).and_return( :a_config_section )
90
+ config = { testconfig: :a_config_section }
106
91
 
107
92
  expect( klass ).to receive( :configure ).with( :a_config_section )
93
+
108
94
  Configurability.configure_objects( config )
109
95
  end
110
96
 
111
97
 
112
- it "fetches config subsections via the index operator if the config doesn't respond " +
113
- "directly to the section name, but does to the index operator and #key?" do
98
+ it "can use a hash as a config with subsections" do
114
99
  klass = Class.new do
115
100
  extend Configurability
116
101
  config_key :testconfig__subsection
117
102
  end
103
+ config = { testconfig: {subsection: :the_config_subsection} }
118
104
 
119
- config = double( "configuration object" )
120
- expect( config ).to receive( :respond_to? ).with( :testconfig ).and_return( false )
121
- expect( config ).to receive( :respond_to? ).with( :key? ).and_return( true )
122
- expect( config ).to receive( :respond_to? ).with( :[] ).and_return( true )
123
- expect( config ).to receive( :key? ).with( :testconfig ).and_return( true )
105
+ expect( klass ).to receive( :configure ).with( :the_config_subsection )
106
+
107
+ Configurability.configure_objects( config )
108
+ end
124
109
 
125
- section = double( "configuration section" )
126
- expect( config ).to receive( :[] ).with( :testconfig ).and_return( section )
127
- expect( section ).to receive( :respond_to? ).with( :subsection ).and_return( false )
128
- expect( section ).to receive( :respond_to? ).with( :key? ).and_return( true )
129
- expect( section ).to receive( :respond_to? ).with( :[] ).and_return( true )
130
- expect( section ).to receive( :key? ).with( :subsection ).and_return( true )
131
- expect( section ).to receive( :[] ).with( :subsection ).and_return( :the_config_subsection )
110
+
111
+ it "can use a mix of struct-like and hash-like objects as a config with subsections" do
112
+ klass = Class.new do
113
+ extend Configurability
114
+ config_key :testconfig__subsection
115
+ end
116
+ config = OpenStruct.new( testconfig: {subsection: :the_config_subsection} )
117
+
118
+ expect( klass ).to receive( :configure ).with( :the_config_subsection )
119
+
120
+ Configurability.configure_objects( config )
121
+ end
122
+
123
+
124
+ it "supports more than one level of subsections" do
125
+ klass = Class.new do
126
+ extend Configurability
127
+ config_key "testconfig.sect1.sect2"
128
+ end
129
+ config = OpenStruct.new( testconfig: {sect1: {sect2: :the_config_subsection}} )
132
130
 
133
131
  expect( klass ).to receive( :configure ).with( :the_config_subsection )
132
+
134
133
  Configurability.configure_objects( config )
135
134
  end
136
135
 
@@ -431,6 +430,19 @@ describe Configurability do
431
430
  end
432
431
 
433
432
 
433
+ it "returns nested hashes for subsection defaults" do
434
+ klass = Class.new do
435
+ extend Configurability
436
+ config_key "testconfig.sect1.sect2"
437
+ self::CONFIG_DEFAULTS = { one: 1, two: 2 }
438
+ end
439
+
440
+ defaults = Configurability.gather_defaults
441
+
442
+ expect( defaults ).to eq({ testconfig: { sect1: {sect2: { one: 1, two: 2 }} } })
443
+ end
444
+
445
+
434
446
  it "can return a Configurability::Config object with defaults, too" do
435
447
  klass1 = Class.new do
436
448
  extend Configurability
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configurability
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0.pre20161121123955
4
+ version: 3.0.0.pre20161123172826
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
8
+ - Mahlon E. Smith
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain:
@@ -35,7 +36,7 @@ cert_chain:
35
36
  w8aNA5re5+Rt/Vvjxj5AcEnZnZiz5x959NaddQocX32Z1unHw44pzRNUur1GInfW
36
37
  p4vpx2kUSFSAGjtCbDGTNV2AH8w9OU4xEmNz8c5lyoA=
37
38
  -----END CERTIFICATE-----
38
- date: 2016-11-21 00:00:00.000000000 Z
39
+ date: 2016-11-24 00:00:00.000000000 Z
39
40
  dependencies:
40
41
  - !ruby/object:Gem::Dependency
41
42
  name: loggability
@@ -99,42 +100,28 @@ dependencies:
99
100
  requirements:
100
101
  - - "~>"
101
102
  - !ruby/object:Gem::Version
102
- version: '0.8'
103
- type: :development
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: '0.8'
110
- - !ruby/object:Gem::Dependency
111
- name: hoe-bundler
112
- requirement: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - "~>"
115
- - !ruby/object:Gem::Version
116
- version: '1.2'
103
+ version: '0.12'
117
104
  type: :development
118
105
  prerelease: false
119
106
  version_requirements: !ruby/object:Gem::Requirement
120
107
  requirements:
121
108
  - - "~>"
122
109
  - !ruby/object:Gem::Version
123
- version: '1.2'
110
+ version: '0.12'
124
111
  - !ruby/object:Gem::Dependency
125
112
  name: rspec
126
113
  requirement: !ruby/object:Gem::Requirement
127
114
  requirements:
128
115
  - - "~>"
129
116
  - !ruby/object:Gem::Version
130
- version: '3.0'
117
+ version: '3.5'
131
118
  type: :development
132
119
  prerelease: false
133
120
  version_requirements: !ruby/object:Gem::Requirement
134
121
  requirements:
135
122
  - - "~>"
136
123
  - !ruby/object:Gem::Version
137
- version: '3.0'
124
+ version: '3.5'
138
125
  - !ruby/object:Gem::Dependency
139
126
  name: rdoc
140
127
  requirement: !ruby/object:Gem::Requirement
@@ -171,18 +158,19 @@ description: |-
171
158
  single action.
172
159
  email:
173
160
  - ged@FaerieMUD.org
161
+ - mahlon@martini.nu
174
162
  executables:
175
163
  - configurability
176
164
  extensions: []
177
165
  extra_rdoc_files:
178
- - History.rdoc
166
+ - History.md
179
167
  - Manifest.txt
180
- - README.rdoc
168
+ - README.md
181
169
  files:
182
170
  - ChangeLog
183
- - History.rdoc
171
+ - History.md
184
172
  - Manifest.txt
185
- - README.rdoc
173
+ - README.md
186
174
  - Rakefile
187
175
  - bin/configurability
188
176
  - examples/basicconfig.rb
@@ -195,21 +183,21 @@ files:
195
183
  - spec/configurability/deferredconfig_spec.rb
196
184
  - spec/configurability_spec.rb
197
185
  - spec/helpers.rb
198
- homepage: https://bitbucket.org/ged/configurability
186
+ homepage: http://deveiate.org/projects/configurability
199
187
  licenses:
200
188
  - BSD-3-Clause
201
189
  metadata: {}
202
190
  post_install_message:
203
191
  rdoc_options:
204
192
  - "--main"
205
- - README.rdoc
193
+ - README.md
206
194
  require_paths:
207
195
  - lib
208
196
  required_ruby_version: !ruby/object:Gem::Requirement
209
197
  requirements:
210
198
  - - ">="
211
199
  - !ruby/object:Gem::Version
212
- version: 1.9.2
200
+ version: 2.2.0
213
201
  required_rubygems_version: !ruby/object:Gem::Requirement
214
202
  requirements:
215
203
  - - ">"