Sha256: 8f90040c38e2d2a56d170ad91e590be0bc298471280d486f68679c9a50cf1529

Contents?: true

Size: 923 Bytes

Versions: 6

Compression:

Stored size: 923 Bytes

Contents

class Topographer::Importer::Strategy::Base

  attr_reader :mapper
  attr_accessor :dry_run

  def initialize(mapper)
    @mapper = mapper
    @dry_run = false
  end

  def import_record (record_input)
    raise NotImplementedError
  end

  def success_message
    'Imported'
  end

  def failure_message
    'Unable to import'
  end

  def should_persist_import?(status)
    (@dry_run || status.errors?) ? false : true
  end

  private

    def get_import_status(mapping_result, new_model_errors)
      status = Topographer::Importer::Strategy::ImportStatus.new(mapping_result.source_identifier)
      mapping_result.errors.values.each do |error|
        status.add_error(:mapping, error)
      end
      new_model_errors.each do |error|
        status.add_error(:validation, error)
      end
      status.message = (status.errors?) ? failure_message : success_message
      status.set_timestamp
      status
    end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
topographer-0.0.7 lib/topographer/importer/strategy/base.rb
topographer-0.0.6 lib/topographer/importer/strategy/base.rb
topographer-0.0.5 lib/topographer/importer/strategy/base.rb
topographer-0.0.4 lib/topographer/importer/strategy/base.rb
topographer-0.0.3 lib/Topographer/importer/strategy/base.rb
topographer-0.0.2 lib/Topographer/importer/strategy/base.rb