Class: Duracloud::Space
- Inherits:
-
AbstractEntity
- Object
- Hashie::Dash
- AbstractEntity
- Duracloud::Space
- Defined in:
- lib/duracloud/space.rb
Overview
A “space” within a DuraCloud account.
Constant Summary collapse
- MAX_RESULTS =
Max size of content item list for one request.
This limit is imposed by Duracloud.
1000
Class Method Summary collapse
-
.all(store_id = nil) ⇒ Array<Duracloud::Space>
List all spaces.
-
.audit_log(*args) ⇒ Duracloud::AuditLog
Return the audit log for the space.
-
.bit_integrity_report(*args) ⇒ Duracloud::BitIntegrityReport
Return the bit integrity report for the space.
-
.content_ids(space_id, store_id: nil, prefix: nil, start_after: nil) ⇒ Enumerator
Enumerates the content IDs in the space.
-
.count(*args) ⇒ Fixnum
Return the number of items in the space.
-
.create(*args) ⇒ Duracloud::Space
Create a new space.
-
.exist?(*args) ⇒ Boolean
Does the space exist?.
-
.find(*args) ⇒ Duracloud::Space
Find a space.
-
.ids(store_id = nil) ⇒ Array<String>
List all space IDs.
-
.items(space_id, store_id: nil, prefix: nil, start_after: nil) ⇒ Enumerator
Enumerates the content items in the space.
-
.manifest(*args) ⇒ Duracloud::Manifest
Return the manifest for the space.
Instance Method Summary collapse
-
#acls ⇒ Duracloud::SpaceAcls
Return the ACLs for the space.
-
#audit_log ⇒ Duracloud::AuditLog
Return the audit log for the space.
-
#bit_integrity_report ⇒ Duracloud::BitIntegrityReport
Return the bit integrity report for the space.
-
#content_ids(prefix: nil, start_after: nil) ⇒ Enumerator
Enumerates the content IDs in the space.
-
#count ⇒ Fixnum
Return the number of items in the space.
-
#created ⇒ DateTime
Return the creation date of the space, if persisted, or nil.
-
#find_content(content_id) ⇒ Duracloud::Content
Find a content item in the space.
-
#initialize(space_id, store_id = nil) {|_self| ... } ⇒ Space
constructor
A new instance of Space.
- #inspect ⇒ Object
-
#items(*args) ⇒ Enumerator
Enumerates the content items in the space.
-
#manifest ⇒ Duracloud::Manifest
Return the manifest for the space.
- #to_s ⇒ Object
Methods inherited from AbstractEntity
#delete, #deleted?, #load_properties, #persisted?, #properties, #save
Constructor Details
#initialize(space_id, store_id = nil) {|_self| ... } ⇒ Space
Returns a new instance of Space.
125 126 127 128 |
# File 'lib/duracloud/space.rb', line 125 def initialize(space_id, store_id = nil) super(space_id: space_id, store_id: store_id) yield self if block_given? end |
Class Method Details
.all(store_id = nil) ⇒ Array<Duracloud::Space>
List all spaces
24 25 26 |
# File 'lib/duracloud/space.rb', line 24 def all(store_id = nil) ids(store_id).map { |id| new(id, store_id) } end |
.audit_log(*args) ⇒ Duracloud::AuditLog
Return the audit log for the space
104 105 106 |
# File 'lib/duracloud/space.rb', line 104 def audit_log(*args) find(*args).audit_log end |
.bit_integrity_report(*args) ⇒ Duracloud::BitIntegrityReport
Return the bit integrity report for the space
111 112 113 |
# File 'lib/duracloud/space.rb', line 111 def bit_integrity_report(*args) find(*args).bit_integrity_report end |
.content_ids(space_id, store_id: nil, prefix: nil, start_after: nil) ⇒ Enumerator
Enumerates the content IDs in the space.
46 47 48 49 |
# File 'lib/duracloud/space.rb', line 46 def content_ids(space_id, store_id: nil, prefix: nil, start_after: nil) space = find(space_id, store_id) space.content_ids(prefix: prefix, start_after: start_after) end |
.count(*args) ⇒ Fixnum
Return the number of items in the space
97 98 99 |
# File 'lib/duracloud/space.rb', line 97 def count(*args) find(*args).count end |
.create(*args) ⇒ Duracloud::Space
Create a new space
68 69 70 71 72 73 |
# File 'lib/duracloud/space.rb', line 68 def create(*args) new(*args) do |space| yield space if block_given? space.save end end |
.exist?(*args) ⇒ Boolean
Does the space exist?
78 79 80 81 82 |
# File 'lib/duracloud/space.rb', line 78 def exist?(*args) find(*args) && true rescue NotFoundError false end |
.find(*args) ⇒ Duracloud::Space
Find a space
88 89 90 91 92 |
# File 'lib/duracloud/space.rb', line 88 def find(*args) new(*args) do |space| space.load_properties end end |
.ids(store_id = nil) ⇒ Array<String>
List all space IDs
32 33 34 35 36 |
# File 'lib/duracloud/space.rb', line 32 def ids(store_id = nil) response = Client.get_spaces(storeID: store_id) doc = Nokogiri::XML(response.body) doc.css('space').map { |s| s['id'] } end |
.items(space_id, store_id: nil, prefix: nil, start_after: nil) ⇒ Enumerator
Enumerates the content items in the space.
59 60 61 62 |
# File 'lib/duracloud/space.rb', line 59 def items(space_id, store_id: nil, prefix: nil, start_after: nil) space = find(space_id, store_id) space.items(prefix: prefix, start_after: start_after) end |
.manifest(*args) ⇒ Duracloud::Manifest
Return the manifest for the space
118 119 120 |
# File 'lib/duracloud/space.rb', line 118 def manifest(*args) find(*args).manifest end |
Instance Method Details
#acls ⇒ Duracloud::SpaceAcls
Return the ACLs for the space
182 183 184 |
# File 'lib/duracloud/space.rb', line 182 def acls @acls ||= SpaceAcls.new(self) end |
#audit_log ⇒ Duracloud::AuditLog
Return the audit log for the space
164 165 166 |
# File 'lib/duracloud/space.rb', line 164 def audit_log AuditLog.new(space_id, store_id) end |
#bit_integrity_report ⇒ Duracloud::BitIntegrityReport
Return the bit integrity report for the space
170 171 172 |
# File 'lib/duracloud/space.rb', line 170 def bit_integrity_report BitIntegrityReport.new(space_id, store_id) end |
#content_ids(prefix: nil, start_after: nil) ⇒ Enumerator
Enumerates the content IDs in the space.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/duracloud/space.rb', line 192 def content_ids(prefix: nil, start_after: nil) Enumerator.new do |yielder| num = 0 marker = start_after while num < count || count == 1000 q = query.merge(prefix: prefix, maxResults: MAX_RESULTS, marker: marker) response = Client.get_space(space_id, **q) xml = Nokogiri::XML(response.body) ids = xml.css('item').map(&:text) break if ids.empty? ids.each do |content_id| yielder << content_id end num += ids.length marker = ids.last end end end |
#count ⇒ Fixnum
If the count is over 1000, DuraCloud sets the x-dura-meta-space-count header to “1000+”. This method will in that case return 1000, indicating that the exact count must be retrieved by other means.
Return the number of items in the space
145 146 147 |
# File 'lib/duracloud/space.rb', line 145 def count properties["x-dura-meta-space-count"].to_i end |
#created ⇒ DateTime
Return the creation date of the space, if persisted, or nil.
151 152 153 |
# File 'lib/duracloud/space.rb', line 151 def created DateTime.parse(properties["x-dura-meta-space-created"]) rescue nil end |
#find_content(content_id) ⇒ Duracloud::Content
Find a content item in the space
158 159 160 |
# File 'lib/duracloud/space.rb', line 158 def find_content(content_id) Content.find(space_id: space_id, content_id: content_id, store_id: store_id) end |
#inspect ⇒ Object
130 131 132 133 |
# File 'lib/duracloud/space.rb', line 130 def inspect "#<#{self.class} space_id=#{space_id.inspect}," \ " store_id=#{(store_id || '(default)').inspect}>" end |
#items(*args) ⇒ Enumerator
Enumerates the content items in the space.
215 216 217 218 219 220 221 |
# File 'lib/duracloud/space.rb', line 215 def items(*args) Enumerator.new do |yielder| content_ids(*args).each do |content_id| yielder << find_content(content_id) end end end |
#manifest ⇒ Duracloud::Manifest
Return the manifest for the space
176 177 178 |
# File 'lib/duracloud/space.rb', line 176 def manifest Manifest.new(space_id, store_id) end |
#to_s ⇒ Object
135 136 137 |
# File 'lib/duracloud/space.rb', line 135 def to_s space_id end |