configurability 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/ChangeLog CHANGED
@@ -1,8 +1,61 @@
1
+ 2012-01-27 Michael Granger <ged@FaerieMUD.org>
2
+
3
+ * lib/configurability.rb:
4
+ Fixing the version
5
+ [9319c44c05ce] [tip]
6
+
7
+ * .hgsigs, .hgtags, History.rdoc, lib/configurability.rb,
8
+ spec/configurability/config_spec.rb:
9
+ Merged with ssh://hg@bitbucket.org/ged/configurability@86718657a466
10
+ [d3f6f8d77060]
11
+
12
+ * .hgtags:
13
+ Added tag v1.0.8 for changeset 6a7852aa7398
14
+ [5e85b9cb1122]
15
+
16
+ * .hgsigs:
17
+ Added signature for changeset 2501a302fe07
18
+ [6a7852aa7398]
19
+
20
+ * History.rdoc, lib/configurability.rb:
21
+ Bumped the version, updated history.
22
+ [2501a302fe07]
23
+
24
+ * .rvm.gems, .rvmrc, experiments/staticcling-weirdness.rb, experiments
25
+ /staticcling-weirdness2.rb, experiments/staticcling-weirdness3.rb,
26
+ lib/configurability.rb, lib/configurability/deferredconfig.rb,
27
+ spec/configurability/config_spec.rb, spec/configurability_spec.rb,
28
+ spec/lib/helpers.rb:
29
+ Fixing bugs found while working on StaticCling
30
+ [0c3c20665455]
31
+
32
+ * .tm_properties:
33
+ Adding TextMate properties
34
+ [45b92add3e1e]
35
+
36
+ 2011-11-01 Michael Granger <ged@FaerieMUD.org>
37
+
38
+ * .hgtags:
39
+ Added tag v1.0.8 for changeset 5b3d66af5a59
40
+ [86718657a466]
41
+
42
+ * .hgsigs:
43
+ Added signature for changeset 97a03db6f41c
44
+ [5b3d66af5a59] [v1.0.8]
45
+
46
+ * History.rdoc, lib/configurability.rb:
47
+ Bumped patch version and updated the History file.
48
+ [97a03db6f41c]
49
+
50
+ * spec/configurability/config_spec.rb:
51
+ Fix for Ruby 1.9.3.
52
+ [a26cd541ea8f]
53
+
1
54
  2011-10-13 Michael Granger <ged@FaerieMUD.org>
2
55
 
3
56
  * .hgtags:
4
57
  Added tag v1.0.7 for changeset 4e605f137155
5
- [0f391f680b61] [tip]
58
+ [0f391f680b61]
6
59
 
7
60
  * .hgsigs:
8
61
  Added signature for changeset 605036b92217
@@ -26,7 +79,7 @@
26
79
 
27
80
  * Rakefile:
28
81
  Merged with c9b7b76e4792
29
- [cae88e472706] [github/master]
82
+ [cae88e472706]
30
83
 
31
84
  * Rakefile:
32
85
  Cleaning up the Rakefile a bit
@@ -1,3 +1,21 @@
1
+ == v1.0.9 [2012-01-27] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ Fix problems associated with inheritance.
4
+
5
+ - Added a Hash of configure methods that have already been called
6
+ as pairs of Methods and Config sections. (Configurability.configured)
7
+ - Use the `configured` hash to avoid re-calling configure with the same
8
+ config section more than once when a class with Configurability is
9
+ inherited.
10
+ - Configurability.install_config -- Only use the index operator method
11
+ of the config object if it actually has the config_key as a key. Else
12
+ configure with +nil+.
13
+ - Support different whitespace conventions in different YAML libraries
14
+
15
+ Thanks to Mahlon E. Smith for reporting this bug, and for pairing with
16
+ me to fix it.
17
+
18
+
1
19
  == v1.0.8 [2011-11-01] Michael Granger <ged@FaerieMUD.org>
2
20
 
3
21
  - Fix for Ruby 1.9.3-p0.
