diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-08-09 10:05:47 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-08-09 10:05:47 -0700 |
commit | b7a5d28ac34d4661bb8a4e2e92d25e023f60f987 (patch) | |
tree | 99fede241b3b91687a15e55a9d045885562c8056 /lib/chef | |
parent | adbb0fa85cc45b93ba91dc3019094b312cafb35c (diff) | |
download | chef-b7a5d28ac34d4661bb8a4e2e92d25e023f60f987.tar.gz |
Revert "remove #to_json Monkeytpatching"
This reverts commit adbb0fa85cc45b93ba91dc3019094b312cafb35c.
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/api_client.rb | 2 | ||||
-rw-r--r-- | lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb | 1 | ||||
-rw-r--r-- | lib/chef/chef_fs/file_system/rest_list_entry.rb | 2 | ||||
-rw-r--r-- | lib/chef/cookbook/metadata.rb | 4 | ||||
-rw-r--r-- | lib/chef/cookbook_version.rb | 5 | ||||
-rw-r--r-- | lib/chef/data_bag.rb | 7 | ||||
-rw-r--r-- | lib/chef/data_bag_item.rb | 12 | ||||
-rw-r--r-- | lib/chef/environment.rb | 4 | ||||
-rw-r--r-- | lib/chef/exceptions.rb | 5 | ||||
-rw-r--r-- | lib/chef/handler/json_file.rb | 1 | ||||
-rw-r--r-- | lib/chef/json_compat.rb | 10 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_share.rb | 2 | ||||
-rw-r--r-- | lib/chef/node.rb | 3 | ||||
-rw-r--r-- | lib/chef/provider/deploy/revision.rb | 2 | ||||
-rw-r--r-- | lib/chef/resource.rb | 4 | ||||
-rw-r--r-- | lib/chef/resource_collection.rb | 10 | ||||
-rw-r--r-- | lib/chef/resource_reporter.rb | 6 | ||||
-rw-r--r-- | lib/chef/role.rb | 2 | ||||
-rw-r--r-- | lib/chef/run_list.rb | 9 | ||||
-rw-r--r-- | lib/chef/user.rb | 2 | ||||
-rw-r--r-- | lib/chef/util/diff.rb | 3 |
21 files changed, 49 insertions, 47 deletions
diff --git a/lib/chef/api_client.rb b/lib/chef/api_client.rb index e8585106e4..7b7fd99ff7 100644 --- a/lib/chef/api_client.rb +++ b/lib/chef/api_client.rb @@ -121,7 +121,7 @@ class Chef # # @return [String] the JSON string. def to_json(*a) - ::Chef::JSONCompat.to_json(to_hash, *a) + to_hash.to_json(*a) end def self.json_create(o) diff --git a/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb b/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb index 1b99a0a9cd..3d3f58201e 100644 --- a/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +++ b/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb @@ -41,7 +41,6 @@ class Chef def chef_object begin - # FIXME: FFI_Yajl needs to support :create_additions and this needs to use it return data_handler.chef_object(JSON.parse(read, :create_additions => false)) rescue Chef::Log.error("Could not read #{path_for_printing} into a Chef object: #{$!}") diff --git a/lib/chef/chef_fs/file_system/rest_list_entry.rb b/lib/chef/chef_fs/file_system/rest_list_entry.rb index ce1b27df6a..0d5557de1d 100644 --- a/lib/chef/chef_fs/file_system/rest_list_entry.rb +++ b/lib/chef/chef_fs/file_system/rest_list_entry.rb @@ -128,7 +128,6 @@ class Chef value = minimize_value(value) value_json = Chef::JSONCompat.to_json_pretty(value) begin - # FIXME: replace with FFI_Yajl when it supports :create_additions other_value = JSON.parse(other_value_json, :create_additions => false) rescue JSON::ParserError => e Chef::Log.warn("Parse error reading #{other.path_for_printing} as JSON: #{e}") @@ -146,7 +145,6 @@ class Chef def write(file_contents) begin - # FIXME: replace with FFI_Yajl when it supports :create_additions object = JSON.parse(file_contents, :create_additions => false) rescue JSON::ParserError => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e), "Parse error reading JSON: #{e}" diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb index 1ab7760209..32574c75e2 100644 --- a/lib/chef/cookbook/metadata.rb +++ b/lib/chef/cookbook/metadata.rb @@ -24,7 +24,6 @@ require 'chef/mixin/params_validate' require 'chef/log' require 'chef/version_class' require 'chef/version_constraint' -require 'chef/json_compat' class Chef class Cookbook @@ -442,7 +441,7 @@ class Chef end def to_json(*a) - ::Chef::JSONCompat.to_json(to_hash, *a) + self.to_hash.to_json(*a) end def self.from_hash(o) @@ -652,5 +651,6 @@ INVALID end end + end end diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index 2291caabd8..778a6043bf 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -405,6 +405,7 @@ class Chef records_by_pref[best_pref] end + # Given a node, segment and path (filename or directory name), # return the priority-ordered list of preference locations to # look. @@ -457,9 +458,9 @@ class Chef end def to_json(*a) - result = to_hash + result = self.to_hash result['json_class'] = self.class.name - ::Chef::JSONCompat.to_json(result, *a) + result.to_json(*a) end def self.json_create(o) diff --git a/lib/chef/data_bag.rb b/lib/chef/data_bag.rb index a901517a65..1133aa3e73 100644 --- a/lib/chef/data_bag.rb +++ b/lib/chef/data_bag.rb @@ -54,16 +54,16 @@ class Chef def to_hash result = { - 'name' => @name, + "name" => @name, 'json_class' => self.class.name, - 'chef_type' => 'data_bag', + "chef_type" => "data_bag", } result end # Serialize this object as a hash def to_json(*a) - ::Chef::JSONCompat.to_json(to_hash, *a) + to_hash.to_json(*a) end def chef_server_rest @@ -164,3 +164,4 @@ class Chef end end + diff --git a/lib/chef/data_bag_item.rb b/lib/chef/data_bag_item.rb index a537880f41..07dd15a1dc 100644 --- a/lib/chef/data_bag_item.rb +++ b/lib/chef/data_bag_item.rb @@ -112,13 +112,13 @@ class Chef # Serialize this object as a hash def to_json(*a) result = { - "name" => object_name, + "name" => self.object_name, "json_class" => self.class.name, - "chef_type" => "data_bag_item", - "data_bag" => data_bag, - "raw_data" => raw_data + "chef_type" => "data_bag_item", + "data_bag" => self.data_bag, + "raw_data" => self.raw_data } - ::Chef::JSONCompat.to_json(result, *a) + result.to_json(*a) end def self.from_hash(h) @@ -210,3 +210,5 @@ class Chef end end + + diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb index 84487492d0..5c719ca285 100644 --- a/lib/chef/environment.rb +++ b/lib/chef/environment.rb @@ -129,7 +129,7 @@ class Chef end def to_json(*a) - ::Chef::JSONCompat.to_json(to_hash, *a) + to_hash.to_json(*a) end def update_from!(o) @@ -140,6 +140,7 @@ class Chef self end + def update_attributes_from_params(params) unless params[:default_attributes].nil? || params[:default_attributes].size == 0 default_attributes(Chef::JSONCompat.from_json(params[:default_attributes])) @@ -212,6 +213,7 @@ class Chef end end + def self.json_create(o) environment = new environment.name(o["name"]) diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb index 9f4e1edd66..8c1a285095 100644 --- a/lib/chef/exceptions.rb +++ b/lib/chef/exceptions.rb @@ -195,6 +195,7 @@ class Chef end end + end # Exception class for collecting multiple failures. Used when running # delayed notifications so that chef can process each delayed @@ -262,7 +263,7 @@ class Chef "non_existent_cookbooks" => non_existent_cookbooks, "cookbooks_with_no_versions" => cookbooks_with_no_matching_versions } - ::Chef::JSONCompat.to_json(result, *a) + result.to_json(*a) end end @@ -297,7 +298,7 @@ class Chef "non_existent_cookbooks" => non_existent_cookbooks, "most_constrained_cookbooks" => most_constrained_cookbooks } - ::Chef::JSONCompat.to_json(result, *a) + result.to_json(*a) end end diff --git a/lib/chef/handler/json_file.rb b/lib/chef/handler/json_file.rb index 405c91795e..3473db1838 100644 --- a/lib/chef/handler/json_file.rb +++ b/lib/chef/handler/json_file.rb @@ -58,6 +58,7 @@ class Chef end end + end end end diff --git a/lib/chef/json_compat.rb b/lib/chef/json_compat.rb index baab1386f6..2dbb607d9b 100644 --- a/lib/chef/json_compat.rb +++ b/lib/chef/json_compat.rb @@ -18,6 +18,7 @@ # Wrapper class for interacting with JSON. require 'ffi_yajl' +require 'ffi_yajl/json_gem' # XXX: parts of chef require JSON gem's Hash#to_json monkeypatch class Chef class JSONCompat @@ -87,17 +88,14 @@ class Chef end def to_json(obj, opts = nil) - ::FFI_Yajl::Encoder.encode(obj, opts) + obj.to_json(opts) end def to_json_pretty(obj, opts = nil) - opts ||= {} - options_map = {} - options_map[:pretty] = true - options_map[:indent] = opts[:indent] if opts.has_key?(:indent) - ::FFI_Yajl::Encoder.encode(obj, options_map).chomp + ::JSON.pretty_generate(obj, opts) end + # Map +json_class+ to a Class object. We use a +case+ instead of a Hash # assigned to a constant because otherwise this file could not be loaded # until all the constants were defined, which means you'd have to load diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb index 08841191fe..330f3cb229 100644 --- a/lib/chef/knife/cookbook_site_share.rb +++ b/lib/chef/knife/cookbook_site_share.rb @@ -87,7 +87,7 @@ class Chef def do_upload(cookbook_filename, cookbook_category, user_id, user_secret_filename) uri = "http://cookbooks.opscode.com/api/v1/cookbooks" - category_string = ::Chef::JSONCompat.to_json({ 'category'=>cookbook_category }) + category_string = { 'category'=>cookbook_category }.to_json http_resp = Chef::CookbookSiteStreamingUploader.post(uri, user_id, user_secret_filename, { :tarball => File.open(cookbook_filename), diff --git a/lib/chef/node.rb b/lib/chef/node.rb index e9c0d09751..17ec1d0f0a 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -181,6 +181,7 @@ class Chef attributes.override end + def override_attrs attributes.override end @@ -415,7 +416,7 @@ class Chef # Serialize this object as a hash def to_json(*a) - ::Chef::JSONCompat.to_json(for_json, *a) + for_json.to_json(*a) end def for_json diff --git a/lib/chef/provider/deploy/revision.rb b/lib/chef/provider/deploy/revision.rb index 386718532a..f1eb171cd7 100644 --- a/lib/chef/provider/deploy/revision.rb +++ b/lib/chef/provider/deploy/revision.rb @@ -97,7 +97,7 @@ class Chef end def save_cache(cache) - Chef::FileCache.store("revision-deploys/#{new_resource.name}", ::Chef::JSONCompat.to_json(cache)) + Chef::FileCache.store("revision-deploys/#{new_resource.name}", cache.to_json) cache end diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index dfbef293ec..6c8e0434a0 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -134,6 +134,7 @@ F extend Chef::Mixin::ConvertToClassName + if Module.method(:const_defined?).arity == 1 def self.strict_const_defined?(const) const_defined?(const) @@ -276,6 +277,7 @@ F end end + def updated=(true_or_false) Chef::Log.warn("Chef::Resource#updated=(true|false) is deprecated. Please call #updated_by_last_action(true|false) instead.") Chef::Log.warn("Called from:") @@ -542,7 +544,7 @@ F # Serialize this object as a hash def to_json(*a) results = as_json - ::Chef::JSONCompat.to_json(results, *a) + results.to_json(*a) end def to_hash diff --git a/lib/chef/resource_collection.rb b/lib/chef/resource_collection.rb index e22e6ce026..a528a18aed 100644 --- a/lib/chef/resource_collection.rb +++ b/lib/chef/resource_collection.rb @@ -158,6 +158,7 @@ class Chef # compat. alias_method :resources, :find + # Returns true if +query_object+ is a valid string for looking up a # resource, or raises InvalidResourceSpecification if not. # === Arguments @@ -188,19 +189,16 @@ class Chef end # Serialize this object as a hash - def to_hash + def to_json(*a) instance_vars = Hash.new self.instance_variables.each do |iv| instance_vars[iv] = self.instance_variable_get(iv) end - { + results = { 'json_class' => self.class.name, 'instance_vars' => instance_vars } - end - - def to_json(*a) - ::Chef::JSONCompat.to_json(to_hash, *a) + results.to_json(*a) end def self.json_create(o) diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb index 78e41c1556..046e4e82c6 100644 --- a/lib/chef/resource_reporter.rb +++ b/lib/chef/resource_reporter.rb @@ -230,7 +230,7 @@ class Chef resource_history_url = "reports/nodes/#{node_name}/runs/#{run_id}" Chef::Log.info("Sending resource update report (run-id: #{run_id})") Chef::Log.debug run_data.inspect - compressed_data = encode_gzip(::Chef::JSONCompat.to_json(run_data)) + compressed_data = encode_gzip(run_data.to_json) Chef::Log.debug("Sending compressed run data...") # Since we're posting compressed data we can not directly call post_rest which expects JSON reporting_url = @rest_client.create_url(resource_history_url) @@ -273,7 +273,7 @@ class Chef resource_record.for_json end run_data["status"] = @status - run_data["run_list"] = ::Chef::JSONCompat.to_json(@run_status.node.run_list) + run_data["run_list"] = @run_status.node.run_list.to_json run_data["total_res_count"] = @total_res_count.to_s run_data["data"] = {} run_data["start_time"] = start_time.to_s @@ -283,7 +283,7 @@ class Chef exception_data = {} exception_data["class"] = exception.inspect exception_data["message"] = exception.message - exception_data["backtrace"] = ::Chef::JSONCompat.to_json(exception.backtrace) + exception_data["backtrace"] = exception.backtrace.to_json exception_data["description"] = @error_descriptions run_data["data"]["exception"] = exception_data end diff --git a/lib/chef/role.rb b/lib/chef/role.rb index 232a7e18cd..57f3a2aa29 100644 --- a/lib/chef/role.rb +++ b/lib/chef/role.rb @@ -143,7 +143,7 @@ class Chef # Serialize this object as a hash def to_json(*a) - ::Chef::JSONCompat.to_json(to_hash, *a) + to_hash.to_json(*a) end def update_from!(o) diff --git a/lib/chef/run_list.rb b/lib/chef/run_list.rb index fbdbaaa1cc..684c5e19fc 100644 --- a/lib/chef/run_list.rb +++ b/lib/chef/run_list.rb @@ -85,12 +85,8 @@ class Chef @run_list_items.join(", ") end - def for_json - to_a.map { |item| item.to_s } - end - - def to_json(*a) - ::Chef::JSONCompat.to_json(for_json, *a) + def to_json(*args) + to_a.map { |item| item.to_s}.to_json(*args) end def empty? @@ -162,5 +158,6 @@ class Chef end end + end end diff --git a/lib/chef/user.rb b/lib/chef/user.rb index 4f939556b4..e2ef45dc5c 100644 --- a/lib/chef/user.rb +++ b/lib/chef/user.rb @@ -73,7 +73,7 @@ class Chef end def to_json(*a) - ::Chef::JSONCompat.to_json(to_hash, *a) + to_hash.to_json(*a) end def destroy diff --git a/lib/chef/util/diff.rb b/lib/chef/util/diff.rb index 3117484a71..7bce52d874 100644 --- a/lib/chef/util/diff.rb +++ b/lib/chef/util/diff.rb @@ -82,7 +82,7 @@ class Chef end end end - + # produces a unified-output-format diff with 3 lines of context # ChefFS uses udiff() directly def udiff(old_file, new_file) @@ -185,3 +185,4 @@ class Chef end end end + |