Class: Itiel::Load::DatabaseTable

Inherits:
Object
  • Object
show all
Includes:
DB::SQLConnectable, ChainedStep, Nameable
Defined in:
lib/itiel/load/database_table.rb

Overview

Loads the stream into a database table.

Usage:

@loader = Itiel::Load::DatabaseTable.new :connection, "table_name"

Instance Attribute Summary collapse

Attributes included from DB::SQLConnectable

#connection, #connection_file_path

Attributes included from Nameable

#debug, #step_name

Instance Method Summary collapse

Methods included from DB::SQLConnectable

included

Methods included from ChainedStep

included

Constructor Details

#initialize(connection, table_name) ⇒ DatabaseTable

Returns a new instance of DatabaseTable.



17
18
19
20
# File 'lib/itiel/load/database_table.rb', line 17

def initialize(connection, table_name)
  self.connection = connection
  self.table_name = table_name
end

Instance Attribute Details

#table_nameObject

Returns the value of attribute table_name.



15
16
17
# File 'lib/itiel/load/database_table.rb', line 15

def table_name
  @table_name
end

Instance Method Details

#persist(input_stream) ⇒ Object



22
23
24
25
26
# File 'lib/itiel/load/database_table.rb', line 22

def persist(input_stream)
  input_stream.each do |element|
    table.insert(element)
  end
end

#tableObject



28
29
30
31
# File 'lib/itiel/load/database_table.rb', line 28

def table
  @@db ||= self.class.sequel_connection(connection)
  @@db[table_name.to_sym]
end