Class: Linkage::ImportBuffer
- Inherits:
-
Object
- Object
- Linkage::ImportBuffer
- Defined in:
- lib/linkage/import_buffer.rb
Instance Method Summary collapse
- #add(values) ⇒ Object
- #flush ⇒ Object
-
#initialize(uri, table_name, headers, options = {}, limit = 1000) ⇒ ImportBuffer
constructor
A new instance of ImportBuffer.
Constructor Details
#initialize(uri, table_name, headers, options = {}, limit = 1000) ⇒ ImportBuffer
Returns a new instance of ImportBuffer.
8 9 10 11 12 13 14 15 |
# File 'lib/linkage/import_buffer.rb', line 8 def initialize(uri, table_name, headers, = {}, limit = 1000) @uri = uri @table_name = table_name.to_sym @headers = headers @options = @limit = limit @values = [] end |
Instance Method Details
#add(values) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/linkage/import_buffer.rb', line 17 def add(values) @values << values if @values.length == @limit flush end end |
#flush ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/linkage/import_buffer.rb', line 24 def flush return if @values.empty? database do |db| ds = db[@table_name] ds.import(@headers, @values) @values.clear end end |