Class: Itiel::DB::Truncator

Inherits:
Object
  • Object
show all
Includes:
SQLConnectable, Nameable
Defined in:
lib/itiel/db/truncator.rb

Overview

Truncates specified tables

Usage:

@truncator = Itiel::DB::Truncator.new "tables", "to", "truncate"
@truncator.connection = :database
@truncator.truncate!

Instance Attribute Summary collapse

Attributes included from SQLConnectable

#connection, #connection_file_path

Attributes included from Nameable

#debug, #step_name

Instance Method Summary collapse

Methods included from SQLConnectable

included

Constructor Details

#initialize(*tables) ⇒ Truncator

Returns a new instance of Truncator.



18
19
20
# File 'lib/itiel/db/truncator.rb', line 18

def initialize(*tables)
  self.tables = tables
end

Instance Attribute Details

#tablesObject

Returns the value of attribute tables.



16
17
18
# File 'lib/itiel/db/truncator.rb', line 16

def tables
  @tables
end

Instance Method Details

#truncate!Object



22
23
24
25
26
27
# File 'lib/itiel/db/truncator.rb', line 22

def truncate!
  tables.each do |table|
    db = self.class.sequel_connection(connection)
    db[table.to_sym].truncate
  end
end