Class: Arclight::DocumentDownloads
- Inherits:
-
Object
- Object
- Arclight::DocumentDownloads
- 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
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Class Method Summary collapse
- .config ⇒ Object
- .config_filename ⇒ Object
-
.file_class ⇒ Class
Accessor for the File Class.
Instance Method Summary collapse
-
#files ⇒ Array<Arclight::DocumentDownloads::File>
Factory method for the File objects.
-
#id ⇒ String
Accessor for the ID.
-
#initialize(document, id = nil) ⇒ DocumentDownloads
constructor
A new instance of DocumentDownloads.
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
#document ⇒ Object (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
.config ⇒ Object
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_filename ⇒ Object
42 43 44 |
# File 'app/models/arclight/document_downloads.rb', line 42 def config_filename Rails.root.join('config/downloads.yml') end |
.file_class ⇒ Class
Accessor for the File Class
48 49 50 |
# File 'app/models/arclight/document_downloads.rb', line 48 def file_class Arclight::DocumentDownloads::File end |
Instance Method Details
#files ⇒ Array<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 |
#id ⇒ String
Accessor for the ID
17 18 19 |
# File 'app/models/arclight/document_downloads.rb', line 17 def id @id || document.unitid end |