Class: Dump::DatabaseConfig
- Inherits:
-
Object
- Object
- Dump::DatabaseConfig
- Defined in:
- lib/db_time_machine/dump.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#db ⇒ Object
Returns the value of attribute db.
-
#file ⇒ Object
Returns the value of attribute file.
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#tables ⇒ Object
Returns the value of attribute tables.
-
#tmp_folder ⇒ Object
Returns the value of attribute tmp_folder.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
- .find_adapter ⇒ Object
- .find_config {|Rails.application.class.parent_name.underscore, ActiveRecord::Base.connection_config[:database], ActiveRecord::Base.connection_config[:username], ActiveRecord::Base.connection_config[:password], ActiveRecord::Base.connection_config[:host], ActiveRecord::Base.connection_config[:port]| ... } ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ DatabaseConfig
constructor
A new instance of DatabaseConfig.
- #start_dump ⇒ Object
Constructor Details
#initialize ⇒ DatabaseConfig
Returns a new instance of DatabaseConfig.
6 7 8 9 10 11 12 13 14 |
# File 'lib/db_time_machine/dump.rb', line 6 def initialize self.cmd = nil self.tables = DbTimeMachine.configuration.tables self.tmp_folder = DbTimeMachine.configuration.tmp_folder DatabaseConfig.find_config do |app, d, u, p, h, a, p1| self.db, self.user, self.password, self.host, self.port = d, u, p, h, p1 end self.file = File.join(tmp_folder, "#{db}_#{Time.now.to_i}.sql") end |
Instance Attribute Details
#cmd ⇒ Object
Returns the value of attribute cmd.
4 5 6 |
# File 'lib/db_time_machine/dump.rb', line 4 def cmd @cmd end |
#db ⇒ Object
Returns the value of attribute db.
4 5 6 |
# File 'lib/db_time_machine/dump.rb', line 4 def db @db end |
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/db_time_machine/dump.rb', line 4 def file @file end |
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/db_time_machine/dump.rb', line 4 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
4 5 6 |
# File 'lib/db_time_machine/dump.rb', line 4 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
4 5 6 |
# File 'lib/db_time_machine/dump.rb', line 4 def port @port end |
#tables ⇒ Object
Returns the value of attribute tables.
4 5 6 |
# File 'lib/db_time_machine/dump.rb', line 4 def tables @tables end |
#tmp_folder ⇒ Object
Returns the value of attribute tmp_folder.
4 5 6 |
# File 'lib/db_time_machine/dump.rb', line 4 def tmp_folder @tmp_folder end |
#user ⇒ Object
Returns the value of attribute user.
4 5 6 |
# File 'lib/db_time_machine/dump.rb', line 4 def user @user end |
Class Method Details
.find_adapter ⇒ Object
37 38 39 40 |
# File 'lib/db_time_machine/dump.rb', line 37 def self.find_adapter return 'mongodb' if File.exists?("#{Rails.root}/config/mongoid.yml") ActiveRecord::Base.connection_config[:adapter] end |
.find_config {|Rails.application.class.parent_name.underscore, ActiveRecord::Base.connection_config[:database], ActiveRecord::Base.connection_config[:username], ActiveRecord::Base.connection_config[:password], ActiveRecord::Base.connection_config[:host], ActiveRecord::Base.connection_config[:port]| ... } ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/db_time_machine/dump.rb', line 28 def self.find_config yield Rails.application.class.parent_name.underscore, ActiveRecord::Base.connection_config[:database], ActiveRecord::Base.connection_config[:username], ActiveRecord::Base.connection_config[:password], ActiveRecord::Base.connection_config[:host], ActiveRecord::Base.connection_config[:port] end |
Instance Method Details
#start_dump ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/db_time_machine/dump.rb', line 16 def start_dump puts "exporting the latest dump to #{file}" inprocess = File.join(tmp_folder, "dumping_data") `touch #{inprocess};#{cmd};rm #{inprocess}` while File.exist?('#{inprocess}') puts "database dump is in progress." puts "sleeping" sleep(0.5) end puts "database dump is complete." end |