Class: Spree::ImportRow
- Inherits:
-
Object
- Object
- Spree::ImportRow
- Defined in:
- app/models/spree/import_row.rb
Instance Method Summary collapse
- #attribute_by_schema_field(schema_field, mappings = nil) ⇒ Object
- #data_json ⇒ Object
- #process! ⇒ Object
- #publish_import_row_completed_event ⇒ Object
- #publish_import_row_failed_event ⇒ Object
- #to_schema_hash ⇒ Object
Instance Method Details
#attribute_by_schema_field(schema_field, mappings = nil) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'app/models/spree/import_row.rb', line 69 def attribute_by_schema_field(schema_field, mappings = nil) mappings ||= import.mappings.mapped mapping = mappings.find { |m| m.schema_field == schema_field } return unless mapping&.mapped? data_json[mapping.file_column] end |
#data_json ⇒ Object
50 51 52 53 54 |
# File 'app/models/spree/import_row.rb', line 50 def data_json @data_json ||= JSON.parse(data) rescue JSON::ParserError {} end |
#process! ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'app/models/spree/import_row.rb', line 78 def process! start_processing! self.item = import.row_processor_class.new(self).process! complete! rescue StandardError => e Rails.error.report(e, handled: true, context: { import_row_id: id }, source: 'spree.core') self.validation_errors = e. fail! end |
#publish_import_row_completed_event ⇒ Object
88 89 90 |
# File 'app/models/spree/import_row.rb', line 88 def publish_import_row_completed_event publish_event('import_row.completed') end |
#publish_import_row_failed_event ⇒ Object
92 93 94 |
# File 'app/models/spree/import_row.rb', line 92 def publish_import_row_failed_event publish_event('import_row.failed') end |
#to_schema_hash ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/spree/import_row.rb', line 56 def to_schema_hash @to_schema_hash ||= begin mappings = import.mappings.mapped schema_fields = import.schema_fields attributes = {} schema_fields.each do |field| attributes[field[:name]] = attribute_by_schema_field(field[:name], mappings) end attributes end end |