@@ -11,10 +11,10 @@ require 'yaml'
11
11
  module Configurability
12
12
 
13
13
  # Library version constant
14
- VERSION = '1.0.8'
14
+ VERSION = '1.0.9'
15
15
 
16
16
  # Version-control revision constant
17
- REVISION = %q$Revision: 97a03db6f41c $
17
+ REVISION = %q$Revision: 9319c44c05ce $
18
18
 
19
19
  require 'configurability/logformatter'
20
20
  require 'configurability/deferredconfig'
@@ -26,6 +26,11 @@ module Configurability
26
26
  ### The loaded config (if there is one)
27
27
  @loaded_config = nil
28
28
 
29
+ ### The hash of configuration calls that have already taken place -- the keys are
30
+ ### Method objects for the configure methods of the configured objects, and the values
31
+ ### are the config section it was called with
32
+ @configured = Hash.new( false )
33
+
29
34
  ### Logging
30
35
  @default_logger = Logger.new( $stderr )
31
36
  @default_logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN
@@ -44,6 +49,9 @@ module Configurability
44
49
  # the loaded configuration (after ::configure_objects has been called at least once)
45
50
  attr_accessor :loaded_config
46
51
 
52
+ # the hash of configure methods => config sections which have already been installed
53
+ attr_reader :configured
54
+
47
55
  # the log formatter that will be used when the logging subsystem is
48
56
  # reset
49
57
  attr_accessor :default_log_formatter
@@ -104,6 +112,7 @@ module Configurability
104
112
  self.log.debug "Splitting up config %p between %d objects with configurability." %
105
113
  [ config, self.configurable_objects.length ]
106
114
 
115
+ self.reset
107
116
  self.loaded_config = config
108
117
 
109
118
  self.configurable_objects.each do |obj|
@@ -115,6 +124,7 @@ module Configurability
115
124
  ### If a configuration has been loaded (via {#configure_objects}), clear it.
116
125
  def self::reset
117
126
  self.loaded_config = nil
127
+ self.configured.clear
118
128
  end
119
129
 
120
130
 
@@ -134,15 +144,33 @@ module Configurability
134
144
 
135
145
  if config.respond_to?( section )
136
146
  self.log.debug " config has a %p method; using that" % [ section ]
137
- object.configure( config.send(section) )
138
- elsif config.respond_to?( :[] )
139
- self.log.debug " config has a an index operator method; using that"
140
- object.configure( config[section] || config[section.to_s] )
147
+ section = config.send( section )
148
+ elsif config.respond_to?( :[] ) && config.respond_to?( :key? )
149
+ self.log.debug " config has a hash-ish interface..."
150
+ if config.key?( section ) || config.key?( section.to_s )
151
+ self.log.debug " and has a %p member; using that" % [ section ]
152
+ section = config[section] || config[section.to_s]
153
+ else
154
+ self.log.debug " but no %p member."
155
+ section = nil
156
+ end
141
157
  else
142
158
  self.log.warn " don't know how to get the %p section of the config from %p" %
143
159
  [ section, config ]
144
- object.configure( nil )
160
+ section = nil
145
161
  end
162
+
163
+ # Figure out if the configure method has already been called with this config
164
+ # section before, and don't re-call it if so
165
+ configure_method = object.method( :configure )
166
+
167
+ if self.configured[ configure_method ] == section
168
+ self.log.debug " avoiding re-calling %p" % [ configure_method ]
169
+ return
170
+ end
171
+
172
+ self.log.debug " calling %p" % [ configure_method ]
173
+ configure_method.call( section )
146
174
  end
147
175
 
148
176
 
@@ -150,10 +178,6 @@ module Configurability
150
178
  ### A P P E N D E D M E T H O D S
151
179
  #############################################################
152
180
 
153
- ### The symbol which corresponds to the section of the configuration
154
- ### used to configure the object.
155
- attr_writer :config_key
156
-
157
181
  ### Get (and optionally set) the +config_key+ (a Symbol).
