Class: Duracloud::Space

Inherits:
AbstractEntity show all
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

Instance Method Summary collapse

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.

Parameters:

  • space_id (String)

    the space ID

  • store_id (String) (defaults to: nil)

    the store ID (optional)

Yields:

  • (_self)

Yield Parameters:



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

Parameters:

  • store_id (String) (defaults to: nil)

    the store ID (optional)

Returns:

Raises:



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

Returns:

Raises:



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

Returns:

Raises:



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.

Parameters:

  • space_id (String)

    the space ID

  • store_id (String) (defaults to: nil)

    the store ID (optional)

  • prefix (String) (defaults to: nil)

    the content ID prefix for filtering (optional)

  • start_after (String) (defaults to: nil)

    the content ID to be used as a “marker”. Listing starts after this ID. (optional)

Returns:

  • (Enumerator)

    an enumerator.

Raises:



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

Returns:

  • (Fixnum)

    the number of items

Raises:



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

Returns:

Raises:

See Also:

  • for arguments


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?

Returns:

  • (Boolean)

    whether the space exists.

See Also:

  • for arguments


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

Returns:

Raises:

See Also:

  • for arguments


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

Parameters:

  • store_id (String) (defaults to: nil)

    the store ID (optional)

Returns:

  • (Array<String>)

    the list of space IDs

Raises:



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.

Parameters:

  • space_id (String)

    the space ID

  • store_id (String) (defaults to: nil)

    the store ID (optional)

  • prefix (String) (defaults to: nil)

    the content ID prefix for filtering (optional)

  • start_after (String) (defaults to: nil)

    the content ID to be used as a “marker”. Listing starts after this ID. (optional)

Returns:

  • (Enumerator)

    an enumerator.

Raises:



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

Returns:

Raises:



118
119
120
# File 'lib/duracloud/space.rb', line 118

def manifest(*args)
  find(*args).manifest
end

Instance Method Details

#aclsDuracloud::SpaceAcls

Return the ACLs for the space

Returns:



182
183
184
# File 'lib/duracloud/space.rb', line 182

def acls
  @acls ||= SpaceAcls.new(self)
end

#audit_logDuracloud::AuditLog

Return the audit log for the space

Returns:



164
165
166
# File 'lib/duracloud/space.rb', line 164

def audit_log
  AuditLog.new(space_id, store_id)
end

#bit_integrity_reportDuracloud::BitIntegrityReport

Return the bit integrity report for the space

Returns:



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.

Parameters:

  • prefix (String) (defaults to: nil)

    the content ID prefix for filtering (optional)

  • start_after (String) (defaults to: nil)

    the content ID to be used as a “marker”. Listing starts after this ID. (optional)

Returns:

  • (Enumerator)

    an enumerator.

Raises:



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

#countFixnum

Note:

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

Returns:

  • (Fixnum)

    the number of items



145
146
147
# File 'lib/duracloud/space.rb', line 145

def count
  properties["x-dura-meta-space-count"].to_i
end

#createdDateTime

Return the creation date of the space, if persisted, or nil.

Returns:

  • (DateTime)

    the date



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

Returns:

Raises:



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

#inspectObject



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.

Returns:

  • (Enumerator)

    an enumerator.

Raises:

See Also:



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

#manifestDuracloud::Manifest

Return the manifest for the space

Returns:



176
177
178
# File 'lib/duracloud/space.rb', line 176

def manifest
  Manifest.new(space_id, store_id)
end

#to_sObject



135
136
137
# File 'lib/duracloud/space.rb', line 135

def to_s
  space_id
end