Class: Mysql2Mysql

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

Constant Summary collapse

VERSION =
'0.0.1'
@@methods =
%w(from to tables exclude)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Mysql2Mysql

Returns a new instance of Mysql2Mysql.



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

def initialize(opts = {})
  @@methods.each do |method_name|
    send method_name, opts[method_name.to_sym] or opts[method_name.to_s]
  end
end

Class Method Details

.versionObject



24
25
26
# File 'lib/mysql_2_mysql.rb', line 24

def self.version
  VERSION
end

Instance Method Details

#dump(opts = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/mysql_2_mysql.rb', line 45

def dump(opts = {}) 
  # initialize database connections
  init_db_connection

  # initialize opts
  opts = dump_opts opts  

  # before all callback
  before_dump opts

  tables_list.each do |database, tables| 
    tables.each do |table|

      # before each callback
      if opts[:before_each].respond_to? :call
        to_database, to_table = opts[:before_each].call(database, table)
      end
      to_database ||= database
      to_table ||= table 

      dump_table database, table, to_database, to_table, opts

      # after each callback
      if opts[:after_each].respond_to? :call
        opts[:after_each].call(database, table)
      end
    end
  end

  # after all callback
  after_dump opts

end