Class: Baza::Database

Inherits:
Object
  • Object
show all
Includes:
DatabaseModelFunctionality
Defined in:
lib/baza/database.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DatabaseModelFunctionality

#model_name, #to_model

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

#dbObject (readonly)

Returns the value of attribute db.



4
5
6
# File 'lib/baza/database.rb', line 4

def db
  @db
end

#driverObject (readonly)

Returns the value of attribute driver.



4
5
6
# File 'lib/baza/database.rb', line 4

def driver
  @driver
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/baza/database.rb', line 5

def name
  @name
end

#name_wasObject (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

Returns:

  • (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_paramObject



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