Module: Locomotive::Concerns::ContentType::Import
- Extended by:
- ActiveSupport::Concern
- Included in:
- Locomotive::ContentType
- Defined in:
- app/models/locomotive/concerns/content_type/import.rb
Defined Under Namespace
Classes: ImportState
Instance Method Summary collapse
- #can_import? ⇒ Boolean
- #cancel_import(error_message) ⇒ Object
- #change_import_state(attributes, clear_state = false) ⇒ Object
- #finish_import ⇒ Object
- #import_state ⇒ Object
- #import_status ⇒ Object
- #importing? ⇒ Boolean
- #on_imported_row(index, row_status) ⇒ Object
- #start_import(total:) ⇒ Object
Instance Method Details
#can_import? ⇒ Boolean
17 18 19 |
# File 'app/models/locomotive/concerns/content_type/import.rb', line 17 def can_import? import_enabled? && import_state.can_start? end |
#cancel_import(error_message) ⇒ Object
39 40 41 |
# File 'app/models/locomotive/concerns/content_type/import.rb', line 39 def cancel_import() change_import_state({ 'status' => 'canceled', 'error' => }) end |
#change_import_state(attributes, clear_state = false) ⇒ Object
50 51 52 53 54 55 |
# File 'app/models/locomotive/concerns/content_type/import.rb', line 50 def change_import_state(attributes, clear_state = false) new_attributes = ((clear_state ? nil : raw_import_state) || {}).merge(attributes) update(raw_import_state: new_attributes.merge('updated_at' => Time.zone.now)).tap do @import_state = nil # reset the state object end end |
#finish_import ⇒ Object
35 36 37 |
# File 'app/models/locomotive/concerns/content_type/import.rb', line 35 def finish_import change_import_state({ 'status' => 'done' }) end |
#import_state ⇒ Object
13 14 15 |
# File 'app/models/locomotive/concerns/content_type/import.rb', line 13 def import_state @import_state ||= ImportState.new(raw_import_state) end |
#import_status ⇒ Object
25 26 27 |
# File 'app/models/locomotive/concerns/content_type/import.rb', line 25 def import_status import_state.status end |
#importing? ⇒ Boolean
21 22 23 |
# File 'app/models/locomotive/concerns/content_type/import.rb', line 21 def importing? import_state.running? end |
#on_imported_row(index, row_status) ⇒ Object
43 44 45 46 47 48 |
# File 'app/models/locomotive/concerns/content_type/import.rb', line 43 def on_imported_row(index, row_status) change_import_state({ row_status.to_s => import_state.rows_count(row_status.to_s) + 1, 'failed_ids' => import_state.failed_rows_ids + (row_status.to_s == 'failed' ? [index] : []), }) end |
#start_import(total:) ⇒ Object
29 30 31 32 33 |
# File 'app/models/locomotive/concerns/content_type/import.rb', line 29 def start_import(total:) change_import_state({ 'status' => 'in_progress', 'total_rows' => total }, true) end |