Class: Arclight::DocumentDownloads

Inherits:
Object
  • Object
show all
Defined in:
app/models/arclight/document_downloads.rb

Overview

Model the Download links that can be configured (via YAML) for a collection or container

Defined Under Namespace

Classes: File

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, id = nil) ⇒ DocumentDownloads

Returns a new instance of DocumentDownloads.



10
11
12
13
# File 'app/models/arclight/document_downloads.rb', line 10

def initialize(document, id = nil)
  @document = document
  @id = id
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



8
9
10
# File 'app/models/arclight/document_downloads.rb', line 8

def document
  @document
end

Class Method Details

.configObject



34
35
36
37
38
39
40
# File 'app/models/arclight/document_downloads.rb', line 34

def config
  @config ||= begin
    YAML.safe_load(::File.read(config_filename))
  rescue Errno::ENOENT
    {}
  end
end

.config_filenameObject



42
43
44
# File 'app/models/arclight/document_downloads.rb', line 42

def config_filename
  Rails.root.join('config/downloads.yml')
end

.file_classClass

Accessor for the File Class

Returns:

  • (Class)


48
49
50
# File 'app/models/arclight/document_downloads.rb', line 48

def file_class
  Arclight::DocumentDownloads::File
end

Instance Method Details

#filesArray<Arclight::DocumentDownloads::File>

Factory method for the File objects



23
24
25
26
27
28
29
30
31
# File 'app/models/arclight/document_downloads.rb', line 23

def files
  data = self.class.config[id] || self.class.config['default']
  disabled = data.delete('disabled')
  return [] if disabled

  @files ||= data.map do |file_type, file_data|
    self.class.file_class.new(type: file_type, data: file_data, document: document)
  end.compact
end

#idString

Accessor for the ID

Returns:

  • (String)


17
18
19
# File 'app/models/arclight/document_downloads.rb', line 17

def id
  @id || document.unitid
end