Class: EventSystem::Configuration
- Inherits:
-
Object
- Object
- EventSystem::Configuration
- Defined in:
- lib/event_system/configuration.rb
Overview
Configuration class for the EventSystem Provides a centralized way to configure storage, logging, and other options
Instance Attribute Summary collapse
-
#auto_flush ⇒ Object
Returns the value of attribute auto_flush.
-
#logger ⇒ Logger
Get the logger instance, creating a default one if none is set.
-
#session_id ⇒ String
Get the current session ID, creating one if none is set.
-
#storage_options ⇒ Object
Returns the value of attribute storage_options.
-
#storage_type ⇒ Object
Returns the value of attribute storage_type.
Instance Method Summary collapse
-
#create_storage ⇒ EventSystem::Storage::Base
Create a new storage instance with the current configuration.
-
#initialize ⇒ Configuration
constructor
Initialize a new configuration.
-
#reset! ⇒ void
Reset the configuration to defaults.
-
#storage_class ⇒ Class
Get the storage class based on the configured type.
-
#to_h ⇒ Hash
Get configuration as a hash.
-
#valid? ⇒ Boolean
Validate the current configuration.
Constructor Details
#initialize ⇒ Configuration
Initialize a new configuration
10 11 12 13 14 15 16 |
# File 'lib/event_system/configuration.rb', line 10 def initialize @storage_type = :memory @storage_options = {} @logger = nil @session_id = nil @auto_flush = true end |
Instance Attribute Details
#auto_flush ⇒ Object
Returns the value of attribute auto_flush.
7 8 9 |
# File 'lib/event_system/configuration.rb', line 7 def auto_flush @auto_flush end |
#logger ⇒ Logger
Get the logger instance, creating a default one if none is set
39 40 41 |
# File 'lib/event_system/configuration.rb', line 39 def logger @logger end |
#session_id ⇒ String
Get the current session ID, creating one if none is set
51 52 53 |
# File 'lib/event_system/configuration.rb', line 51 def session_id @session_id end |
#storage_options ⇒ Object
Returns the value of attribute storage_options.
7 8 9 |
# File 'lib/event_system/configuration.rb', line 7 def @storage_options end |
#storage_type ⇒ Object
Returns the value of attribute storage_type.
7 8 9 |
# File 'lib/event_system/configuration.rb', line 7 def storage_type @storage_type end |
Instance Method Details
#create_storage ⇒ EventSystem::Storage::Base
Create a new storage instance with the current configuration
33 34 35 |
# File 'lib/event_system/configuration.rb', line 33 def create_storage storage_class.new(*storage_constructor_args) end |
#reset! ⇒ void
This method returns an undefined value.
Reset the configuration to defaults
63 64 65 66 67 68 69 |
# File 'lib/event_system/configuration.rb', line 63 def reset! @storage_type = :memory @storage_options = {} @logger = nil @session_id = nil @auto_flush = true end |
#storage_class ⇒ Class
Get the storage class based on the configured type
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/event_system/configuration.rb', line 20 def storage_class case @storage_type when :memory Storage::MemoryStore when :file Storage::FileStore else raise ArgumentError, "Unknown storage type: #{@storage_type}. Available types: :memory, :file" end end |
#to_h ⇒ Hash
Get configuration as a hash
88 89 90 91 92 93 94 95 |
# File 'lib/event_system/configuration.rb', line 88 def to_h { storage_type: @storage_type, storage_options: @storage_options, session_id: @session_id, auto_flush: @auto_flush } end |
#valid? ⇒ Boolean
Validate the current configuration
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/event_system/configuration.rb', line 73 def valid? return false unless [:memory, :file].include?(@storage_type) return false if @storage_options.nil? case @storage_type when :file directory = @storage_options[:directory] || @storage_options['directory'] return false if directory.nil? || directory.empty? end true end |