Class: EventSystem::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_flushObject

Returns the value of attribute auto_flush.



7
8
9
# File 'lib/event_system/configuration.rb', line 7

def auto_flush
  @auto_flush
end

#loggerLogger

Get the logger instance, creating a default one if none is set

Returns:

  • (Logger)

    The logger instance



39
40
41
# File 'lib/event_system/configuration.rb', line 39

def logger
  @logger
end

#session_idString

Get the current session ID, creating one if none is set

Returns:

  • (String)

    The current session ID



51
52
53
# File 'lib/event_system/configuration.rb', line 51

def session_id
  @session_id
end

#storage_optionsObject

Returns the value of attribute storage_options.



7
8
9
# File 'lib/event_system/configuration.rb', line 7

def storage_options
  @storage_options
end

#storage_typeObject

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_storageEventSystem::Storage::Base

Create a new storage instance with the current configuration

Returns:



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_classClass

Get the storage class based on the configured type

Returns:

  • (Class)

    The storage class to use



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_hHash

Get configuration as a hash

Returns:

  • (Hash)

    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

Returns:

  • (Boolean)

    True if configuration is valid



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