Module: Bulkrax::ImporterExporterBehavior
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/bulkrax/importer_exporter_behavior.rb
Instance Method Summary collapse
-
#file? ⇒ Boolean
Is this a file?.
- #increment_counters(index, collection: false, file_set: false, work: false) ⇒ Object
- #key_without_numbers(key) ⇒ Object
- #keys_without_numbers(keys) ⇒ Object
- #last_imported_at ⇒ Object
- #next_import_at ⇒ Object
- #parser ⇒ Object
- #parser_class ⇒ Object
-
#zip? ⇒ Boolean
Is this a zip file?.
Instance Method Details
#file? ⇒ Boolean
Is this a file?
48 49 50 |
# File 'app/models/concerns/bulkrax/importer_exporter_behavior.rb', line 48 def file? parser_fields&.[]('import_file_path') && File.file?(parser_fields['import_file_path']) end |
#increment_counters(index, collection: false, file_set: false, work: false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/concerns/bulkrax/importer_exporter_behavior.rb', line 24 def increment_counters(index, collection: false, file_set: false, work: false) # Only set the totals if they were not set on initialization importer_run = ImporterRun.find(current_run.id) # make sure fresh if collection importer_run.total_collection_entries = index + 1 unless parser.collections_total.positive? elsif file_set importer_run.total_file_set_entries = index + 1 unless parser.file_sets_total.positive? elsif work # TODO: differentiate between work and collection counts for exporters importer_run.total_work_entries = index + 1 unless limit.to_i.positive? || parser.total.positive? end importer_run.enqueued_records += 1 importer_run.save! end |
#key_without_numbers(key) ⇒ Object
43 44 45 |
# File 'app/models/concerns/bulkrax/importer_exporter_behavior.rb', line 43 def key_without_numbers(key) key.gsub(/_\d+/, '').sub(/^\d+_/, '') end |
#keys_without_numbers(keys) ⇒ Object
39 40 41 |
# File 'app/models/concerns/bulkrax/importer_exporter_behavior.rb', line 39 def keys_without_numbers(keys) keys.map { |key| key_without_numbers(key) } end |
#last_imported_at ⇒ Object
16 17 18 |
# File 'app/models/concerns/bulkrax/importer_exporter_behavior.rb', line 16 def last_imported_at @last_imported_at ||= self.importer_runs.last&.created_at end |
#next_import_at ⇒ Object
20 21 22 |
# File 'app/models/concerns/bulkrax/importer_exporter_behavior.rb', line 20 def next_import_at (last_imported_at || Time.current) + frequency.to_seconds if schedulable? && last_imported_at.present? end |
#parser ⇒ Object
8 9 10 |
# File 'app/models/concerns/bulkrax/importer_exporter_behavior.rb', line 8 def parser @parser ||= parser_class.new(self) end |
#parser_class ⇒ Object
12 13 14 |
# File 'app/models/concerns/bulkrax/importer_exporter_behavior.rb', line 12 def parser_class self.parser_klass.constantize end |
#zip? ⇒ Boolean
Is this a zip file?
53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/concerns/bulkrax/importer_exporter_behavior.rb', line 53 def zip? filename = parser_fields&.[]('import_file_path') return false unless filename return false unless File.file?(filename) returning_value = false File.open(filename) do |file| returning_value = ::Marcel::MimeType.for(file).include?('application/zip') end returning_value end |