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



33
34
35
36
37
38
39
40
41
42
# File 'app/models/collection_branding_info.rb', line 33

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



49
50
51
# File 'app/models/collection_branding_info.rb', line 49

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



44
45
46
47
# File 'app/models/collection_branding_info.rb', line 44

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



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

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