lib/ridley/resources/cookbook_resource.rb in ridley-0.12.0.rc1 vs lib/ridley/resources/cookbook_resource.rb in ridley-0.12.0
- old
+ new
@@ -47,24 +47,23 @@
url = "#{self.class.resource_path}/#{name}/#{version}"
url += "?purge=true" if options[:purge]
request(:delete, url)
true
- rescue Errors::HTTPNotFound
- true
+ rescue AbortError => ex
+ return nil if ex.cause.is_a?(Errors::HTTPNotFound)
+ abort(ex.cause)
end
# Delete all of the versions of a given cookbook on the remote Chef server
#
# @param [String] name
# name of the cookbook to delete
#
# @option options [Boolean] purge (false)
def delete_all(name, options = {})
- versions(name).each do |version|
- future(:delete, name, version, options)
- end.map(&:value)
+ versions(name).collect { |version| future(:delete, name, version, options) }.map(&:value)
end
# Download the entire cookbook
#
# @param [String] name
@@ -90,12 +89,13 @@
#
# @return [nil, CookbookResource]
def find(object, version)
chef_id = object.respond_to?(:chef_id) ? object.chef_id : object
new(request(:get, "#{self.class.resource_path}/#{chef_id}/#{version}"))
- rescue Errors::HTTPNotFound
- nil
+ rescue AbortError => ex
+ return nil if ex.cause.is_a?(Errors::HTTPNotFound)
+ abort(ex.cause)
end
# Return the latest version of the given cookbook found on the remote Chef server
#
# @param [String] name
@@ -155,12 +155,15 @@
url = "cookbooks/#{cookbook.cookbook_name}/#{cookbook.version}"
url << "?force=true" if options[:force]
request(:put, url, cookbook.to_json)
- rescue Ridley::Errors::HTTPConflict => ex
- abort Ridley::Errors::FrozenCookbook.new(ex)
+ rescue AbortError => ex
+ if ex.cause.is_a?(Errors::HTTPConflict)
+ abort Ridley::Errors::FrozenCookbook.new(ex)
+ end
+ abort(ex.cause)
end
alias_method :create, :update
# Uploads a cookbook to the remote Chef server from the contents of a filepath
#
@@ -219,11 +222,14 @@
response = request(:get, "#{self.class.resource_path}/#{name}")
response[name]["versions"].collect do |cb_ver|
cb_ver["version"]
end
- rescue Errors::HTTPNotFound => ex
- abort(Errors::ResourceNotFound.new(ex))
+ rescue AbortError => ex
+ if ex.cause.is_a?(Errors::HTTPNotFound)
+ abort Errors::ResourceNotFound.new(ex)
+ end
+ abort(ex.cause)
end
private
attr_reader :sandbox_resource