Class: Mihari::Database
- Inherits:
-
Object
- Object
- Mihari::Database
- Defined in:
- lib/mihari/database.rb
Overview
Database
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)
149 150 151 152 153 |
# File 'lib/mihari/database.rb', line 149 def close return unless connected? ActiveRecord::Base.connection_handler.clear_active_connections! end |
.connect ⇒ Object
Establish DB connection
132 133 134 135 136 137 |
# File 'lib/mihari/database.rb', line 132 def connect return if connected? ActiveRecord::Base.establish_connection Mihari.config.database_url.to_s ActiveRecord::Base.logger = Logger.new($stdout) if Mihari.development? end |
.connected? ⇒ Boolean
142 143 144 |
# File 'lib/mihari/database.rb', line 142 def connected? ActiveRecord::Base.connected? end |
.migrate(direction) ⇒ Object
DB migration
125 126 127 |
# File 'lib/mihari/database.rb', line 125 def migrate(direction) schemas.each { |schema| schema.migrate direction } end |
.with_db_connection ⇒ Object
155 156 157 158 159 160 161 162 |
# File 'lib/mihari/database.rb', line 155 def with_db_connection Mihari::Database.connect unless connected? yield rescue ActiveRecord::StatementInvalid Mihari.logger.error("DB migration is not yet complete. Please run 'mihari db migrate'.") ensure Mihari::Database.close end |