158
182
  def config_key( sym=nil )
159
183
  @config_key = sym unless sym.nil?
@@ -20,6 +20,7 @@ module Configurability::DeferredConfig
20
20
  super
21
21
 
22
22
  if sym == :configure
23
+ Configurability.log.debug "Re-configuring %p via deferred config hook." % [ self ]
23
24
  config = Configurability.loaded_config
24
25
  Configurability.log.debug "Propagating config to %p" % [ self ]
25
26
  Configurability.install_config( config, self )
@@ -53,7 +53,7 @@ describe Configurability::Config do
53
53
  end
54
54
 
55
55
  it "can dump itself as YAML" do
56
- Configurability::Config.new.dump.should =~ /^--- \{\}\n\n?/
56
+ Configurability::Config.new.dump.strip.should == "--- {}"
57
57
  end
58
58
 
59
59
  it "returns nil as its change description" do
@@ -74,7 +74,7 @@ describe Configurability do
74
74
  end
75
75
 
76
76
  it "fetches config sections via the index operator if the config doesn't respond " +
77
- "directly to the section name, but does to the index operator" do
77
+ "directly to the section name, but does to the index operator and #key?" do
78
78
  klass = Class.new do
79
79
  extend Configurability
80
80
  config_key :testconfig
@@ -82,7 +82,9 @@ describe Configurability do
82
82
 
83
83
  config = mock( "configuration object" )
84
84
  config.should_receive( :respond_to? ).with( :testconfig ).and_return( false )
85
+ config.should_receive( :respond_to? ).with( :key? ).and_return( true )
85
86
  config.should_receive( :respond_to? ).with( :[] ).and_return( true )
87
+ config.should_receive( :key? ).with( :testconfig ).and_return( true )
86
88
  config.should_receive( :[] ).with( :testconfig ).and_return( :a_config_section )
87
89
 
88
90
  klass.should_receive( :configure ).with( :a_config_section )
@@ -113,7 +115,10 @@ describe Configurability do
113
115
 
114
116
  config = mock( "configuration object" )
115
117
  config.should_receive( :respond_to? ).with( :testconfig ).and_return( false )
118
+ config.should_receive( :respond_to? ).with( :key? ).and_return( true )
116
119
  config.should_receive( :respond_to? ).with( :[] ).and_return( true )
120
+ config.should_receive( :key? ).with( :testconfig ).and_return( false )
121
+ config.should_receive( :key? ).with( 'testconfig' ).and_return( true )
117
122
  config.should_receive( :[] ).with( :testconfig ).and_return( nil )
118
123
  config.should_receive( :[] ).with( 'testconfig' ).and_return( :a_config_section )
119
124
 
@@ -253,6 +258,33 @@ describe Configurability do
253
258
  objectclass.config.should == :yes
254
259
  end
255
260
 
261
+ it "doesn't reconfigure objects that have already been configured unless the config changes" do
262
+ first_objectclass = Class.new do
263
+ extend Configurability
264
+ @configs = []
265
+ config_key :postconfig
266
+ def self::configure( config ); @configs << config; end
267
+ def self::inherited( subclass ); subclass.instance_variable_set(:@configs, []); super; end
268
+ class << self; attr_reader :configs; end
269
+ end
270
+
271
+ second_objectclass = Class.new( first_objectclass ) do
272
+ extend Configurability
273
+ config_key :postconfig
274
+ def self::configure( config ); @configs << config; end
275
+ end
276
+
277
+ third_objectclass = Class.new( second_objectclass ) do
278
+ extend Configurability
279
+ config_key :postconfig
280
+ def self::configure( config ); @configs << config; end
281
+ end
282
+
283
+ first_objectclass.configs.should == [ @config[:postconfig] ]
284
+ second_objectclass.configs.should == [ nil, @config[:postconfig] ]
285
+ third_objectclass.configs.should == [ nil, @config[:postconfig] ]
286
+ end
287
+
256
288
  end
