Class: Linkage::ImportBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/linkage/import_buffer.rb

Instance Method Summary (collapse)

Constructor Details

- (ImportBuffer) initialize(dataset, headers, limit = 1000)



6
7
8
9
10
11
# File 'lib/linkage/import_buffer.rb', line 6

def initialize(dataset, headers, limit = 1000)
  @dataset = dataset
  @headers = headers
  @limit = limit
  @values = []
end

Instance Method Details

- (Object) add(values)



13
14
15
16
17
18
# File 'lib/linkage/import_buffer.rb', line 13

def add(values)
  @values << values
  if @values.length == @limit
    flush
  end
end

- (Object) flush



20
21
22
23
24
25
26
# File 'lib/linkage/import_buffer.rb', line 20

def flush
  return if @values.empty?
  @dataset.db.synchronize do
    @dataset.import(@headers, @values)
    @values.clear
  end
end