Module: Bulkrax::FileSetEntryBehavior
- Extended by:
- ActiveSupport::Concern
- Included in:
- CsvFileSetEntry, RdfFileSetEntry
- Defined in:
- app/models/concerns/bulkrax/file_set_entry_behavior.rb
Instance Method Summary collapse
- #add_path_to_file ⇒ Object
- #child_jobs ⇒ Object
- #file_reference ⇒ Object
- #parent_jobs ⇒ Object
- #validate_presence_of_filename! ⇒ Object
- #validate_presence_of_parent! ⇒ Object
Instance Method Details
#add_path_to_file ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 16 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_jobs ⇒ Object
49 50 51 |
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 49 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_reference ⇒ Object
11 12 13 14 |
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 11 def file_reference return 'file' if &.[]('file')&.map(&:present?)&.any? return 'remote_files' if &.[]('remote_files')&.map(&:present?)&.any? end |
#parent_jobs ⇒ Object
45 46 47 |
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 45 def parent_jobs false # FileSet relationships are handled in ObjectFactory#create_file_set end |
#validate_presence_of_filename! ⇒ Object
33 34 35 36 37 |
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 33 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
39 40 41 42 43 |
# File 'app/models/concerns/bulkrax/file_set_entry_behavior.rb', line 39 def validate_presence_of_parent! return if []&.map(&:present?)&.any? raise StandardError, 'File set must be related to at least one work' end |