Class: AbstractImporter::Collection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modelObject

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



2
3
4
# File 'lib/abstract_importer/collection.rb', line 2

def model
  @model
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/abstract_importer/collection.rb', line 2

def name
  @name
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



2
3
4
# File 'lib/abstract_importer/collection.rb', line 2

def options
  @options
end

#scopeObject

Returns the value of attribute scope

Returns:

  • (Object)

    the current value of scope



2
3
4
# File 'lib/abstract_importer/collection.rb', line 2

def scope
  @scope
end

#table_nameObject

Returns the value of attribute table_name

Returns:

  • (Object)

    the current value of table_name



2
3
4
# File 'lib/abstract_importer/collection.rb', line 2

def table_name
  @table_name
end

Instance Method Details

#association_attrsObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/abstract_importer/collection.rb', line 4

def association_attrs
  return @assocation_attrs if defined?(@assocation_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))`.
  @assocation_attrs = {}
  assocation = scope.instance_variable_get(:@association)
  unless assocation.is_a?(ActiveRecord::Associations::HasManyThroughAssociation)
    @assocation_attrs.merge!(assocation.reflection.foreign_key.to_sym => assocation.owner.id)
  end
  @assocation_attrs.freeze
end