lib/duracloud/content.rb in duracloud-client-0.9.1 vs lib/duracloud/content.rb in duracloud-client-0.10.0

- old
+ new

@@ -1,7 +1,5 @@ -require "active_model" - module Duracloud # # A piece of content in DuraCloud # class Content < AbstractEntity @@ -11,10 +9,21 @@ CHUNK_SIZE = 1024 * 16 COPY_SOURCE_HEADER = "x-dura-meta-copy-source" COPY_SOURCE_STORE_HEADER = "x-dura-meta-copy-source-store" MANIFEST_EXT = ".dura-manifest" + property :space_id, required: true + property :content_id, required: true + property :store_id + property :body + property :md5 + property :content_type + property :size + property :modified + + alias_method :id, :content_id + # Does the content exist in DuraCloud? # @return [Boolean] whether the content exists. # @raise [Duracloud::MessageDigestError] the provided digest in the :md5 keyword option, # if given, does not match the stored value. def self.exist?(**kwargs) @@ -43,14 +52,18 @@ # if given, does not match the stored value. def self.create(**kwargs) new(**kwargs).save end - attr_accessor :space_id, :content_id, :store_id, - :body, :md5, :content_type, :size, :modified - alias_method :id, :content_id - validates_presence_of :space_id, :content_id + # Delete content from DuraCloud. + # @return [Duraclound::Content] the deleted content. + # @raise [Duracloud::NotFoundError] the space, content or store (if given) does not exist. + # @raise [Duracloud::MessageDigestError] the provided digest in the :md5 keyword option, + # if given, does not match the stored value. + def self.delete(**kwargs) + find(**kwargs).delete + end # Return the space associated with this content. # @return [Duracloud::Space] the space. # @raise [Duracloud::NotFoundError] the space or store does not exist. def space @@ -79,10 +92,10 @@ # @return [Duracloud::Content] the copied content # The current instance still represents the original content. # @raise [Duracloud::Error] def copy(**args) - dest = args.except(:force) + dest = args.reject { |k, v| k == :force } dest[:space_id] ||= space_id dest[:store_id] ||= store_id dest[:content_id] ||= content_id if dest == copy_source raise CopyError, "Destination is the same as the source."