Class: Database

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/tmis/engine/database.rb

Overview

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



26
27
28
# File 'lib/tmis/engine/database.rb', line 26

def path
  @path
end

Instance Method Details

#connect_to(path) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/tmis/engine/database.rb', line 28

def connect_to(path)
  @path = path
  if ActiveRecord::Base.connected?
    ActiveRecord::Base.remove_connection
    connect path
  else
    connect path
  end
  self
end

#connected?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/tmis/engine/database.rb', line 39

def connected?
  ActiveRecord::Base.connected?
end

#disconnectObject



43
44
45
# File 'lib/tmis/engine/database.rb', line 43

def disconnect
  ActiveRecord::Base.remove_connection; self
end

#transaction(&block) ⇒ Object



47
48
49
# File 'lib/tmis/engine/database.rb', line 47

def transaction(&block)
  ActiveRecord::Base.transaction(&block); self
end