Class: Duracloud::Content
- Inherits:
-
AbstractEntity
- Object
- Hashie::Dash
- AbstractEntity
- Duracloud::Content
- Defined in:
- lib/duracloud/content.rb
Overview
A piece of content in DuraCloud
Direct Known Subclasses
Defined Under Namespace
Classes: CopyError
Constant Summary collapse
- 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"
Class Method Summary collapse
-
.create(**kwargs) ⇒ Duraclound::Content
Create new content in DuraCloud.
-
.delete(**kwargs) ⇒ Duraclound::Content
Delete content from DuraCloud.
-
.exist?(**kwargs) ⇒ Boolean
Does the content exist in DuraCloud?.
-
.find(**kwargs) ⇒ Duraclound::Content
Find content in DuraCloud.
Instance Method Summary collapse
- #chunked? ⇒ Boolean
-
#copy(**args) ⇒ Duracloud::Content
The copied content The current instance still represents the original content.
-
#download {|String| ... } ⇒ Duracloud::Response
Downloads the remote content.
-
#empty? ⇒ Boolean
Is the content empty?.
- #human_size ⇒ Object
- #inspect ⇒ Object
-
#move(**args) ⇒ Duracloud::Content
The moved content The current instance still represents the deleted content.
-
#space ⇒ Duracloud::Space
Return the space associated with this content.
Methods inherited from AbstractEntity
#delete, #deleted?, #load_properties, #persisted?, #properties, #save
Class Method Details
.create(**kwargs) ⇒ Duraclound::Content
Create new content in DuraCloud.
53 54 55 |
# File 'lib/duracloud/content.rb', line 53 def self.create(**kwargs) new(**kwargs).save end |
.delete(**kwargs) ⇒ Duraclound::Content
Delete content from DuraCloud.
62 63 64 |
# File 'lib/duracloud/content.rb', line 62 def self.delete(**kwargs) find(**kwargs).delete end |
.exist?(**kwargs) ⇒ Boolean
Does the content exist in DuraCloud?
29 30 31 32 33 |
# File 'lib/duracloud/content.rb', line 29 def self.exist?(**kwargs) find(**kwargs) && true rescue NotFoundError false end |
.find(**kwargs) ⇒ Duraclound::Content
Find content in DuraCloud.
40 41 42 43 44 45 46 |
# File 'lib/duracloud/content.rb', line 40 def self.find(**kwargs) new(**kwargs).tap do |content| content.load_properties end rescue NotFoundError => e ChunkedContent.find(**kwargs) end |
Instance Method Details
#chunked? ⇒ Boolean
125 126 127 |
# File 'lib/duracloud/content.rb', line 125 def chunked? false end |
#copy(**args) ⇒ Duracloud::Content
Returns the copied content The current instance still represents the original content.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/duracloud/content.rb', line 96 def copy(**args) 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." end if !args[:force] && Content.exist?(**dest) raise CopyError, "Destination exists and `:force' option is false." end = { storeID: dest[:store_id], headers: copy_headers } response = Client.copy_content(dest[:space_id], dest[:content_id], **) if md5 != response.md5 raise CopyError, "Message digest of copy does not match source " \ "(source: #{md5}; destination: #{response.md5})" end Content.new(dest.merge(md5: md5)) end |
#download {|String| ... } ⇒ Duracloud::Response
Downloads the remote content
89 90 91 |
# File 'lib/duracloud/content.rb', line 89 def download(&block) Client.get_content(*args, **query, &block) end |
#empty? ⇒ Boolean
Is the content empty?
81 82 83 |
# File 'lib/duracloud/content.rb', line 81 def empty? body.nil? || ( body.respond_to?(:size) && body.size == 0 ) end |
#human_size ⇒ Object
129 130 131 |
# File 'lib/duracloud/content.rb', line 129 def human_size ActiveSupport::NumberHelper.number_to_human_size(size, prefix: :si) end |
#inspect ⇒ Object
73 74 75 76 77 |
# File 'lib/duracloud/content.rb', line 73 def inspect "#<#{self.class} space_id=#{space_id.inspect}," \ " content_id=#{content_id.inspect}," \ " store_id=#{store_id || '(default)'}>" end |
#move(**args) ⇒ Duracloud::Content
Returns the moved content The current instance still represents the deleted content.
119 120 121 122 123 |
# File 'lib/duracloud/content.rb', line 119 def move(**args) copied = copy(**args) delete copied end |
#space ⇒ Duracloud::Space
Return the space associated with this content.
69 70 71 |
# File 'lib/duracloud/content.rb', line 69 def space @space ||= Space.find(space_id, store_id) end |