Class: Shepherd::Db
- Inherits:
-
Object
- Object
- Shepherd::Db
- Defined in:
- lib/shepherd/db.rb
Overview
A class through which you can connect to the database.
Usage
module Shepherd
Db.new.execute "sql query"
end
Inside a Shepherd::Command::Klass
, it would look like:
module Shepherd::Command
class Klass
def init
Shepherd::Db.new.execute "sql query"
end
end
end
Here is SQLite3 documantation. Shepherd::Db.new
is equal to SQLite3::Database.new
so there you’ve got a complete documentation.
Defined Under Namespace
Classes: DatabaseNotFound
Instance Method Summary collapse
-
#initialize ⇒ Db
constructor
A new instance of Db.
- #method_missing(m, *args, &block) ⇒ Object
Constructor Details
#initialize ⇒ Db
Returns a new instance of Db.
30 31 32 33 34 |
# File 'lib/shepherd/db.rb', line 30 def initialize raise DatabaseNotFound, "Error: database file not found: '#{Dir.home}/.shepherd/herd.db'\nTry running 'shep setup'." unless File.exists? "#{Dir.home}/.shepherd/herd.db" # A new instance of +SQLite3::Database+ @db = SQLite3::Database.new "#{Dir.home}/.shepherd/herd.db" end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
36 37 38 |
# File 'lib/shepherd/db.rb', line 36 def method_missing m, *args, &block @db.send m, *args, &block end |