Class: Spree::AgentTools::DescribeImportMapping

Inherits:
ImportTool show all
Defined in:
app/tools/spree/agent_tools/describe_import_mapping.rb

Overview

What an import still needs mapped: the file's own column headings, the Spree fields available, and which of those are required.

This is the half of the mapping problem a computer cannot do. Deciding that a column headed "Retail Price (inc VAT)" is the price field is judgement about messy human spreadsheets — exactly what the model is for — but it can only judge from the real vocabulary, so this hands it the schema rather than letting it guess field names.

Constant Summary

Constants inherited from Spree::AgentTool

Spree::AgentTool::PARENT_ID_DESCRIPTION

Instance Attribute Summary

Attributes inherited from Spree::AgentTool

#context

Instance Method Summary collapse

Methods inherited from Spree::AgentTool

additive!, audience, description, destructive?, #initialize, input_schema, mutating!, mutating?, param, params, permission, #permitted?, tool_name, #unknown_resource

Constructor Details

This class inherits a constructor from Spree::AgentTool

Instance Method Details

#call(id: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/tools/spree/agent_tools/describe_import_mapping.rb', line 23

def call(id: nil)
  import = find_import(id, status: 'mapping')
  return { error: 'No import is waiting to be mapped.' } if import.nil?

  refusal = unauthorized_import(import)
  return refusal if refusal

  {
    id: import.prefixed_id,
    number: import.number,
    status: import.status,
    file_columns: import.csv_headers,
    unmapped_file_columns: import.unmapped_file_columns,
    spree_fields: describe_fields(import),
    already_mapped: current_mapping(import),
    sample_row: import.sample_row
  }.compact
end

#summary(arguments) ⇒ Object



42
43
44
# File 'app/tools/spree/agent_tools/describe_import_mapping.rb', line 42

def summary(arguments)
  'Read the import file layout'
end