Class: TransporterTool

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_transporter.rb

Defined Under Namespace

Classes: ConversionError, InvalidObjectType, StageNotFoundError, UnexpectedJSONStructureError, UnsupportedStageTypeError

Constant Summary collapse

SUPPORTED_FILE_TYPES =
%w(.csv .json)

Instance Method Summary collapse

Constructor Details

#initialize(*files, config, object_type) ⇒ TransporterTool

Returns a new instance of TransporterTool.

Raises:



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/shopify_transporter.rb', line 54

def initialize(*files, config, object_type)
  config_file(config)
  input_files(*files)
  @object_type = object_type
  return if @config.nil? || @input_files.nil?

  raise InvalidObjectType, object_type unless supported_object_type?(object_type)

  build_classes_based_on_config
  initialize_stages
end

Instance Method Details

#initialize_stagesObject



72
73
74
75
76
77
# File 'lib/shopify_transporter.rb', line 72

def initialize_stages
  @pipeline_stages ||= {}
  @config['object_types'][@object_type]['pipeline_stages'].each do |pipeline_stage|
    initialize_pipeline_stage(pipeline_stage)
  end
end

#runObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/shopify_transporter.rb', line 79

def run
  return if @input_files.nil?

  unless file_extension_supported?
    $stderr.puts "File type must be one of: #{SUPPORTED_FILE_TYPES.join(', ')}."
    return
  end

  @input_files.each do |file_name|
    run_based_on_file_ext(file_name)
  end

  complete
end

#supported_object_type?(object_type) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/shopify_transporter.rb', line 68

def supported_object_type?(object_type)
  @config['object_types'].key?(object_type)
end