Class: AbstractImporter::Mapping

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

Direct Known Subclasses

PolymorphicMapping

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, association) ⇒ Mapping

Returns a new instance of Mapping.



5
6
7
8
9
# File 'lib/abstract_importer/mapping.rb', line 5

def initialize(collection, association)
  @collection = collection
  @depends_on = association.table_name.to_sym
  @foreign_key = association.foreign_key.to_sym
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



3
4
5
# File 'lib/abstract_importer/mapping.rb', line 3

def collection
  @collection
end

#depends_onObject (readonly)

Returns the value of attribute depends_on.



3
4
5
# File 'lib/abstract_importer/mapping.rb', line 3

def depends_on
  @depends_on
end

#foreign_keyObject (readonly)

Returns the value of attribute foreign_key.



3
4
5
# File 'lib/abstract_importer/mapping.rb', line 3

def foreign_key
  @foreign_key
end

Instance Method Details

#applicable?(attrs) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/abstract_importer/mapping.rb', line 11

def applicable?(attrs)
  attrs.key?(foreign_key)
end

#apply(attrs) ⇒ Object



19
20
21
# File 'lib/abstract_importer/mapping.rb', line 19

def apply(attrs)
  collection.map_foreign_key(attrs[foreign_key], foreign_key, depends_on)
end

#apply!(attrs) ⇒ Object



15
16
17
# File 'lib/abstract_importer/mapping.rb', line 15

def apply!(attrs)
  attrs[foreign_key] = apply(attrs)
end

#inspectObject



23
24
25
# File 'lib/abstract_importer/mapping.rb', line 23

def inspect
  "#<#{self.class.name} #{self}>"
end

#to_sObject



27
28
29
# File 'lib/abstract_importer/mapping.rb', line 27

def to_s
  "#{collection.name}.#{foreign_key}"
end