Class: Kaal::Configuration
- Inherits:
-
Object
- Object
- Kaal::Configuration
- Defined in:
- lib/kaal/config/configuration.rb
Overview
Configuration class for Kaal Holds all settings for the scheduler, tick intervals, locks, and more.
Constant Summary collapse
- DEFAULTS =
Default values for all configuration options
{ tick_interval: 5, window_lookback: 120, window_lookahead: 0, lease_ttl: 125, # Must be >= window_lookback + tick_interval (120 + 5 = 125) namespace: 'kaal', backend: nil, logger: nil, time_zone: nil, enable_log_dispatch_registry: false, enable_dispatch_recovery: true, recovery_window: 86_400, # 24 hours in seconds recovery_startup_jitter: 5, # max random delay in seconds scheduler_config_path: 'config/scheduler.yml', scheduler_conflict_policy: :error, scheduler_missing_file_policy: :warn }.freeze
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
Initialize a new Configuration instance with default values.
-
#method_missing(method_name, *args) ⇒ Object
Retrieve or assign configuration values by method name.
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Advertise supported configuration keys for respond_to?.
-
#to_h ⇒ Hash
Get a hash representation of the current configuration.
-
#validate ⇒ Array<String>
Validate configuration without raising.
-
#validate! ⇒ Configuration
Validate the configuration settings.
Constructor Details
#initialize ⇒ Configuration
Initialize a new Configuration instance with default values.
41 42 43 |
# File 'lib/kaal/config/configuration.rb', line 41 def initialize @values = DEFAULTS.dup end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
Retrieve or assign configuration values by method name.
47 48 49 50 51 52 53 54 55 |
# File 'lib/kaal/config/configuration.rb', line 47 def method_missing(method_name, *args) handled, value = handle_known_key(method_name) do |key, setter| setter ? set_value(key, args.first) : @values[key] end return value if handled super end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Advertise supported configuration keys for respond_to?.
59 60 61 62 |
# File 'lib/kaal/config/configuration.rb', line 59 def respond_to_missing?(method_name, include_private = false) handled, value = handle_known_key(method_name) { true } (handled && value) || super end |
#to_h ⇒ Hash
Get a hash representation of the current configuration.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/kaal/config/configuration.rb', line 89 def to_h backend = @values[:backend] logger = @values[:logger] { tick_interval: @values[:tick_interval], window_lookback: @values[:window_lookback], window_lookahead: @values[:window_lookahead], lease_ttl: @values[:lease_ttl], namespace: @values[:namespace], backend: backend&.class&.name, logger: logger&.class&.name, time_zone: @values[:time_zone], enable_log_dispatch_registry: @values[:enable_log_dispatch_registry], enable_dispatch_recovery: @values[:enable_dispatch_recovery], recovery_window: @values[:recovery_window], recovery_startup_jitter: @values[:recovery_startup_jitter], scheduler_config_path: @values[:scheduler_config_path], scheduler_conflict_policy: @values[:scheduler_conflict_policy], scheduler_missing_file_policy: @values[:scheduler_missing_file_policy] } end |
#validate ⇒ Array<String>
Validate configuration without raising.
68 69 70 |
# File 'lib/kaal/config/configuration.rb', line 68 def validate validation_errors end |
#validate! ⇒ Configuration
Validate the configuration settings. Raises errors if required settings are invalid.
78 79 80 81 82 83 |
# File 'lib/kaal/config/configuration.rb', line 78 def validate! errors = validation_errors raise ConfigurationError, errors.join('; ') if errors.any? self end |