Class: SakaiInfo::Database

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

Instance Method Summary collapse

Constructor Details

#initialize(connect_info, logger = nil) ⇒ Database

Returns a new instance of Database.



169
170
171
172
173
174
175
# File 'lib/sakai-info/database.rb', line 169

def initialize(connect_info, logger = nil)
  if connect_info.nil?
    raise MissingConfigException.new("No configuration was provided")
  end
  @connect_info = connect_info
  @logger = logger
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


201
202
203
# File 'lib/sakai-info/database.rb', line 201

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

#connectObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/sakai-info/database.rb', line 177

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

  begin
    @connection = Sequel.connect(@connect_info)
  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



196
197
198
199
# File 'lib/sakai-info/database.rb', line 196

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