23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/pluto/connecter.rb', line 23
def connect( config={} )
if config.empty?
logger.debug "ENV['DATBASE_URL'] - >#{ENV['DATABASE_URL']}<"
db = URI.parse( ENV['DATABASE_URL'] || 'sqlite3:///pluto.db' )
if db.scheme == 'postgres'
config = {
adapter: 'postgresql',
host: db.host,
port: db.port,
username: db.user,
password: db.password,
database: db.path[1..-1],
encoding: 'utf8'
}
else
config = {
adapter: db.scheme,
database: db.path[1..-1]
}
end
end
logger.info 'db settings:'
logger.info config.pretty_inspect
if ActiveRecord::Base.configurations.nil?
logger.debug "ActiveRecord configurations nil - set to empty hash"
ActiveRecord::Base.configurations = {}
end
if debug?
logger.debug 'ar configurations (before):'
logger.debug ActiveRecord::Base.configurations.pretty_inspect
end
configs = ActiveRecord::Base.configurations.to_h.reject { |db_config| db_config.env_name == 'pluto' }
configs['pluto'] = config
ActiveRecord::Base.configurations = configs
if debug?
logger.debug 'ar configurations (after):'
logger.debug ActiveRecord::Base.configurations.pretty_inspect
end
if debug?
ActiveRecord::Base.logger = Logger.new( STDOUT )
end
ActiveRecord::Base.establish_connection( config )
end
|