Class: SakaiInfo::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/sakai-info/database.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection_string, logger = nil) ⇒ Database

Returns a new instance of Database.



108
109
110
111
# File 'lib/sakai-info/database.rb', line 108

def initialize(connection_string, logger = nil)
  @connection_string = connection_string.to_s
  @logger = logger
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/sakai-info/database.rb', line 137

def alive?
  (not @connection.nil?) && @connection.test_connection
end

#connectObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/sakai-info/database.rb', line 113

def connect
  if @connection and self.alive?
    return @connection
  end

  begin
    @connection = Sequel.connect(@connection_string)
  rescue => e
    @connection = nil
    raise ConnectionFailureException.new("Could not connect: #{e}")
  end

  if not @logger.nil?
    @connection.logger = @logger
  end

  return @connection
end

#logger=(logger) ⇒ Object



132
133
134
135
# File 'lib/sakai-info/database.rb', line 132

def logger=(logger)
  @logger = logger
  @connection.logger = @logger
end