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

Returns a new instance of CollectionBrandingInfo.



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

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 = File.join(role, filename)
end

Instance Method Details

#delete(location_path = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/collection_branding_info.rb', line 30

def delete(location_path = nil)
  id = if location_path
         Deprecation.warn('Passing an explict location path is ' \
                          'deprecated. Call without arguments instead.')
         location_path
       else
         local_path
       end

  storage.delete(id: id)
end

#find_local_dir_name(collection_id, role) ⇒ Object



47
48
49
# File 'app/models/collection_branding_info.rb', line 47

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



42
43
44
45
# File 'app/models/collection_branding_info.rb', line 42

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



17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/collection_branding_info.rb', line 17

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

  storage.upload(resource: Hyrax::PcdmCollection.new(id: collection_id),
                 file: File.open(file_location),
                 original_filename: role_and_filename)
  self.local_path = find_local_filename(collection_id, role, filename)

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