Class: AbstractImporter::Strategies::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/abstract_importer/strategies/base.rb

Direct Known Subclasses

DefaultStrategy, InsertStrategy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ Base

Returns a new instance of Base.



17
18
19
# File 'lib/abstract_importer/strategies/base.rb', line 17

def initialize(collection)
  @collection = collection
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



4
5
6
# File 'lib/abstract_importer/strategies/base.rb', line 4

def collection
  @collection
end

Instance Method Details

#already_imported?(hash) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/abstract_importer/strategies/base.rb', line 25

def already_imported?(hash)
  id_map.contains? collection.table_name, hash[:id]
end

#flushObject



29
30
# File 'lib/abstract_importer/strategies/base.rb', line 29

def flush
end

#prepare_attributes(hash) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/abstract_importer/strategies/base.rb', line 32

def prepare_attributes(hash)
  hash = invoke_callback(:before_build, hash) || hash

  legacy_id = hash.delete(:id)

  hash.merge(legacy_id: legacy_id).merge(association_attrs)
end

#process_record(hash) ⇒ Object

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/abstract_importer/strategies/base.rb', line 21

def process_record(hash)
  raise NotImplementedError
end