Class: Itiel::Extract::CustomSQL

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

Overview

Creates a stream from the specified SQL query. Connection must be defined on a file that’s on config/database.yml by default.

Usage:

@custom_sql = Itiel::Extract::CustomSQL.new
@custom_sql.connection = :test
@custom_sql.script = 'SELECT * FROM some_table'

You can set a different path for the config file at class level

Itiel::Extract::CustomSQL.connection_file_path = 'path_to_my_config/database.yml'

Direct Known Subclasses

DatabaseTable

Instance Attribute Summary collapse

Attributes included from Nameable

#debug, #step_name

Attributes included from DB::SQLConnectable

#connection, #connection_file_path

Attributes included from ChainedStep

#next_step

Instance Method Summary collapse

Methods included from DB::SQLConnectable

included

Methods included from ChainedStep

#start

Constructor Details

#initialize(*args) ⇒ CustomSQL

Returns a new instance of CustomSQL.



28
29
30
# File 'lib/itiel/extract/custom_sql.rb', line 28

def initialize(*args)
  self.script = args[0]
end

Instance Attribute Details

#scriptObject

Returns the value of attribute script.



26
27
28
# File 'lib/itiel/extract/custom_sql.rb', line 26

def script
  @script
end

Instance Method Details

#extractObject



32
33
34
35
# File 'lib/itiel/extract/custom_sql.rb', line 32

def extract
  db = self.class.sequel_connection(connection)
  db[script].all
end