Class: DataMask::Mask
- Inherits:
-
Object
- Object
- DataMask::Mask
- Defined in:
- lib/data_mask.rb
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(path = 'config') ⇒ Mask
constructor
A new instance of Mask.
- #migrate ⇒ Object
- #operate_db(op) ⇒ Object
- #play ⇒ Object
- #run ⇒ Object
- #tmp_db_clear ⇒ Object
Constructor Details
Instance Method Details
#export ⇒ Object
27 28 29 |
# File 'lib/data_mask.rb', line 27 def export system DBShell.new(@db_conf[:to]).export(to_file = true) end |
#migrate ⇒ Object
17 18 19 20 21 |
# File 'lib/data_mask.rb', line 17 def migrate remote = DBShell.new(@db_conf[:from]).export local = DBShell.new(@db_conf[:to]).import system "#{remote} | #{local}" end |
#operate_db(op) ⇒ Object
13 14 15 |
# File 'lib/data_mask.rb', line 13 def operate_db(op) execute_sql "#{op.upcase} DATABASE %{database}" % @db_conf[:to] end |
#play ⇒ Object
23 24 25 |
# File 'lib/data_mask.rb', line 23 def play mask(@db_conf[:to], @tasks) end |
#run ⇒ Object
41 42 43 44 45 46 |
# File 'lib/data_mask.rb', line 41 def run tmp_db_clear operate_db('create') migrate play end |
#tmp_db_clear ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/data_mask.rb', line 31 def tmp_db_clear return if if @db_conf[:to][:adapter] == 'postgres' # Force drop db while others may be connected execute_sql 'select pg_terminate_backend(procpid)' \ " from pg_stat_activity where datname=’%{database}’" % @db_conf[:to] end execute_sql "DROP DATABASE IF EXISTS %{database}" % @db_conf[:to] end |