mixlib-config 1.1.0.rc01 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :patch: 0
3
- :build: rc01
3
+ :build:
4
4
  :major: 1
5
5
  :minor: 1
@@ -18,6 +18,12 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
+ class Object # http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
22
+ def meta_def name, &blk
23
+ (class << self; self; end).instance_eval { define_method name, &blk }
24
+ end
25
+ end
26
+
21
27
  module Mixlib
22
28
  module Config
23
29
 
@@ -119,7 +125,7 @@ module Mixlib
119
125
  #
120
126
  def internal_set(method_symbol,value)
121
127
  method_name = method_symbol.id2name
122
- if self.respond_to?("#{method_name}=".to_sym)
128
+ if (self.public_methods - ["[]="]).include?("#{method_name}=")
123
129
  self.send("#{method_name}=", value)
124
130
  else
125
131
  self.configuration[method_symbol] = value
@@ -136,9 +142,8 @@ module Mixlib
136
142
  # value<Object>:: Value to be set in config hash
137
143
  #
138
144
  def config_attr_writer(method_symbol, &blk)
139
- meta = class << self; self; end
140
- method_name = "#{method_symbol.to_s}=".to_sym
141
- meta.send :define_method, method_name do |value|
145
+ method_name = "#{method_symbol.to_s}="
146
+ meta_def method_name do |value|
142
147
  self.configuration[method_symbol] = blk.call(value)
143
148
  end
144
149
  end
@@ -18,11 +18,6 @@
18
18
 
19
19
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
20
20
 
21
- class ConfigIt
22
- extend ::Mixlib::Config
23
- end
24
-
25
-
26
21
  describe Mixlib::Config do
27
22
  before(:each) do
28
23
  ConfigIt.configure do |c|
@@ -101,41 +96,47 @@ describe Mixlib::Config do
101
96
 
102
97
  describe "when a class method override accessor exists" do
103
98
  before do
104
- @klass = Class.new
105
- @klass.extend(::Mixlib::Config)
106
- @klass.class_eval(<<-EVAL)
99
+ class ConfigIt
100
+
107
101
  config_attr_writer :test_method do |blah|
108
102
  blah.is_a?(Integer) ? blah * 1000 : blah
109
103
  end
110
- pp self.methods
111
- EVAL
104
+
105
+ end
112
106
  end
113
107
 
114
108
  it "should multiply an integer by 1000" do
115
- @klass[:test_method] = 53
116
- @klass[:test_method].should == 53000
109
+ ConfigIt[:test_method] = 53
110
+ ConfigIt[:test_method].should == 53000
117
111
  end
118
112
 
119
113
  it "should multiply an integer by 1000 with the method_missing form" do
120
- @klass.test_method = 63
121
- @klass.test_method.should == 63000
114
+ ConfigIt.test_method = 63
115
+ ConfigIt.test_method.should == 63000
122
116
  end
123
117
 
124
118
  it "should multiply an integer by 1000 with the instance_eval DSL form" do
125
- @klass.instance_eval("test_method 73")
126
- @klass.test_method.should == 73000
119
+ ConfigIt.instance_eval("test_method 73")
120
+ ConfigIt.test_method.should == 73000
127
121
  end
128
122
 
129
123
  it "should multiply an integer by 1000 via from-file, too" do
130
124
  IO.stub!(:read).with('config.rb').and_return("test_method 99")
131
- @klass.from_file('config.rb')
132
- @klass.test_method.should == 99000
125
+ ConfigIt.from_file('config.rb')
126
+ ConfigIt.test_method.should == 99000
133
127
  end
134
128
 
135
129
  it "should receive internal_set with the method name and config value" do
136
- @klass.should_receive(:internal_set).with(:test_method, 53).and_return(true)
137
- @klass[:test_method] = 53
130
+ ConfigIt.should_receive(:internal_set).with(:test_method, 53).and_return(true)
131
+ ConfigIt[:test_method] = 53
138
132
  end
139
133
 
134
+ after do
135
+ class ConfigIt
136
+ class << self
137
+ undef test_method=
138
+ end
139
+ end
140
+ end
140
141
  end
141
142
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-config
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ prerelease: false
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
8
  - 0
9
- - rc01
10
- version: 1.1.0.rc01
9
+ version: 1.1.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Opscode, Inc.
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-06-15 00:00:00 -07:00
17
+ date: 2010-02-28 00:00:00 -08:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
@@ -55,7 +54,6 @@ rdoc_options:
55
54
  require_paths:
56
55
  - lib
57
56
  required_ruby_version: !ruby/object:Gem::Requirement
58
- none: false
59
57
  requirements:
60
58
  - - ">="
61
59
  - !ruby/object:Gem::Version
@@ -63,19 +61,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
61
  - 0
64
62
  version: "0"
65
63
  required_rubygems_version: !ruby/object:Gem::Requirement
66
- none: false
67
64
  requirements:
68
- - - ">"
65
+ - - ">="
69
66
  - !ruby/object:Gem::Version
70
67
  segments:
71
- - 1
72
- - 3
73
- - 1
74
- version: 1.3.1
68
+ - 0
69
+ version: "0"
75
70
  requirements: []
76
71
 
77
72
  rubyforge_project:
78
- rubygems_version: 1.3.7
73
+ rubygems_version: 1.3.6
79
74
  signing_key:
80
75
  specification_version: 3
81
76
  summary: A class based config mixin, similar to the one found in Chef.