summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NOTICE6
-rw-r--r--chef-server-api/README.rdoc1
-rw-r--r--chef-server-api/config/router.rb2
-rw-r--r--chef/README.rdoc1
-rw-r--r--chef/chef.gemspec2
-rw-r--r--chef/lib/chef.rb4
-rw-r--r--chef/lib/chef/api_client.rb2
-rw-r--r--chef/lib/chef/cookbook/cookbook_collection.rb2
-rw-r--r--chef/lib/chef/data_bag.rb2
-rw-r--r--chef/lib/chef/data_bag_item.rb2
-rw-r--r--chef/lib/chef/mash.rb211
-rw-r--r--chef/lib/chef/node.rb2
-rw-r--r--chef/lib/chef/role.rb2
-rw-r--r--chef/lib/chef/run_list/run_list_expansion.rb2
14 files changed, 228 insertions, 13 deletions
diff --git a/NOTICE b/NOTICE
index 04c07d8309..b4ea2ccbee 100644
--- a/NOTICE
+++ b/NOTICE
@@ -19,3 +19,9 @@ Chef incorporates code modified from Open4 (http://www.codeforpeople.com/lib/rub
Chef incorporates code modified from Merb (http://www.merbivore.com), which is Copyright (c) 2008 Engine Yard.
Chef incorporates code modified from deep_merge (http://trac.misuse.org/science/wiki/DeepMerge), which is Copyright (c) 2008 Steve Midgley
+
+Chef incorporates code modified from extlib
+(http://github.com/datamapper/extlib), which is Copyright 2009 Dan
+Kubb with some portions of mash.rb being verbatim copies of software
+licensed under the MIT license and Copyright 2005-2008 David
+Heinemeier Hansson
diff --git a/chef-server-api/README.rdoc b/chef-server-api/README.rdoc
index 017d536dbf..e2daaf7ff7 100644
--- a/chef-server-api/README.rdoc
+++ b/chef-server-api/README.rdoc
@@ -15,7 +15,6 @@ chef:
* ruby-openid
* json
* erubis
-* extlib
* stomp
* ohai
diff --git a/chef-server-api/config/router.rb b/chef-server-api/config/router.rb
index a74238a839..7f9e701b87 100644
--- a/chef-server-api/config/router.rb
+++ b/chef-server-api/config/router.rb
@@ -135,7 +135,7 @@ Merb::Router.prepare do
# Call Chef's JSON utility instead of the default in Merb,
# JSON.parse.
jobj = Chef::JSONCompat.from_json(raw_post)
- jobj = jobj.to_mash if jobj.is_a?(Hash)
+ jobj = Mash.from_hash(jobj) if jobj.is_a?(Hash)
rescue JSON::ParserError
jobj = Mash.new
end
diff --git a/chef/README.rdoc b/chef/README.rdoc
index 80ee9c9cca..cc28dd0991 100644
--- a/chef/README.rdoc
+++ b/chef/README.rdoc
@@ -44,7 +44,6 @@ Install these via your platform's preferred method; for example apt, yum, ports,
* ohai
* bunny
* erubis
-* extlib
* highline
* json (1.4.4 - 1.4.6)
* mixlib-authentication
diff --git a/chef/chef.gemspec b/chef/chef.gemspec
index bb087c3679..3fec1c9ba9 100644
--- a/chef/chef.gemspec
+++ b/chef/chef.gemspec
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
s.add_dependency "bunny", ">= 0.6.0"
s.add_dependency "json", ">= 1.4.4", "<= 1.4.6"
s.add_dependency "treetop", "~> 1.4.9"
- %w{erubis extlib moneta highline uuidtools}.each { |gem| s.add_dependency gem }
+ %w{erubis moneta highline uuidtools}.each { |gem| s.add_dependency gem }
s.bindir = "bin"
s.executables = %w( chef-client chef-solo knife shef )
diff --git a/chef/lib/chef.rb b/chef/lib/chef.rb
index a9431c1889..3218fb2b37 100644
--- a/chef/lib/chef.rb
+++ b/chef/lib/chef.rb
@@ -18,7 +18,7 @@
require 'chef/version'
require 'chef/nil_argument'
-require 'extlib'
+require 'chef/mash'
require 'chef/exceptions'
require 'chef/log'
require 'chef/config'
@@ -37,4 +37,4 @@ require 'chef/handler/json_file'
require 'chef/monkey_patches/tempfile'
require 'chef/monkey_patches/dir'
require 'chef/monkey_patches/string'
-require 'chef/monkey_patches/numeric' \ No newline at end of file
+require 'chef/monkey_patches/numeric'
diff --git a/chef/lib/chef/api_client.rb b/chef/lib/chef/api_client.rb
index 184b965b80..a202bccb27 100644
--- a/chef/lib/chef/api_client.rb
+++ b/chef/lib/chef/api_client.rb
@@ -23,7 +23,7 @@ require 'chef/mixin/from_file'
require 'chef/couchdb'
require 'chef/certificate'
require 'chef/index_queue'
-require 'extlib'
+require 'chef/mash'
require 'chef/json_compat'
class Chef
diff --git a/chef/lib/chef/cookbook/cookbook_collection.rb b/chef/lib/chef/cookbook/cookbook_collection.rb
index 16d85e389a..c4b05d5ea0 100644
--- a/chef/lib/chef/cookbook/cookbook_collection.rb
+++ b/chef/lib/chef/cookbook/cookbook_collection.rb
@@ -17,7 +17,7 @@
# limitations under the License.
#
-require 'extlib'
+require 'chef/mash'
class Chef
# == Chef::CookbookCollection
diff --git a/chef/lib/chef/data_bag.rb b/chef/lib/chef/data_bag.rb
index 7ba0944d4c..c0342f8437 100644
--- a/chef/lib/chef/data_bag.rb
+++ b/chef/lib/chef/data_bag.rb
@@ -24,7 +24,7 @@ require 'chef/mixin/from_file'
require 'chef/couchdb'
require 'chef/data_bag_item'
require 'chef/index_queue'
-require 'extlib'
+require 'chef/mash'
require 'chef/json_compat'
class Chef
diff --git a/chef/lib/chef/data_bag_item.rb b/chef/lib/chef/data_bag_item.rb
index 4d311ebfa9..1f23d5d750 100644
--- a/chef/lib/chef/data_bag_item.rb
+++ b/chef/lib/chef/data_bag_item.rb
@@ -26,7 +26,7 @@ require 'chef/mixin/from_file'
require 'chef/couchdb'
require 'chef/index_queue'
require 'chef/data_bag'
-require 'extlib'
+require 'chef/mash'
require 'chef/json_compat'
class Chef
diff --git a/chef/lib/chef/mash.rb b/chef/lib/chef/mash.rb
new file mode 100644
index 0000000000..368d806ba1
--- /dev/null
+++ b/chef/lib/chef/mash.rb
@@ -0,0 +1,211 @@
+# Copyright (c) 2009 Dan Kubb
+
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+# ---
+# ---
+
+# Some portions of blank.rb and mash.rb are verbatim copies of software
+# licensed under the MIT license. That license is included below:
+
+# Copyright (c) 2005-2008 David Heinemeier Hansson
+
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+# This class has dubious semantics and we only have it so that people can write
+# params[:key] instead of params['key'].
+class Mash < Hash
+
+ # @param constructor<Object>
+ # The default value for the mash. Defaults to an empty hash.
+ #
+ # @details [Alternatives]
+ # If constructor is a Hash, a new mash will be created based on the keys of
+ # the hash and no default value will be set.
+ def initialize(constructor = {})
+ if constructor.is_a?(Hash)
+ super()
+ update(constructor)
+ else
+ super(constructor)
+ end
+ end
+
+ # @param key<Object> The default value for the mash. Defaults to nil.
+ #
+ # @details [Alternatives]
+ # If key is a Symbol and it is a key in the mash, then the default value will
+ # be set to the value matching the key.
+ def default(key = nil)
+ if key.is_a?(Symbol) && include?(key = key.to_s)
+ self[key]
+ else
+ super
+ end
+ end
+
+ alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
+ alias_method :regular_update, :update unless method_defined?(:regular_update)
+
+ # @param key<Object> The key to set.
+ # @param value<Object>
+ # The value to set the key to.
+ #
+ # @see Mash#convert_key
+ # @see Mash#convert_value
+ def []=(key, value)
+ regular_writer(convert_key(key), convert_value(value))
+ end
+
+ # @param other_hash<Hash>
+ # A hash to update values in the mash with. The keys and the values will be
+ # converted to Mash format.
+ #
+ # @return [Mash] The updated mash.
+ def update(other_hash)
+ other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
+ self
+ end
+
+ alias_method :merge!, :update
+
+ # @param key<Object> The key to check for. This will be run through convert_key.
+ #
+ # @return [Boolean] True if the key exists in the mash.
+ def key?(key)
+ super(convert_key(key))
+ end
+
+ # def include? def has_key? def member?
+ alias_method :include?, :key?
+ alias_method :has_key?, :key?
+ alias_method :member?, :key?
+
+ # @param key<Object> The key to fetch. This will be run through convert_key.
+ # @param *extras<Array> Default value.
+ #
+ # @return [Object] The value at key or the default value.
+ def fetch(key, *extras)
+ super(convert_key(key), *extras)
+ end
+
+ # @param *indices<Array>
+ # The keys to retrieve values for. These will be run through +convert_key+.
+ #
+ # @return [Array] The values at each of the provided keys
+ def values_at(*indices)
+ indices.collect {|key| self[convert_key(key)]}
+ end
+
+ # @param hash<Hash> The hash to merge with the mash.
+ #
+ # @return [Mash] A new mash with the hash values merged in.
+ def merge(hash)
+ self.dup.update(hash)
+ end
+
+ # @param key<Object>
+ # The key to delete from the mash.\
+ def delete(key)
+ super(convert_key(key))
+ end
+
+ # @param *rejected<Array[(String, Symbol)] The mash keys to exclude.
+ #
+ # @return [Mash] A new mash without the selected keys.
+ #
+ # @example
+ # { :one => 1, :two => 2, :three => 3 }.except(:one)
+ # #=> { "two" => 2, "three" => 3 }
+ def except(*keys)
+ super(*keys.map {|k| convert_key(k)})
+ end
+
+ # Used to provide the same interface as Hash.
+ #
+ # @return [Mash] This mash unchanged.
+ def stringify_keys!; self end
+
+ # @return [Hash] The mash as a Hash with symbolized keys.
+ def symbolize_keys
+ h = Hash.new(default)
+ each { |key, val| h[key.to_sym] = val }
+ h
+ end
+
+ # @return [Hash] The mash as a Hash with string keys.
+ def to_hash
+ Hash.new(default).merge(self)
+ end
+
+ # @return [Mash] Convert a Hash into a Mash
+ # The input Hash's default value is maintained
+ def self.from_hash(hash)
+ mash = Mash.new(hash)
+ mash.default = hash.default
+ mash
+ end
+
+ protected
+ # @param key<Object> The key to convert.
+ #
+ # @param [Object]
+ # The converted key. If the key was a symbol, it will be converted to a
+ # string.
+ #
+ # @api private
+ def convert_key(key)
+ key.kind_of?(Symbol) ? key.to_s : key
+ end
+
+ # @param value<Object> The value to convert.
+ #
+ # @return [Object]
+ # The converted value. A Hash or an Array of hashes, will be converted to
+ # their Mash equivalents.
+ #
+ # @api private
+ def convert_value(value)
+ if value.class == Hash
+ Mash.from_hash(value)
+ elsif value.is_a?(Array)
+ value.collect { |e| convert_value(e) }
+ else
+ value
+ end
+ end
+end
diff --git a/chef/lib/chef/node.rb b/chef/lib/chef/node.rb
index 0d93aba091..c390ea7cbb 100644
--- a/chef/lib/chef/node.rb
+++ b/chef/lib/chef/node.rb
@@ -33,7 +33,7 @@ require 'chef/rest'
require 'chef/run_list'
require 'chef/node/attribute'
require 'chef/index_queue'
-require 'extlib'
+require 'chef/mash'
require 'chef/json_compat'
class Chef
diff --git a/chef/lib/chef/role.rb b/chef/lib/chef/role.rb
index 0227b2822e..28ef2aac2a 100644
--- a/chef/lib/chef/role.rb
+++ b/chef/lib/chef/role.rb
@@ -24,7 +24,7 @@ require 'chef/mixin/from_file'
require 'chef/couchdb'
require 'chef/run_list'
require 'chef/index_queue'
-require 'extlib'
+require 'chef/mash'
require 'chef/json_compat'
class Chef
diff --git a/chef/lib/chef/run_list/run_list_expansion.rb b/chef/lib/chef/run_list/run_list_expansion.rb
index 37d5dd36d7..7323dba7be 100644
--- a/chef/lib/chef/run_list/run_list_expansion.rb
+++ b/chef/lib/chef/run_list/run_list_expansion.rb
@@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-require 'extlib'
+require 'chef/mash'
require 'chef/mixin/deep_merge'