Class: Database::Base
- Inherits:
-
Object
- Object
- Database::Base
- Defined in:
- lib/capistrano-db-tasks/database.rb
Constant Summary collapse
- DBCONFIG_BEGIN_FLAG =
"__CAPISTRANODB_CONFIG_BEGIN_FLAG__".freeze
- DBCONFIG_END_FLAG =
"__CAPISTRANODB_CONFIG_END_FLAG__".freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#output_file ⇒ Object
Returns the value of attribute output_file.
Instance Method Summary collapse
- #compressor ⇒ Object
- #credentials ⇒ Object
- #current_time ⇒ Object
- #database ⇒ Object
-
#initialize(cap_instance) ⇒ Base
constructor
A new instance of Base.
- #mysql? ⇒ Boolean
- #postgresql? ⇒ Boolean
Constructor Details
#initialize(cap_instance) ⇒ Base
Returns a new instance of Base.
8 9 10 |
# File 'lib/capistrano-db-tasks/database.rb', line 8 def initialize(cap_instance) @cap = cap_instance end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/capistrano-db-tasks/database.rb', line 6 def config @config end |
#output_file ⇒ Object
Returns the value of attribute output_file.
6 7 8 |
# File 'lib/capistrano-db-tasks/database.rb', line 6 def output_file @output_file end |
Instance Method Details
#compressor ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/capistrano-db-tasks/database.rb', line 51 def compressor @compressor ||= begin compressor_klass = @cap.fetch(:compressor).to_s.split('_').collect(&:capitalize).join klass = Object.module_eval("::Compressors::#{compressor_klass}", __FILE__, __LINE__) klass end end |
#credentials ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/capistrano-db-tasks/database.rb', line 20 def credentials credential_params = "" username = @config['username'] || @config['user'] if mysql? credential_params << " -u #{username} " if username credential_params << " -p'#{@config['password']}' " if @config['password'] credential_params << " -h #{@config['host']} " if @config['host'] credential_params << " -S #{@config['socket']} " if @config['socket'] credential_params << " -P #{@config['port']} " if @config['port'] elsif postgresql? credential_params << " -U #{username} " if username credential_params << " -h #{@config['host']} " if @config['host'] credential_params << " -p #{@config['port']} " if @config['port'] end credential_params end |
#current_time ⇒ Object
43 44 45 |
# File 'lib/capistrano-db-tasks/database.rb', line 43 def current_time Time.now.strftime("%Y-%m-%d-%H%M%S") end |
#database ⇒ Object
39 40 41 |
# File 'lib/capistrano-db-tasks/database.rb', line 39 def database @config['database'] end |
#mysql? ⇒ Boolean
12 13 14 |
# File 'lib/capistrano-db-tasks/database.rb', line 12 def mysql? @config['adapter'] =~ /^mysql/ end |
#postgresql? ⇒ Boolean
16 17 18 |
# File 'lib/capistrano-db-tasks/database.rb', line 16 def postgresql? %w(postgresql pg postgis).include? @config['adapter'] end |