Class: EnMasse::Inserts

Inherits:
Object
  • Object
show all
Defined in:
lib/en_masse/inserts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ Inserts

Returns a new instance of Inserts.



6
7
8
9
# File 'lib/en_masse/inserts.rb', line 6

def initialize collection
  @collection = collection
  @collection += collect_new_dependents
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



4
5
6
# File 'lib/en_masse/inserts.rb', line 4

def collection
  @collection
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
# File 'lib/en_masse/inserts.rb', line 11

def call
  ActiveRecord::Base.connection.transaction do
    by_model.each do |model, records|
      model.insert_collection(records)
    end
  end
end