Module: Kaal::Hanami
- Defined in:
- lib/kaal/hanami.rb,
lib/kaal/hanami/version.rb,
lib/kaal/hanami/middleware.rb
Overview
Hanami integration surface for Kaal.
Defined Under Namespace
Classes: Middleware
Constant Summary collapse
- VERSION =
'0.6.0'
Class Method Summary collapse
- .configure!(app) ⇒ Object
- .configure_backend!(backend: nil, database: nil, redis: nil, adapter: nil, configuration: Kaal.configuration) ⇒ Object
- .detect_backend_name(database, adapter: nil) ⇒ Object
- .load_config_file!(root:, environment:, configuration: Kaal.configuration) ⇒ Object
- .load_scheduler_file!(root:, environment: nil) ⇒ Object
- .register!(app, backend: nil, database: nil, redis: nil, scheduler_config_path: 'config/kaal-scheduler.yml', namespace: nil, start_scheduler: false, adapter: nil, root: nil, environment: nil) ⇒ Object
- .start! ⇒ Object
- .stop!(timeout: 30) ⇒ Object
Class Method Details
.configure!(app) ⇒ Object
17 18 19 20 |
# File 'lib/kaal/hanami.rb', line 17 def configure!(app, **) app.config.middleware.use(Kaal::Hanami::Middleware, hanami_app: app, **) app end |
.configure_backend!(backend: nil, database: nil, redis: nil, adapter: nil, configuration: Kaal.configuration) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/kaal/hanami.rb', line 51 def configure_backend!(backend: nil, database: nil, redis: nil, adapter: nil, configuration: Kaal.configuration) current_backend = configuration.backend return current_backend if current_backend return configuration.backend = backend if backend return configuration.backend = build_redis_backend(redis, configuration) if redis explicit_adapter = adapter.to_s.strip unless explicit_adapter.empty? raise ArgumentError, 'database is required when adapter is provided' unless database backend_name = normalize_backend_name(explicit_adapter) raise ArgumentError, "Unsupported Hanami datastore backend: #{adapter.inspect}" unless backend_name return configuration.backend = build_backend(backend_name, database) end return configuration.backend = Kaal::Backend::MemoryAdapter.new unless database backend_name = detect_backend_name(database, adapter:) raise ArgumentError, 'Unsupported Hanami datastore backend; use memory, redis, sqlite, postgres, or mysql' unless backend_name configuration.backend = build_backend(backend_name, database) end |
.detect_backend_name(database, adapter: nil) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/kaal/hanami.rb', line 81 def detect_backend_name(database, adapter: nil) explicit_adapter = normalize_backend_name(adapter) return explicit_adapter if explicit_adapter inferred_adapter = database_adapter_name(database) normalize_backend_name(inferred_adapter) end |
.load_config_file!(root:, environment:, configuration: Kaal.configuration) ⇒ Object
76 77 78 79 |
# File 'lib/kaal/hanami.rb', line 76 def load_config_file!(root:, environment:, configuration: Kaal.configuration) runtime_context = Kaal::Runtime::RuntimeContext.new(root_path: root, environment_name: runtime_environment_name(environment)) Kaal::Config::FileLoader.new(configuration:, runtime_context:).load end |
.load_scheduler_file!(root:, environment: nil) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/kaal/hanami.rb', line 89 def load_scheduler_file!(root:, environment: nil) runtime_context = Kaal::Runtime::RuntimeContext.new( root_path: root, environment_name: runtime_environment_name(environment) ) Kaal::Runtime::SchedulerBootLoader.new( configuration_provider: -> { Kaal.configuration }, logger: Kaal.configuration.logger, runtime_context: runtime_context, load_scheduler_file: -> { Kaal.load_scheduler_file!(runtime_context:) } ).load_on_boot! end |
.register!(app, backend: nil, database: nil, redis: nil, scheduler_config_path: 'config/kaal-scheduler.yml', namespace: nil, start_scheduler: false, adapter: nil, root: nil, environment: nil) ⇒ Object
22 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 |
# File 'lib/kaal/hanami.rb', line 22 def register!( app, backend: nil, database: nil, redis: nil, scheduler_config_path: 'config/kaal-scheduler.yml', namespace: nil, start_scheduler: false, adapter: nil, root: nil, environment: nil ) configuration = Kaal.configuration load_config_file!( root: root_path_for(app, root:), environment: environment_name_for(app, environment:), configuration: ) apply_runtime_overrides(configuration:, scheduler_config_path:, namespace:) configure_backend!(backend:, database:, redis:, adapter:, configuration:) load_scheduler_file!( root: root_path_for(app, root:), environment: environment_name_for(app, environment:) ) start_managed_scheduler! if start_scheduler app end |
.start! ⇒ Object
103 104 105 |
# File 'lib/kaal/hanami.rb', line 103 def start! Kaal.start! end |
.stop!(timeout: 30) ⇒ Object
107 108 109 |
# File 'lib/kaal/hanami.rb', line 107 def stop!(timeout: 30) Kaal.stop!(timeout:) end |