Class: CollectionBrandingInfo

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/collection_branding_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#alt_txtObject

Returns the value of attribute alt_txt.



3
4
5
# File 'app/models/collection_branding_info.rb', line 3

def alt_txt
  @alt_txt
end

#filenameObject

Returns the value of attribute filename.



3
4
5
# File 'app/models/collection_branding_info.rb', line 3

def filename
  @filename
end

Instance Method Details

#delete(_location_path = nil) ⇒ Object



22
23
24
# File 'app/models/collection_branding_info.rb', line 22

def delete(_location_path = nil)
  storage.delete(id: local_path)
end

#find_local_dir_name(collection_id, role) ⇒ Object



31
32
33
# File 'app/models/collection_branding_info.rb', line 31

def find_local_dir_name(collection_id, role)
  File.join(Hyrax.config.branding_path, collection_id.to_s, role.to_s)
end

#find_local_filename(collection_id, role, filename) ⇒ Object



26
27
28
29
# File 'app/models/collection_branding_info.rb', line 26

def find_local_filename(collection_id, role, filename)
  local_dir = find_local_dir_name(collection_id, role)
  File.join(local_dir, filename)
end

#save(file_location, upload_file = true) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/models/collection_branding_info.rb', line 6

def save(file_location, upload_file = true)
  filename = File.split(local_path).last
  role_and_filename = File.join(role, filename)

  if upload_file
    storage.upload(resource: Hyrax::PcdmCollection.new(id: collection_id),
                   file: File.open(file_location),
                   original_filename: role_and_filename)
  end

  self.local_path = find_local_filename(collection_id, role, filename)

  FileUtils.remove_file(file_location) if File.exist?(file_location) && upload_file
  super()
end