Class: Multisert

Inherits:
Object
  • Object
show all
Defined in:
lib/multisert.rb,
lib/multisert/version.rb

Constant Summary collapse

MAX_BUFFER_COUNT_DEFAULT =
10_000
VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Multisert

Returns a new instance of Multisert.



10
11
12
13
14
# File 'lib/multisert.rb', line 10

def initialize attrs = {}
  attrs.each do |attr, value|
    self.send "#{attr}=", value
  end
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



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

def connection
  @connection
end

#databaseObject

Returns the value of attribute database.



5
6
7
# File 'lib/multisert.rb', line 5

def database
  @database
end

#fieldsObject

Returns the value of attribute fields.



7
8
9
# File 'lib/multisert.rb', line 7

def fields
  @fields
end

#max_buffer_countObject



36
37
38
# File 'lib/multisert.rb', line 36

def max_buffer_count
  @max_buffer_count || MAX_BUFFER_COUNT_DEFAULT
end

#tableObject

Returns the value of attribute table.



6
7
8
# File 'lib/multisert.rb', line 6

def table
  @table
end

Instance Method Details

#<<(entry) ⇒ Object



24
25
26
27
28
# File 'lib/multisert.rb', line 24

def << entry
  entries << entry
  flush! if flush_buffer?
  entry
end

#entriesObject



20
21
22
# File 'lib/multisert.rb', line 20

def entries
  @entries ||= []
end

#flush!Object



30
31
32
33
34
# File 'lib/multisert.rb', line 30

def flush!
  return if buffer_empty?
  @connection.query multisert_sql
  reset_entries!
end