Class: Database::Base
- Inherits:
-
Object
- Object
- Database::Base
- Defined in:
- lib/capistrano-db-tasks/database.rb
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
- #credentials ⇒ Object
- #current_time ⇒ Object
- #database ⇒ Object
-
#initialize(cap_instance) ⇒ Base
constructor
A new instance of Base.
- #mysql? ⇒ Boolean
- #pgpass ⇒ Object
- #postgresql? ⇒ Boolean
Constructor Details
#initialize(cap_instance) ⇒ Base
Returns a new instance of Base.
4 5 6 |
# File 'lib/capistrano-db-tasks/database.rb', line 4 def initialize(cap_instance) @cap = cap_instance end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/capistrano-db-tasks/database.rb', line 3 def config @config end |
#output_file ⇒ Object
Returns the value of attribute output_file.
3 4 5 |
# File 'lib/capistrano-db-tasks/database.rb', line 3 def output_file @output_file end |
Instance Method Details
#credentials ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/capistrano-db-tasks/database.rb', line 16 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
39 40 41 |
# File 'lib/capistrano-db-tasks/database.rb', line 39 def current_time Time.now.strftime("%Y-%m-%d-%H%M%S") end |
#database ⇒ Object
35 36 37 |
# File 'lib/capistrano-db-tasks/database.rb', line 35 def database @config['database'] end |
#mysql? ⇒ Boolean
8 9 10 |
# File 'lib/capistrano-db-tasks/database.rb', line 8 def mysql? @config['adapter'] =~ /^mysql/ end |
#pgpass ⇒ Object
47 48 49 |
# File 'lib/capistrano-db-tasks/database.rb', line 47 def pgpass "PGPASSWORD='#{@config['password']}'" if @config['password'] end |
#postgresql? ⇒ Boolean
12 13 14 |
# File 'lib/capistrano-db-tasks/database.rb', line 12 def postgresql? %w(postgresql pg).include? @config['adapter'] end |