Class: CollectionBrandingInfo
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- CollectionBrandingInfo
- Defined in:
- app/models/collection_branding_info.rb
Instance Method Summary collapse
- #delete(location_path) ⇒ Object
- #find_local_dir_name(collection_id, role) ⇒ Object
- #find_local_filename(collection_id, role, filename) ⇒ Object
-
#initialize(collection_id:, filename:, role:, alt_txt: "", target_url: "") ⇒ CollectionBrandingInfo
constructor
i = ColectionImageInfo.new().
- #save(file_location, copy_file = true) ⇒ Object
Constructor Details
#initialize(collection_id:, filename:, role:, alt_txt: "", target_url: "") ⇒ CollectionBrandingInfo
i = ColectionImageInfo.new()
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/models/collection_branding_info.rb', line 4 def initialize(collection_id:, filename:, role:, alt_txt: "", target_url: "") super() self.collection_id = collection_id self.role = role self.alt_text = alt_txt self.target_url = target_url self.local_path = find_local_filename(collection_id, role, filename) end |
Instance Method Details
#delete(location_path) ⇒ Object
27 28 29 |
# File 'app/models/collection_branding_info.rb', line 27 def delete(location_path) FileUtils.remove_file(location_path) if File.exist?(location_path) end |
#find_local_dir_name(collection_id, role) ⇒ Object
36 37 38 |
# File 'app/models/collection_branding_info.rb', line 36 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
31 32 33 34 |
# File 'app/models/collection_branding_info.rb', line 31 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, copy_file = true) ⇒ Object
19 20 21 22 23 24 25 |
# File 'app/models/collection_branding_info.rb', line 19 def save(file_location, copy_file = true) local_dir = find_local_dir_name(collection_id, role) FileUtils.mkdir_p local_dir FileUtils.cp file_location, local_path unless file_location == local_path || !copy_file FileUtils.remove_file(file_location) if File.exist?(file_location) && copy_file super() end |