Module: Bulkrax::FileSetEntryBehavior

Extended by:
ActiveSupport::Concern
Included in:
CsvFileSetEntry, RdfFileSetEntry
Defined in:
app/models/concerns/bulkrax/file_set_entry_behavior.rb

Defined Under Namespace

Classes: FileNameError, FilePathError, OrphanFileSetError

Instance Method Summary collapse

Instance Method Details

#add_path_to_fileObject

Raises:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 25

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 if path_to_file.present?
  end
  ['file'].delete('')

  raise FilePathError, "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)


58
59
60
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 58

def child_jobs
  raise ::StandardError, "A #{Bulkrax.file_model_class} cannot be a parent of a #{Bulkrax.collection_model_class}, Work, or other #{Bulkrax.file_model_class}"
end

#file_referenceObject



20
21
22
23
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 20

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

#parent_jobsObject



54
55
56
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 54

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

#validate_presence_of_filename!Object

Raises:



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

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

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

#validate_presence_of_parent!Object

Raises:



48
49
50
51
52
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 48

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

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