Class: Baza::Database
- Inherits:
-
Object
- Object
- Baza::Database
- Includes:
- DatabaseModelFunctionality
- Defined in:
- lib/baza/database.rb
Direct Known Subclasses
Baza::Driver::Mysql::Database, Baza::Driver::Pg::Database, Baza::Driver::Sqlite3::Database, Baza::Driver::Sqlite3java::Database
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
-
#name ⇒ Object
Returns the value of attribute name.
-
#name_was ⇒ Object
readonly
Returns the value of attribute name_was.
Instance Method Summary collapse
-
#initialize(args) ⇒ Database
constructor
A new instance of Database.
- #save! ⇒ Object
- #table(name) ⇒ Object
- #table_exists?(name) ⇒ Boolean
- #tables(args = {}) ⇒ Object
- #to_param ⇒ Object
- #use(&blk) ⇒ Object
Methods included from DatabaseModelFunctionality
Constructor Details
#initialize(args) ⇒ Database
Returns a new instance of Database.
7 8 9 10 11 12 |
# File 'lib/baza/database.rb', line 7 def initialize(args) @db = args.fetch(:db) @driver = args.fetch(:driver) @name = args.fetch(:name) @name_was = @name end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
4 5 6 |
# File 'lib/baza/database.rb', line 4 def db @db end |
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
4 5 6 |
# File 'lib/baza/database.rb', line 4 def driver @driver end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/baza/database.rb', line 5 def name @name end |
#name_was ⇒ Object (readonly)
Returns the value of attribute name_was.
4 5 6 |
# File 'lib/baza/database.rb', line 4 def name_was @name_was end |
Instance Method Details
#save! ⇒ Object
38 39 40 |
# File 'lib/baza/database.rb', line 38 def save! raise Baza::Errors::NotImplemented end |
#table(name) ⇒ Object
25 26 27 28 29 |
# File 'lib/baza/database.rb', line 25 def table(name) table = tables(name: name).first raise Baza::Errors::TableNotFound unless table table end |
#table_exists?(name) ⇒ Boolean
31 32 33 34 35 36 |
# File 'lib/baza/database.rb', line 31 def table_exists?(name) table(name) true rescue Baza::Errors::TableNotFound false end |
#tables(args = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/baza/database.rb', line 14 def tables(args = {}) list_args = {database: name} list_args[:name] = args.fetch(:name) if args[:name] ArrayEnumerator.new do |yielder| @db.tables.list(list_args) do |table| yielder << table end end end |
#to_param ⇒ Object
42 43 44 |
# File 'lib/baza/database.rb', line 42 def to_param name end |
#use(&blk) ⇒ Object
46 47 48 |
# File 'lib/baza/database.rb', line 46 def use(&blk) @db.databases.with_database(name, &blk) end |