mixlib-config 1.0.12 → 1.1.0.rc01

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ *.gemspec
data/NOTICE ADDED
@@ -0,0 +1,27 @@
1
+ Mixin::Config NOTICE
2
+ =================
3
+
4
+ Developed at Opscode (http://www.opscode.com).
5
+
6
+ * Copyright 2009, Opscode, Inc. <legal@opscode.com>
7
+
8
+ Mixin::Config incorporates code from Chef. The Chef notice file follows:
9
+
10
+ Chef NOTICE
11
+ ===========
12
+
13
+ Developed at Opscode (http://www.opscode.com).
14
+
15
+ Contributors and Copyright holders:
16
+
17
+ * Copyright 2008, Adam Jacob <adam@opscode.com>
18
+ * Copyright 2008, Arjuna Christensen <aj@hjksolutions.com>
19
+ * Copyright 2008, Bryan McLellan <btm@loftninjas.org>
20
+ * Copyright 2008, Ezra Zygmuntowicz <ezra@engineyard.com>
21
+ * Copyright 2009, Sean Cribbs <seancribbs@gmail.com>
22
+ * Copyright 2009, Christopher Brown <cb@opscode.com>
23
+ * Copyright 2009, Thom May <thom@clearairturbulence.org>
24
+
25
+ Chef incorporates code modified from Open4 (http://www.codeforpeople.com/lib/ruby/open4/), which was written by Ara T. Howard.
26
+
27
+ Chef incorporates code modified from Merb (http://www.merbivore.com), which is Copyright (c) 2008 Engine Yard.
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ begin
13
13
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
14
  end
15
15
  rescue LoadError
16
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
16
+ puts "Jeweler (or a dependency) not available. Install from gemcutter with: sudo gem install gemcutter jeweler"
17
17
  end
18
18
 
19
19
  require 'spec/rake/spectask'
@@ -62,3 +62,5 @@ end
62
62
 
63
63
  desc "Run the spec and features"
64
64
  task :test => [ :features, :spec ]
65
+
66
+ Jeweler::GemcutterTasks.new
@@ -1,4 +1,5 @@
1
1
  ---
2
- :major: 1
3
- :minor: 0
4
- :patch: 12
2
+ :patch: 0
3
+ :build: rc01
4
+ :major: 1
5
+ :minor: 1
@@ -0,0 +1,31 @@
1
+ Feature: Configure an application
2
+ In order to make it trivial to configure an application
3
+ As a Developer
4
+ I want to utilize a simple configuration object
5
+
6
+ Scenario: Set a configuration option to a string
7
+ Given a configuration class 'ConfigIt'
8
+ When I set 'foo' to 'bar' in configuration class 'ConfigIt'
9
+ Then config option 'foo' is 'bar'
10
+
11
+ Scenario: Set the same configuration option to different strings for two configuration classes
12
+ Given a configuration class 'ConfigIt'
13
+ And a configuration class 'ConfigItToo'
14
+ When I set 'foo' to 'bar' in configuration class 'ConfigIt'
15
+ And I set 'foo' to 'bar2' in configuration class 'ConfigItToo'
16
+ Then in configuration class 'ConfigItToo' config option 'foo' is 'bar2'
17
+ And in configuration class 'ConfigIt' config option 'foo' is 'bar'
18
+
19
+ Scenario: Set a configuration option to an Array
20
+ Given a configuration class 'ConfigIt'
21
+ When I set 'foo' to:
22
+ |key|
23
+ |bar|
24
+ |baz|
25
+ Then an array is returned for 'foo'
26
+
27
+ Scenario: Set a configuration option from a file
28
+ Given a configuration file 'bobo.config'
29
+ When I load the configuration
30
+ Then config option 'foo' is 'bar'
31
+ And config option 'baz' is 'snarl'
@@ -0,0 +1,66 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ Given /^a configuration class '(.+)'$/ do |classname|
20
+ end
21
+
22
+ When /^I set '(.+)' to '(.+)' in configuration class '(.+)'$/ do |key, value, classname|
23
+
24
+ #ConfigIt[key.to_sym] = value
25
+ if classname == 'ConfigIt'
26
+ ConfigIt[key.to_sym] = value
27
+ elsif classname == 'ConfigItToo'
28
+ ConfigItToo[key.to_sym] = value
29
+ else
30
+ raise ArgumentError, "configuration class must be ConfigIt or ConfigItToo"
31
+ end
32
+ end
33
+
34
+ Then /^config option '(.+)' is '(.+)'$/ do |key, value|
35
+ ConfigIt[key.to_sym].should == value
36
+ end
37
+
38
+ Then /^in configuration class '(.+)' config option '(.+)' is '(.+)'$/ do |classname, key, value|
39
+ if classname == 'ConfigIt'
40
+ ConfigIt[key.to_sym].should == value
41
+ elsif classname == 'ConfigItToo'
42
+ ConfigItToo[key.to_sym].should == value
43
+ else
44
+ raise ArgumentError, "configuration class must be ConfigIt or ConfigItToo"
45
+ end
46
+ end
47
+
48
+ When /^I set '(.+)' to:$/ do |key, foo_table|
49
+ ConfigIt[key.to_sym] = Array.new
50
+ foo_table.hashes.each do |hash|
51
+ ConfigIt[key.to_sym] << hash['key']
52
+ end
53
+ end
54
+
55
+ Then /^an array is returned for '(.+)'$/ do |key|
56
+ ConfigIt[key.to_sym].should be_a_kind_of(Array)
57
+ end
58
+
59
+ Given /^a configuration file '(.+)'$/ do |filename|
60
+ @config_file = File.join(File.dirname(__FILE__), "..", "support", filename)
61
+ end
62
+
63
+ When /^I load the configuration$/ do
64
+ ConfigIt.from_file(@config_file)
65
+ end
66
+
@@ -0,0 +1,3 @@
1
+ # Sample config file
2
+ foo 'bar'
3
+ baz 'snarl'
@@ -0,0 +1,28 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ $: << File.join(File.dirname(__FILE__), '..', '..', 'lib')
20
+ require 'mixlib/config'
21
+
22
+ class ConfigIt
23
+ extend Mixlib::Config
24
+ end
25
+
26
+ class ConfigItToo
27
+ extend Mixlib::Config
28
+ end
@@ -0,0 +1,31 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ $: << File.join(File.dirname(__FILE__), '..', '..', 'lib')
20
+
21
+ require 'spec/expectations'
22
+ require 'mixlib/config'
23
+ require 'tmpdir'
24
+ require 'stringio'
25
+
26
+ class MyWorld
27
+ end
28
+
29
+ World do
30
+ MyWorld.new
31
+ end
@@ -1,5 +1,7 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Nuo Yan (<nuo@opscode.com>)
4
+ # Author:: Christopher Brown (<cb@opscode.com>)
3
5
  # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
6
  # License:: Apache License, Version 2.0
5
7
  #
@@ -16,16 +18,13 @@
16
18
  # limitations under the License.
17
19
  #
18
20
 
19
- class Object # http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
20
- def meta_def name, &blk
21
- (class << self; self; end).instance_eval { define_method name, &blk }
22
- end
23
- end
24
-
25
21
  module Mixlib
26
22
  module Config
27
-
28
- @@configuration = Hash.new
23
+
24
+ def self.extended(base)
25
+ class << base; attr_accessor :configuration; end
26
+ base.configuration = Hash.new
27
+ end
29
28
 
30
29
  # Loads a given ruby file, and runs instance_eval against it in the context of the current
31
30
  # object.
@@ -38,14 +37,14 @@ module Mixlib
38
37
  self.instance_eval(IO.read(filename), filename, 1)
39
38
  end
40
39
 
41
- # Pass Mixlib::Config.configure() a block, and it will yield @@configuration.
40
+ # Pass Mixlib::Config.configure() a block, and it will yield self.configuration.
42
41
  #
43
42
  # === Parameters
44
- # <block>:: A block that is sent @@configuration as its argument
43
+ # <block>:: A block that is sent self.configuration as its argument
45
44
  def configure(&block)
46
- block.call(@@configuration)
45
+ block.call(self.configuration)
47
46
  end
48
-
47
+
49
48
  # Get the value of a configuration option
50
49
  #
51
50
  # === Parameters
@@ -57,7 +56,7 @@ module Mixlib
57
56
  # === Raises
58
57
  # <ArgumentError>:: If the configuration option does not exist
59
58
  def [](config_option)
60
- @@configuration[config_option.to_sym]
59
+ self.configuration[config_option.to_sym]
61
60
  end
62
61
 
63
62
  # Set the value of a configuration option
@@ -81,7 +80,7 @@ module Mixlib
81
80
  # <True>:: If the configuration option exists
82
81
  # <False>:: If the configuration option does not exist
83
82
  def has_key?(key)
84
- @@configuration.has_key?(key.to_sym)
83
+ self.configuration.has_key?(key.to_sym)
85
84
  end
86
85
 
87
86
  # Merge an incoming hash with our config options
@@ -92,7 +91,7 @@ module Mixlib
92
91
  # === Returns
93
92
  # result of Hash#merge!
94
93
  def merge!(hash)
95
- @@configuration.merge!(hash)
94
+ self.configuration.merge!(hash)
96
95
  end
97
96
 
98
97
  # Return the set of config hash keys
@@ -100,7 +99,7 @@ module Mixlib
100
99
  # === Returns
101
100
  # result of Hash#keys
102
101
  def keys
103
- @@configuration.keys
102
+ self.configuration.keys
104
103
  end
105
104
 
106
105
  # Creates a shallow copy of the internal hash
@@ -108,7 +107,7 @@ module Mixlib
108
107
  # === Returns
109
108
  # result of Hash#dup
110
109
  def hash_dup
111
- @@configuration.dup
110
+ self.configuration.dup
112
111
  end
113
112
 
114
113
  # Internal dispatch setter, calling either the real defined method or setting the
@@ -120,10 +119,10 @@ module Mixlib
120
119
  #
121
120
  def internal_set(method_symbol,value)
122
121
  method_name = method_symbol.id2name
123
- if (self.public_methods - ["[]="]).include?("#{method_name}=")
122
+ if self.respond_to?("#{method_name}=".to_sym)
124
123
  self.send("#{method_name}=", value)
125
124
  else
126
- @@configuration[method_symbol] = value
125
+ self.configuration[method_symbol] = value
127
126
  end
128
127
  end
129
128
 
@@ -137,9 +136,10 @@ module Mixlib
137
136
  # value<Object>:: Value to be set in config hash
138
137
  #
139
138
  def config_attr_writer(method_symbol, &blk)
140
- method_name = "#{method_symbol.to_s}="
141
- meta_def method_name do |value|
142
- @@configuration[method_symbol] = blk.call(value)
139
+ meta = class << self; self; end
140
+ method_name = "#{method_symbol.to_s}=".to_sym
141
+ meta.send :define_method, method_name do |value|
142
+ self.configuration[method_symbol] = blk.call(value)
143
143
  end
144
144
  end
145
145
 
@@ -165,7 +165,7 @@ module Mixlib
165
165
  end
166
166
 
167
167
  # Returning
168
- @@configuration[method_symbol]
168
+ self.configuration[method_symbol]
169
169
 
170
170
  end
171
171
  end
@@ -18,6 +18,11 @@
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
+
21
26
  describe Mixlib::Config do
22
27
  before(:each) do
23
28
  ConfigIt.configure do |c|
@@ -96,47 +101,41 @@ describe Mixlib::Config do
96
101
 
97
102
  describe "when a class method override accessor exists" do
98
103
  before do
99
- class ConfigIt
100
-
104
+ @klass = Class.new
105
+ @klass.extend(::Mixlib::Config)
106
+ @klass.class_eval(<<-EVAL)
101
107
  config_attr_writer :test_method do |blah|
102
108
  blah.is_a?(Integer) ? blah * 1000 : blah
103
109
  end
104
-
105
- end
110
+ pp self.methods
111
+ EVAL
106
112
  end
107
113
 
108
114
  it "should multiply an integer by 1000" do
109
- ConfigIt[:test_method] = 53
110
- ConfigIt[:test_method].should == 53000
115
+ @klass[:test_method] = 53
116
+ @klass[:test_method].should == 53000
111
117
  end
112
118
 
113
119
  it "should multiply an integer by 1000 with the method_missing form" do
114
- ConfigIt.test_method = 63
115
- ConfigIt.test_method.should == 63000
120
+ @klass.test_method = 63
121
+ @klass.test_method.should == 63000
116
122
  end
117
123
 
118
124
  it "should multiply an integer by 1000 with the instance_eval DSL form" do
119
- ConfigIt.instance_eval("test_method 73")
120
- ConfigIt.test_method.should == 73000
125
+ @klass.instance_eval("test_method 73")
126
+ @klass.test_method.should == 73000
121
127
  end
122
128
 
123
129
  it "should multiply an integer by 1000 via from-file, too" do
124
130
  IO.stub!(:read).with('config.rb').and_return("test_method 99")
125
- ConfigIt.from_file('config.rb')
126
- ConfigIt.test_method.should == 99000
131
+ @klass.from_file('config.rb')
132
+ @klass.test_method.should == 99000
127
133
  end
128
134
 
129
135
  it "should receive internal_set with the method name and config value" do
130
- ConfigIt.should_receive(:internal_set).with(:test_method, 53).and_return(true)
131
- ConfigIt[:test_method] = 53
136
+ @klass.should_receive(:internal_set).with(:test_method, 53).and_return(true)
137
+ @klass[:test_method] = 53
132
138
  end
133
139
 
134
- after do
135
- class ConfigIt
136
- class << self
137
- undef test_method=
138
- end
139
- end
140
- end
141
140
  end
142
141
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ prerelease: true
5
+ segments:
6
+ - 1
7
+ - 1
8
+ - 0
9
+ - rc01
10
+ version: 1.1.0.rc01
5
11
  platform: ruby
6
12
  authors:
7
13
  - Opscode, Inc.
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-08-26 00:00:00 +12:00
18
+ date: 2010-06-15 00:00:00 -07:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -23,10 +29,18 @@ extra_rdoc_files:
23
29
  - LICENSE
24
30
  - README.rdoc
25
31
  files:
32
+ - .gitignore
26
33
  - LICENSE
34
+ - NOTICE
27
35
  - README.rdoc
28
36
  - Rakefile
29
37
  - VERSION.yml
38
+ - features/mixlib_config.feature
39
+ - features/step_definitions/mixlib_config_steps.rb
40
+ - features/steps/config_steps.rb
41
+ - features/support/bobo.config
42
+ - features/support/config_it.rb
43
+ - features/support/env.rb
30
44
  - lib/mixlib/config.rb
31
45
  - spec/mixlib/config_spec.rb
32
46
  - spec/spec.opts
@@ -41,21 +55,27 @@ rdoc_options:
41
55
  require_paths:
42
56
  - lib
43
57
  required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
44
59
  requirements:
45
60
  - - ">="
46
61
  - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
47
64
  version: "0"
48
- version:
49
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
50
67
  requirements:
51
- - - ">="
68
+ - - ">"
52
69
  - !ruby/object:Gem::Version
53
- version: "0"
54
- version:
70
+ segments:
71
+ - 1
72
+ - 3
73
+ - 1
74
+ version: 1.3.1
55
75
  requirements: []
56
76
 
57
77
  rubyforge_project:
58
- rubygems_version: 1.3.5
78
+ rubygems_version: 1.3.7
59
79
  signing_key:
60
80
  specification_version: 3
61
81
  summary: A class based config mixin, similar to the one found in Chef.