Class: AbstractImporter::Mapping
- Inherits:
-
Object
- Object
- AbstractImporter::Mapping
- Defined in:
- lib/abstract_importer/mapping.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#depends_on ⇒ Object
readonly
Returns the value of attribute depends_on.
-
#foreign_key ⇒ Object
readonly
Returns the value of attribute foreign_key.
Instance Method Summary collapse
- #applicable?(attrs) ⇒ Boolean
- #apply(attrs) ⇒ Object
- #apply!(attrs) ⇒ Object
-
#initialize(collection, association) ⇒ Mapping
constructor
A new instance of Mapping.
- #inspect ⇒ Object
- #to_s ⇒ Object
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
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
3 4 5 |
# File 'lib/abstract_importer/mapping.rb', line 3 def collection @collection end |
#depends_on ⇒ Object (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_key ⇒ Object (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
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 |
#inspect ⇒ Object
23 24 25 |
# File 'lib/abstract_importer/mapping.rb', line 23 def inspect "#<#{self.class.name} #{self}>" end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/abstract_importer/mapping.rb', line 27 def to_s "#{collection.name}.#{foreign_key}" end |