Class: OkComputer::SequelCheck
- Defined in:
- lib/ok_computer/built_in_checks/sequel_check.rb
Constant Summary collapse
- ConnectionFailed =
Class.new(StandardError)
Constants inherited from Check
Instance Attribute Summary collapse
-
#migration_directory ⇒ Object
readonly
Returns the value of attribute migration_directory.
Attributes inherited from Check
#failure_occurred, #message, #registrant_name, #time
Instance Method Summary collapse
-
#check ⇒ Object
Public: Return the schema version of the database.
- #database ⇒ Object
-
#initialize(options = {}) ⇒ SequelCheck
constructor
Public: Initialize the SequelCheck with the database and/or the migration_directory.
-
#is_current? ⇒ Boolean
Public: The scema version of the app’s database.
Methods inherited from Check
#<=>, #clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text, #with_benchmarking
Constructor Details
#initialize(options = {}) ⇒ SequelCheck
Public: Initialize the SequelCheck with the database and/or the migration_directory.
Defaults to Sequel:Model.db and ‘db/migration’ respectively. “database” option can be a Proc so that Sequel can be instantiated later in the boot process.
9 10 11 12 |
# File 'lib/ok_computer/built_in_checks/sequel_check.rb', line 9 def initialize(={}) @database = [:database] || -> { ::Sequel::Model.db } @migration_directory = [:migration_directory] || 'db/migrate' end |
Instance Attribute Details
#migration_directory ⇒ Object (readonly)
Returns the value of attribute migration_directory.
3 4 5 |
# File 'lib/ok_computer/built_in_checks/sequel_check.rb', line 3 def migration_directory @migration_directory end |
Instance Method Details
#check ⇒ Object
Public: Return the schema version of the database
15 16 17 18 19 20 |
# File 'lib/ok_computer/built_in_checks/sequel_check.rb', line 15 def check "Schema is #{'not ' unless is_current?}up to date" rescue ConnectionFailed => e mark_failure "Error: '#{e}'" end |
#database ⇒ Object
22 23 24 |
# File 'lib/ok_computer/built_in_checks/sequel_check.rb', line 22 def database @database.is_a?(Proc) ? @database.call : @database end |
#is_current? ⇒ Boolean
Public: The scema version of the app’s database
Returns a String with the version number
29 30 31 32 33 34 |
# File 'lib/ok_computer/built_in_checks/sequel_check.rb', line 29 def is_current? ::Sequel.extension(:migration) ::Sequel::Migrator.is_current?(database, migration_directory) rescue => e raise ConnectionFailed, e end |