Class: Backhoe::Database
- Inherits:
-
Object
- Object
- Backhoe::Database
- Defined in:
- lib/backhoe/database.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #adapter ⇒ Object
- #current_environment_name ⇒ Object
-
#initialize(config = load_config) ⇒ Database
constructor
A new instance of Database.
- #mysql? ⇒ Boolean
- #name ⇒ Object
- #postgresql? ⇒ Boolean
- #to_mysql_options ⇒ Object
Constructor Details
#initialize(config = load_config) ⇒ Database
Returns a new instance of Database.
3 4 5 |
# File 'lib/backhoe/database.rb', line 3 def initialize config=load_config @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/backhoe/database.rb', line 7 def config @config end |
Instance Method Details
#adapter ⇒ Object
29 30 31 |
# File 'lib/backhoe/database.rb', line 29 def adapter config["adapter"] end |
#current_environment_name ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/backhoe/database.rb', line 9 def current_environment_name [ defined?(Rails) && Rails.env, ENV["RAILS_ENV"], "development", ].find(&:itself) end |
#mysql? ⇒ Boolean
37 38 39 |
# File 'lib/backhoe/database.rb', line 37 def mysql? %w[mysql2 trilogy].include?(config["adapter"]) end |
#name ⇒ Object
25 26 27 |
# File 'lib/backhoe/database.rb', line 25 def name config["database"] end |
#postgresql? ⇒ Boolean
33 34 35 |
# File 'lib/backhoe/database.rb', line 33 def postgresql? config["adapter"] == "postgresql" end |
#to_mysql_options ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/backhoe/database.rb', line 17 def = " -u #{config["username"]}" += " -p'#{config["password"]}'" if config["password"] += " -h #{config["host"]}" if config["host"] += " -S #{config["socket"]}" if config["socket"] end |