Class: CollectionBrandingInfo

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

Instance Method Summary collapse

Constructor Details

#initialize(collection_id:, filename:, role:, alt_txt: "", target_url: "") ⇒ CollectionBrandingInfo

i = ColectionImageInfo.new()



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

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



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

def delete(location_path)
  FileUtils.remove_file(location_path) if File.exist?(location_path)
end

#find_local_dir_name(collection_id, role) ⇒ Object



37
38
39
# File 'app/models/collection_branding_info.rb', line 37

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



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

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



20
21
22
23
24
25
26
# File 'app/models/collection_branding_info.rb', line 20

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