Class: MassInsert::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/mass_insert/process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values, options) ⇒ Process

Returns a new instance of Process.



5
6
7
8
# File 'lib/mass_insert/process.rb', line 5

def initialize(values, options)
  @values  = values
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/mass_insert/process.rb', line 3

def options
  @options
end

#valuesObject (readonly)

Returns the value of attribute values.



3
4
5
# File 'lib/mass_insert/process.rb', line 3

def values
  @values
end

Instance Method Details

#startObject



10
11
12
13
14
15
16
17
# File 'lib/mass_insert/process.rb', line 10

def start
  ActiveRecord::Base.transaction do
    values.each_slice(per_batch).each do |batch|
      query = builder.build(batch, options)
      executer.execute(query)
    end
  end
end