Class: RubyTodo::Database
- Inherits:
-
Object
- Object
- RubyTodo::Database
- Defined in:
- lib/ruby_todo/database.rb
Class Method Summary collapse
Class Method Details
.db ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ruby_todo/database.rb', line 26 def db # Ensure connection is established setup unless initialized? # Return connection ActiveRecord::Base.connection end |
.initialized? ⇒ Boolean
18 19 20 21 22 23 24 |
# File 'lib/ruby_todo/database.rb', line 18 def initialized? # Try to check if the database exists and is set up db_path = File.("~/.ruby_todo/ruby_todo.db") File.exist?(db_path) && ActiveRecord::Base.connected? rescue StandardError false end |
.setup ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/ruby_todo/database.rb', line 10 def setup return if ActiveRecord::Base.connected? ensure_database_directory establish_connection create_tables end |