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



38
39
40
41
42
43
44
# File 'app/models/arclight/document_downloads.rb', line 38

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

.config_filenameObject



46
47
48
# File 'app/models/arclight/document_downloads.rb', line 46

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

.file_classClass

Accessor for the File Class

Returns:

  • (Class)


52
53
54
# File 'app/models/arclight/document_downloads.rb', line 52

def file_class
  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

#to_partial_pathObject



33
34
35
# File 'app/models/arclight/document_downloads.rb', line 33

def to_partial_path
  'catalog/document_downloads'
end