Class: Dumptruck::Load

Inherits:
Object
  • Object
show all
Defined in:
lib/dumptruck/load.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Load

Returns a new instance of Load.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dumptruck/load.rb', line 6

def initialize(params = {})
  defaults = {
    options: ["--single-transaction", "--opt", "--skip-comments"],
  }.merge!(params)

  @options  = defaults[:options]

  @database = params[:database] || '--all-databases'

  unless params[:options].nil?
    params[:options].each do |o|
      add_option(o)
    end
  end

  unless params[:ignored_tables].nil?
    params[:ignored_tables].each do |t|
      add_ignored_table(t)
    end
  end
end

Instance Attribute Details

#databaseObject

Specify a Database [TODO] if database isn’t specified then –all-databases is used



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

def database
  @database
end

Instance Method Details

#add_ignored_table(table) ⇒ Object



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

def add_ignored_table(table)
  @ignored_tables = [] unless @ignored_tables
  @ignored_tables << table
end

#add_option(option) ⇒ Object



33
34
35
36
# File 'lib/dumptruck/load.rb', line 33

def add_option(option)
  @options = [] unless @options
  @options << option
end

#ignored_tablesObject



46
47
48
49
50
51
52
53
# File 'lib/dumptruck/load.rb', line 46

def ignored_tables
  return nil unless @ignored_tables
  tables = ""
  @ignored_tables.each do |e|
    tables << "--ignore-table=#{@database}.#{e} "
  end
  tables.strip
end

#optionsObject



38
39
40
41
42
43
44
# File 'lib/dumptruck/load.rb', line 38

def options
  cmd = ""
  @options.each do |o|
    cmd << "#{o} "
  end
  cmd.strip
end