Module: Kaal::Rails
- Defined in:
- lib/kaal/rails.rb,
lib/kaal/rails/railtie.rb,
lib/kaal/rails/version.rb,
lib/kaal/rails/installer.rb
Overview
Rails integration surface for Kaal.
Defined Under Namespace
Classes: Installer, Railtie
Constant Summary
collapse
- DETECT_BACKEND_DEFAULT =
Object.new
- VERSION =
'0.6.0'
Class Method Summary
collapse
Class Method Details
.build_backend(backend_name = detect_backend_name) ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/kaal/rails.rb', line 32
def build_backend(backend_name = detect_backend_name)
case backend_name.to_s
when 'sqlite'
Kaal::Backend::SQLite.new
when 'postgres'
Kaal::Backend::Postgres.new
when 'mysql'
Kaal::Backend::MySQL.new
end
end
|
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/kaal/rails.rb', line 43
def configure_backend!(configuration: Kaal.configuration, backend: build_backend)
load_config_file!(configuration:)
logger = configuration.logger
current_backend = configuration.backend
selected_backend = current_backend || backend
return nil unless selected_backend
configuration.backend = selected_backend unless current_backend
Kaal.warn_on_risky_configuration!(configuration:, logger:)
selected_backend
end
|
.detect_backend_name(db_config = DETECT_BACKEND_DEFAULT) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/kaal/rails.rb', line 19
def detect_backend_name(db_config = DETECT_BACKEND_DEFAULT)
db_config = ::ActiveRecord::Base.connection_db_config if db_config.equal?(DETECT_BACKEND_DEFAULT)
adapter = db_config&.adapter.to_s.downcase
return 'sqlite' if adapter.include?('sqlite')
return 'postgres' if adapter.include?('postgres')
return 'mysql' if adapter.include?('mysql') || adapter.include?('trilogy')
nil
rescue ::ActiveRecord::ConnectionNotEstablished
nil
end
|
.install!(root: ::Rails.root, backend: detect_backend_name) ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'lib/kaal/rails.rb', line 60
def install!(root: ::Rails.root, backend: detect_backend_name)
installer = Installer.new(root:, backend:)
{
runtime_config: installer.install_runtime_config,
scheduler_config: installer.install_scheduler_config,
migrations: installer.install_migrations
}
end
|
.load_config_file!(configuration: Kaal.configuration, root: ::Rails.root, environment: ::Rails.env) ⇒ Object
55
56
57
58
|
# File 'lib/kaal/rails.rb', line 55
def load_config_file!(configuration: Kaal.configuration, root: ::Rails.root, environment: ::Rails.env)
runtime_context = Kaal::Runtime::RuntimeContext.new(root_path: root, environment_name: environment.to_s)
Kaal::Config::FileLoader.new(configuration:, runtime_context:).load
end
|