Class: Fractor::Configuration
- Inherits:
-
Object
- Object
- Fractor::Configuration
- Defined in:
- lib/fractor/configuration.rb
Overview
Central configuration management for Fractor. Provides a unified way to configure all Fractor components.
Constant Summary collapse
- DEFAULTS =
Default configuration values
{ debug: false, log_level: Logger::INFO, default_worker_timeout: 120, default_max_retries: 3, default_retry_delay: 1, enable_performance_monitoring: false, enable_error_reporting: false, ractor_pool_size: nil, # nil = auto-detect (CPU count) workflow_validation_strict: true, thread_safe: true, }.freeze
Instance Attribute Summary collapse
-
#debug ⇒ Object
Other configuration attributes.
-
#default_max_retries ⇒ Object
Other configuration attributes.
-
#default_retry_delay ⇒ Object
Other configuration attributes.
-
#default_worker_timeout ⇒ Object
Other configuration attributes.
-
#enable_error_reporting ⇒ Object
Other configuration attributes.
-
#enable_performance_monitoring ⇒ Object
Other configuration attributes.
-
#log_level ⇒ Object
Other configuration attributes.
-
#ractor_pool_size ⇒ Object
Other configuration attributes.
-
#thread_safe ⇒ Object
Other configuration attributes.
-
#workflow_validation_strict ⇒ Object
Other configuration attributes.
Class Method Summary collapse
-
.apply_config(config_hash) ⇒ Object
Load configuration from a hash.
-
.config ⇒ Object
Access configuration properties directly on Fractor.
-
.configure {|Configuration| ... } ⇒ Object
Configure Fractor with a block.
-
.configure_from_env ⇒ Object
Load configuration from environment variables.
-
.configure_from_file(file_path) ⇒ Object
Load configuration from a YAML file.
-
.instance ⇒ Configuration
Get the global configuration instance.
-
.reset! ⇒ Object
Reset configuration to defaults.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Get a configuration value by key.
-
#[]=(key, value) ⇒ Object
Set a configuration value by key.
-
#debug_enabled? ⇒ Boolean
Check if debug logging is enabled.
-
#initialize ⇒ Configuration
constructor
Initialize a new configuration with default values.
-
#logger ⇒ Logger
Get the logger instance (creates default if not set).
-
#logger=(logger_instance) ⇒ Object
Set the logger instance.
-
#to_h ⇒ Hash
Export configuration as hash.
-
#validate! ⇒ Boolean
Validate configuration.
Constructor Details
#initialize ⇒ Configuration
Initialize a new configuration with default values.
201 202 203 |
# File 'lib/fractor/configuration.rb', line 201 def initialize apply_defaults end |
Instance Attribute Details
#debug ⇒ Object
Other configuration attributes
60 61 62 |
# File 'lib/fractor/configuration.rb', line 60 def debug @debug end |
#default_max_retries ⇒ Object
Other configuration attributes
60 61 62 |
# File 'lib/fractor/configuration.rb', line 60 def default_max_retries @default_max_retries end |
#default_retry_delay ⇒ Object
Other configuration attributes
60 61 62 |
# File 'lib/fractor/configuration.rb', line 60 def default_retry_delay @default_retry_delay end |
#default_worker_timeout ⇒ Object
Other configuration attributes
60 61 62 |
# File 'lib/fractor/configuration.rb', line 60 def default_worker_timeout @default_worker_timeout end |
#enable_error_reporting ⇒ Object
Other configuration attributes
60 61 62 |
# File 'lib/fractor/configuration.rb', line 60 def enable_error_reporting @enable_error_reporting end |
#enable_performance_monitoring ⇒ Object
Other configuration attributes
60 61 62 |
# File 'lib/fractor/configuration.rb', line 60 def enable_performance_monitoring @enable_performance_monitoring end |
#log_level ⇒ Object
Other configuration attributes
60 61 62 |
# File 'lib/fractor/configuration.rb', line 60 def log_level @log_level end |
#ractor_pool_size ⇒ Object
Other configuration attributes
60 61 62 |
# File 'lib/fractor/configuration.rb', line 60 def ractor_pool_size @ractor_pool_size end |
#thread_safe ⇒ Object
Other configuration attributes
60 61 62 |
# File 'lib/fractor/configuration.rb', line 60 def thread_safe @thread_safe end |
#workflow_validation_strict ⇒ Object
Other configuration attributes
60 61 62 |
# File 'lib/fractor/configuration.rb', line 60 def workflow_validation_strict @workflow_validation_strict end |
Class Method Details
.apply_config(config_hash) ⇒ Object
Load configuration from a hash.
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/fractor/configuration.rb', line 120 def apply_config(config_hash) return if config_hash.nil? || config_hash.empty? config_hash.each do |key, value| setter = "#{key}=" if instance.respond_to?(setter) instance.public_send(setter, value) else warn "Unknown configuration option: #{key}" end end end |
.config ⇒ Object
Access configuration properties directly on Fractor.
172 173 174 |
# File 'lib/fractor/configuration.rb', line 172 def config instance end |
.configure {|Configuration| ... } ⇒ Object
Configure Fractor with a block.
90 91 92 93 |
# File 'lib/fractor/configuration.rb', line 90 def configure yield instance if block_given? instance end |
.configure_from_env ⇒ Object
Load configuration from environment variables. Environment variables should be prefixed with FRACTOR_.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/fractor/configuration.rb', line 142 def configure_from_env env_config = {} ENV.each do |key, value| next unless key.start_with?("FRACTOR_") config_key = key.sub(/^FRACTOR_/, "").downcase config_key = underscore_to_camelcase(config_key) # Convert string values to appropriate types typed_value = parse_env_value(value) env_config[config_key] = typed_value end apply_config(env_config) end |
.configure_from_file(file_path) ⇒ Object
Load configuration from a YAML file.
108 109 110 111 112 113 114 115 |
# File 'lib/fractor/configuration.rb', line 108 def configure_from_file(file_path) unless File.exist?(file_path) raise ArgumentError, "Configuration file not found: #{file_path}" end config_data = YAML.load_file(file_path) apply_config(config_data) end |
.instance ⇒ Configuration
Get the global configuration instance.
73 74 75 76 77 78 79 |
# File 'lib/fractor/configuration.rb', line 73 def instance return @instance if @instance @mutex.synchronize do @instance ||= new end end |
.reset! ⇒ Object
Reset configuration to defaults. Useful for testing.
161 162 163 164 165 |
# File 'lib/fractor/configuration.rb', line 161 def reset! @mutex.synchronize do @instance = new end end |
Instance Method Details
#[](key) ⇒ Object
Get a configuration value by key.
209 210 211 |
# File 'lib/fractor/configuration.rb', line 209 def [](key) public_send(key) if respond_to?(key) end |
#[]=(key, value) ⇒ Object
Set a configuration value by key.
217 218 219 220 |
# File 'lib/fractor/configuration.rb', line 217 def []=(key, value) setter = "#{key}=" public_send(setter, value) if respond_to?(setter) end |
#debug_enabled? ⇒ Boolean
Check if debug logging is enabled.
55 56 57 |
# File 'lib/fractor/configuration.rb', line 55 def debug_enabled? debug && logger&.debug? end |
#logger ⇒ Logger
Get the logger instance (creates default if not set).
41 42 43 |
# File 'lib/fractor/configuration.rb', line 41 def logger @logger ||= create_default_logger end |
#logger=(logger_instance) ⇒ Object
Set the logger instance.
48 49 50 |
# File 'lib/fractor/configuration.rb', line 48 def logger=(logger_instance) @logger = logger_instance end |
#to_h ⇒ Hash
Export configuration as hash.
225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/fractor/configuration.rb', line 225 def to_h { debug: @debug, log_level: @log_level, default_worker_timeout: @default_worker_timeout, default_max_retries: @default_max_retries, default_retry_delay: @default_retry_delay, enable_performance_monitoring: @enable_performance_monitoring, enable_error_reporting: @enable_error_reporting, ractor_pool_size: @ractor_pool_size, workflow_validation_strict: @workflow_validation_strict, thread_safe: @thread_safe, } end |
#validate! ⇒ Boolean
Validate configuration.
244 245 246 247 248 249 |
# File 'lib/fractor/configuration.rb', line 244 def validate! validate_timeouts! validate_retries! validate_pool_size! true end |