257
289
 
258
290
  end
@@ -19,6 +19,7 @@ require 'yaml'
19
19
 
20
20
  SimpleCov.start do
21
21
  add_filter '/spec/'
22
+ add_filter '/textmate-command/'
22
23
  end
23
24
  require 'configurability'
24
25
 
@@ -127,7 +128,6 @@ module Configurability::SpecHelpers
127
128
  Thread.current['logger-output'] = []
128
129
  logdevice = ArrayLogger.new( Thread.current['logger-output'] )
129
130
  Configurability.logger = Logger.new( logdevice )
130
- Configurability.logger.level = level
131
131
  Configurability.logger.formatter = HtmlLogFormatter.new( Configurability.logger )
132
132
  else
133
133
  logger = Logger.new( $stderr )
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: 1.0.8
4
+ version: 1.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -48,11 +48,11 @@ cert_chain:
48
48
  -----END CERTIFICATE-----
49
49
 
50
50
  '
51
- date: 2011-11-01 00:00:00.000000000 Z
51
+ date: 2012-01-28 00:00:00.000000000 Z
52
52
  dependencies:
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: hoe-mercurial
55
- requirement: &70130268838340 !ruby/object:Gem::Requirement
55
+ requirement: &70293058889240 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ~>
@@ -60,10 +60,10 @@ dependencies:
60
60
  version: 1.3.1
61
61
  type: :development
62
62
  prerelease: false
63
- version_requirements: *70130268838340
63
+ version_requirements: *70293058889240
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: hoe-highline
66
- requirement: &70130268837300 !ruby/object:Gem::Requirement
66
+ requirement: &70293058887220 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
69
69
  - - ~>
@@ -71,10 +71,10 @@ dependencies:
71
71
  version: 0.0.1
72
72
  type: :development
73
73
  prerelease: false
74
- version_requirements: *70130268837300
74
+ version_requirements: *70293058887220
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rspec
77
- requirement: &70130268836020 !ruby/object:Gem::Requirement
77
+ requirement: &70293058885400 !ruby/object:Gem::Requirement
78
78
  none: false
79
79
  requirements:
80
80
  - - ~>
@@ -82,10 +82,10 @@ dependencies:
82
82
  version: '2.4'
83
83
  type: :development
84
84
  prerelease: false
85
- version_requirements: *70130268836020
85
+ version_requirements: *70293058885400
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: simplecov
88
- requirement: &70130268834960 !ruby/object:Gem::Requirement
88
+ requirement: &70293058884740 !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
91
  - - ~>
@@ -93,18 +93,29 @@ dependencies:
93
93
  version: '0.3'
94
94
  type: :development
95
95
  prerelease: false
96
- version_requirements: *70130268834960
96
+ version_requirements: *70293058884740
97
+ - !ruby/object:Gem::Dependency
98
+ name: rdoc
99
+ requirement: &70293058884160 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: '3.10'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: *70293058884160
97
108
  - !ruby/object:Gem::Dependency
98
109
  name: hoe
99
- requirement: &70130268833240 !ruby/object:Gem::Requirement
110
+ requirement: &70293058883580 !ruby/object:Gem::Requirement
100
111
  none: false
101
112
  requirements:
102
113
  - - ~>
103
114
  - !ruby/object:Gem::Version
104
- version: '2.12'
115
+ version: '2.13'
105
116
  type: :development
106
117
  prerelease: false
107
- version_requirements: *70130268833240
118
+ version_requirements: *70293058883580
108
119
  description: ! 'Configurability is a mixin that allows you to add configurability
109
120
  to one or
110
121
 
@@ -163,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
174
  version: '0'
164
175
  requirements: []
165
176
  rubyforge_project: configurability
166
- rubygems_version: 1.8.10
177
+ rubygems_version: 1.8.14
167
178
  signing_key:
168
179
  specification_version: 3
169
180
  summary: Configurability is a mixin that allows you to add configurability to one
metadata.gz.sig CHANGED
Binary file