Class: Medusa::FileGroup

Inherits:
Object
  • Object
show all
Includes:
Resource
Defined in:
lib/medusa/file_group.rb

Overview

Represents a Medusa file group.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource

#exists?, #id, #uuid

Methods included from Uuidable

#uuid_url

Constructor Details

#initializeFileGroup

Returns a new instance of FileGroup.



36
37
38
39
40
41
42
43
44
# File 'lib/medusa/file_group.rb', line 36

def initialize
  @loading      = false
  @loaded       = false
  @collection   = nil
  @directory    = nil
  @directory_id = nil
  @id           = nil
  @uuid         = nil
end

Class Method Details

.with_id(id) ⇒ Medusa::FileGroup

Returns a new instance with the given ID. Existence is not checked, so an instance is returned regardless of whether the ID is valid.

Parameters:

  • uuid (String)

    Medusa database ID.

Returns:



17
18
19
20
21
# File 'lib/medusa/file_group.rb', line 17

def self.with_id(id)
  fg = FileGroup.new
  fg.instance_variable_set('@id', id)
  fg
end

.with_uuid(uuid) ⇒ Medusa::FileGruop

Returns a new instance with the given UUID. Existence is not checked, so an instance is returned regardless of whether the UUID is valid.

Parameters:

  • uuid (String)

    Medusa UUID.

Returns:

  • (Medusa::FileGruop)


30
31
32
33
34
# File 'lib/medusa/file_group.rb', line 30

def self.with_uuid(uuid)
  fg = FileGroup.new
  fg.instance_variable_set('@uuid', uuid)
  fg
end

Instance Method Details

#collectionMedusa::Collection

Returns Owning collection.

Returns:



49
50
51
52
# File 'lib/medusa/file_group.rb', line 49

def collection
  load
  @collection ||= Collection.with_id(@collection_id)
end

#directoryMedusa::Directory

Returns For instances with a #storage_level of bit_level, the root directory of the file group. Otherwise, nil.

Returns:



59
60
61
62
63
64
65
66
# File 'lib/medusa/file_group.rb', line 59

def directory
  load
  if @directory_id
    @directory ||= Directory.with_id(@directory_id)
  else
    nil
  end
end

#external_file_locationString

Returns:

  • (String)


71
72
73
74
# File 'lib/medusa/file_group.rb', line 71

def external_file_location
  load
  @external_file_location
end

#loadObject

Updates the instance with current properties from Medusa.

It should not typically be necessary to use this method publicly.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/medusa/file_group.rb', line 97

def load
  return if @loading || @loaded
  @loading                = true
  struct                  = fetch_body
  @collection_id          = struct['collection_id']
  @directory_id           = struct['cfs_directory']['id'] if struct['cfs_directory']
  @external_file_location = struct['external_file_location']
  @id                     = struct['id']
  @storage_level          = struct['storage_level']
  @title                  = struct['title']
  @uuid                   = struct['uuid']
  @loaded                 = true
ensure
  @loading = false
end

#storage_levelString

Returns:

  • (String)


79
80
81
82
# File 'lib/medusa/file_group.rb', line 79

def storage_level
  load
  @storage_level
end

#titleString

Returns:

  • (String)


87
88
89
90
# File 'lib/medusa/file_group.rb', line 87

def title
  load
  @title
end

#urlString

Returns Absolute URI of the corresponding Medusa resource.

Returns:

  • (String)

    Absolute URI of the corresponding Medusa resource.



116
117
118
119
120
# File 'lib/medusa/file_group.rb', line 116

def url
  [::Medusa::Client.configuration[:medusa_base_url].chomp('/'),
   'file_groups',
   self.id].join('/')
end