Module: Bulkrax::FileSetEntryBehavior

Included in:
CsvFileSetEntry, RdfFileSetEntry
Defined in:
app/models/concerns/bulkrax/file_set_entry_behavior.rb

Instance Method Summary collapse

Instance Method Details

#add_path_to_fileObject

Raises:

  • (::StandardError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 14

def add_path_to_file
  return unless file_reference == 'file'

  ['file'].each_with_index do |filename, i|
    next if filename.blank?

    path_to_file = parser.path_to_files(filename: filename)

    ['file'][i] = path_to_file
  end
  ['file'].delete('')

  raise ::StandardError, "one or more file paths are invalid: #{['file'].join(', ')}" unless ['file'].map { |file_path| ::File.file?(file_path) }.all?

  ['file']
end

#child_jobsObject

Raises:

  • (::StandardError)


47
48
49
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 47

def child_jobs
  raise ::StandardError, 'A FileSet cannot be a parent of a Collection, Work, or other FileSet'
end

#factory_classObject



5
6
7
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 5

def factory_class
  ::FileSet
end

#file_referenceObject



9
10
11
12
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 9

def file_reference
  return 'file' if &.[]('file')&.map(&:present?)&.any?
  return 'remote_files' if &.[]('remote_files')&.map(&:present?)&.any?
end

#parent_jobsObject



43
44
45
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 43

def parent_jobs
  false # FileSet relationships are handled in ObjectFactory#create_file_set
end

#validate_presence_of_filename!Object

Raises:

  • (StandardError)


31
32
33
34
35
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 31

def validate_presence_of_filename!
  return if &.[](file_reference)&.map(&:present?)&.any?

  raise StandardError, 'File set must have a filename'
end

#validate_presence_of_parent!Object

Raises:

  • (StandardError)


37
38
39
40
41
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 37

def validate_presence_of_parent!
  return if [related_parents_parsed_mapping]&.map(&:present?)&.any?

  raise StandardError, 'File set must be related to at least one work'
end