Class: AbstractImporter::Collection
- Inherits:
-
Struct
- Object
- Struct
- AbstractImporter::Collection
- Defined in:
- lib/abstract_importer/collection.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
Instance Method Summary collapse
- #association_attrs ⇒ Object
- #has_legacy_id? ⇒ Boolean
-
#initialize(name, scope, options = nil) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(name, scope, options = nil) ⇒ Collection
Returns a new instance of Collection.
4 5 6 |
# File 'lib/abstract_importer/collection.rb', line 4 def initialize(name, scope, =nil) super name, scope.model, scope.table_name, scope, end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model
2 3 4 |
# File 'lib/abstract_importer/collection.rb', line 2 def model @model end |
#name ⇒ Object
Returns the value of attribute name
2 3 4 |
# File 'lib/abstract_importer/collection.rb', line 2 def name @name end |
#options ⇒ Object
Returns the value of attribute options
2 3 4 |
# File 'lib/abstract_importer/collection.rb', line 2 def @options end |
#scope ⇒ Object
Returns the value of attribute scope
2 3 4 |
# File 'lib/abstract_importer/collection.rb', line 2 def scope @scope end |
#table_name ⇒ Object
Returns the value of attribute table_name
2 3 4 |
# File 'lib/abstract_importer/collection.rb', line 2 def table_name @table_name end |
Instance Method Details
#association_attrs ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/abstract_importer/collection.rb', line 8 def association_attrs return @association_attrs if defined?(@association_attrs) # Instead of calling `tenant.people.build(__)`, we'll reflect on the # association to find its foreign key and its owner's id, so that we # can call `Person.new(__.merge(tenant_id: id))`. @association_attrs = {} association = scope.instance_variable_get(:@association) if association unless association.is_a?(ActiveRecord::Associations::HasManyThroughAssociation) @association_attrs.merge!(association.reflection.foreign_key.to_sym => association.owner.id) end if association.reflection.inverse_of && association.reflection.inverse_of.polymorphic? @association_attrs.merge!(association.reflection.inverse_of.foreign_type.to_sym => association.owner.class.name) end end @association_attrs.freeze end |
#has_legacy_id? ⇒ Boolean
27 28 29 |
# File 'lib/abstract_importer/collection.rb', line 27 def has_legacy_id? @has_legacy_id ||= model.column_names.member?("legacy_id") end |