Class: ESM::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/esm/database.rb

Class Method Summary collapse

Class Method Details

.configObject



14
15
16
17
18
19
20
21
# File 'lib/esm/database.rb', line 14

def self.config
  @config ||= YAML.safe_load(
    ERB.new(
      File.read(ESM.root.join("config", "database.yml"))
    ).result,
    aliases: true
  )
end

.connect!Object



5
6
7
8
# File 'lib/esm/database.rb', line 5

def self.connect!
  ActiveRecord::Base.configurations = config
  ActiveRecord::Base.establish_connection(ESM.env.to_sym)
end

.connected?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/esm/database.rb', line 10

def self.connected?
  ActiveRecord::Base.connected?
end

.with_connectionObject



23
24
25
26
27
# File 'lib/esm/database.rb', line 23

def self.with_connection(&)
  ESM::ApplicationRecord
    .connection_pool
    .with_connection(prevent_permanent_checkout: true, &)
end