summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2015-02-05 17:53:00 -0800
committerdanielsdeleo <dan@getchef.com>2015-02-11 10:52:49 -0800
commit677ca0d7e3366ea9b3b6a912c8c6c28d543e2046 (patch)
tree512473fe4a623586d86eee948efc43857d800d8e
parente3e9f1996131f287f0e6d8b344e658062003efe7 (diff)
downloadchef-677ca0d7e3366ea9b3b6a912c8c6c28d543e2046.tar.gz
Move remaining http relevant methods to CookbookManifest
-rw-r--r--lib/chef/cookbook_manifest.rb65
-rw-r--r--lib/chef/cookbook_version.rb59
2 files changed, 73 insertions, 51 deletions
diff --git a/lib/chef/cookbook_manifest.rb b/lib/chef/cookbook_manifest.rb
index 82d4da7008..417afbd82c 100644
--- a/lib/chef/cookbook_manifest.rb
+++ b/lib/chef/cookbook_manifest.rb
@@ -36,6 +36,8 @@ class Chef
def_delegator :@cookbook_version, :name
def_delegator :@cookbook_version, :metadata
def_delegator :@cookbook_version, :full_name
+ def_delegator :@cookbook_version, :version
+ def_delegator :@cookbook_version, :frozen_version?
def initialize(cookbook_version)
@cookbook_version = cookbook_version
@@ -97,6 +99,51 @@ class Chef
@manifest_records_by_path
end
+ def to_hash
+ result = manifest.dup
+ result['frozen?'] = frozen_version?
+ result['chef_type'] = 'cookbook_version'
+ result.to_hash
+ end
+
+ def to_json(*a)
+ result = to_hash
+ result['json_class'] = "Chef::CookbookVersion"
+ Chef::JSONCompat.to_json(result, *a)
+ end
+
+ # Return the URL to save (PUT) this object to the server via the
+ # REST api. If there is an existing document on the server and it
+ # is marked frozen, a PUT will result in a 409 Conflict.
+ def save_url
+ "cookbooks/#{name}/#{version}"
+ end
+
+ # Adds the `force=true` parameter to the upload URL. This allows
+ # the user to overwrite a frozen cookbook (a PUT against the
+ # normal #save_url raises a 409 Conflict in this case).
+ def force_save_url
+ "cookbooks/#{name}/#{version}?force=true"
+ end
+
+ # TODO: This is kind of terrible. investigate removing it
+ def update_from(new_manifest)
+ @manifest = Mash.new new_manifest
+ @checksums = extract_checksums_from_manifest(@manifest)
+ @manifest_records_by_path = extract_manifest_records_by_path(@manifest)
+
+ # TODO: this part of this method is "feature envious" it only deals with
+ # mutating the CookbookVersion object.
+ COOKBOOK_SEGMENTS.each do |segment|
+ next unless @manifest.has_key?(segment)
+ filenames = @manifest[segment].map{|manifest_record| manifest_record['name']}
+
+ cookbook_version.replace_segment_filenames(segment, filenames)
+ end
+ end
+
+ private
+
# See #manifest for a description of the manifest return value.
# See #preferred_manifest_record for a description an individual manifest record.
def generate_manifest
@@ -147,24 +194,6 @@ class Chef
@manifest = manifest
end
- # TODO: This is kind of terrible. investigate removing it
- def update_from(new_manifest)
- @manifest = Mash.new new_manifest
- @checksums = extract_checksums_from_manifest(@manifest)
- @manifest_records_by_path = extract_manifest_records_by_path(@manifest)
-
- # TODO: this part of this method is "feature envious" it only deals with
- # mutating the CookbookVersion object.
- COOKBOOK_SEGMENTS.each do |segment|
- next unless @manifest.has_key?(segment)
- filenames = @manifest[segment].map{|manifest_record| manifest_record['name']}
-
- cookbook_version.replace_segment_filenames(segment, filenames)
- end
- end
-
- private
-
def parse_segment_file_from_root_paths(segment, segment_file)
root_paths.each do |root_path|
pathname = Chef::Util::PathHelper.relative_path_from(root_path, segment_file)
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index 025828beb5..c26ab46565 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -63,14 +63,27 @@ class Chef
cookbook_manifest.update_from(new_manifest)
end
+ def save_url
+ cookbook_manifest.save_url
+ end
+
+ def force_save_url
+ cookbook_manifest.force_save_url
+ end
+
+ def to_hash
+ cookbook_manifest.to_hash
+ end
+
+ def to_json(*a)
+ cookbook_manifest.to_json
+ end
+
include Comparable
COOKBOOK_SEGMENTS = [ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates, :root_files ]
- # TODO: deprecate setter
attr_accessor :root_paths
-
- # TODO: deprecate setter for all *_filenames, only used when consuming JSON
attr_accessor :definition_filenames
attr_accessor :template_filenames
attr_accessor :file_filenames
@@ -81,8 +94,15 @@ class Chef
attr_accessor :name
attr_accessor :metadata_filenames
- # TODO: unused, deprecate
- attr_accessor :status
+ def status=(new_status)
+ Chef::Log.warn("Deprecated method `status' called from #{caller(1).first}. This method will be removed")
+ @status = new_status
+ end
+
+ def status
+ Chef::Log.warn("Deprecated method `status' called from #{caller(1).first}. This method will be removed")
+ @status
+ end
# A Chef::Cookbook::Metadata object. It has a setter that fixes up the
# metadata to add descriptions of the recipes contained in this
@@ -139,7 +159,7 @@ class Chef
@metadata_filenames = Array.new
@root_filenames = Array.new
- # TODO: unused, deprecate.
+ # deprecated
@status = :ready
@file_vendor = nil
@metadata = Chef::Cookbook::Metadata.new
@@ -448,19 +468,6 @@ class Chef
end
private :preferences_for_path
- def to_hash
- result = manifest.dup
- result['frozen?'] = frozen_version?
- result['chef_type'] = 'cookbook_version'
- result.to_hash
- end
-
- def to_json(*a)
- result = to_hash
- result['json_class'] = self.class.name
- Chef::JSONCompat.to_json(result, *a)
- end
-
def self.json_create(o)
cookbook_version = new(o["cookbook_name"])
# We want the Chef::Cookbook::Metadata object to always be inflated
@@ -516,20 +523,6 @@ class Chef
self.class.chef_server_rest
end
- # Return the URL to save (PUT) this object to the server via the
- # REST api. If there is an existing document on the server and it
- # is marked frozen, a PUT will result in a 409 Conflict.
- def save_url
- "cookbooks/#{name}/#{version}"
- end
-
- # Adds the `force=true` parameter to the upload URL. This allows
- # the user to overwrite a frozen cookbook (a PUT against the
- # normal #save_url raises a 409 Conflict in this case).
- def force_save_url
- "cookbooks/#{name}/#{version}?force=true"
- end
-
def destroy
chef_server_rest.delete_rest("cookbooks/#{name}/#{version}")
self