Class: Miteru::Database
- Inherits:
-
Object
- Object
- Miteru::Database
- Defined in:
- lib/miteru/database.rb
Class Method Summary collapse
-
.close ⇒ Object
Close DB connection(s).
-
.connect ⇒ Object
Establish DB connection.
- .connected? ⇒ Boolean
-
.migrate(direction) ⇒ Object
DB migration.
- .with_db_connection ⇒ Object
Class Method Details
.close ⇒ Object
Close DB connection(s)
60 61 62 63 64 |
# File 'lib/miteru/database.rb', line 60 def close return unless connected? ActiveRecord::Base.connection_handler.clear_active_connections! end |
.connect ⇒ Object
Establish DB connection
43 44 45 46 47 48 |
# File 'lib/miteru/database.rb', line 43 def connect return if connected? ActiveRecord::Base.establish_connection Miteru.config.database_url.to_s ActiveRecord::Base.logger = Logger.new($stdout) if Miteru.development? end |
.connected? ⇒ Boolean
53 54 55 |
# File 'lib/miteru/database.rb', line 53 def connected? ActiveRecord::Base.connected? end |
.migrate(direction) ⇒ Object
DB migration
36 37 38 |
# File 'lib/miteru/database.rb', line 36 def migrate(direction) schemas.each { |schema| schema.migrate direction } end |
.with_db_connection ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/miteru/database.rb', line 66 def with_db_connection Miteru::Database.connect unless connected? yield rescue ActiveRecord::StatementInvalid Miteru.logger.error("DB migration is not yet complete. Please run 'miteru db migrate'.") ensure Miteru::Database.close end |