Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/fb_adapter.rb

Class Method Summary collapse

Class Method Details

.fb_connection(config) ⇒ Object

:nodoc:


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/active_record/connection_adapters/fb_adapter.rb', line 54

def fb_connection(config) # :nodoc:
  config = config.symbolize_keys.merge(:downcase_names => true)
  unless config.has_key?(:database)
    raise ArgumentError, "No database specified. Missing argument: database."
  end      
  config[:database] = File.expand_path(config[:database]) if config[:host] =~ /localhost/i
  config[:database] = "#{config[:host]}/#{config[:port] || 3050}:#{config[:database]}" if config[:host]
  require 'fb'
  db = Fb::Database.new(config)
  begin
    connection = db.connect
  rescue
    require 'pp'
    pp config unless config[:create]
    connection = config[:create] ? db.create.connect : (raise ConnectionNotEstablished, "No Firebird connections established.")
  end
  ConnectionAdapters::FbAdapter.new(connection, logger, config)
end