Class: Takagi::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/takagi/config.rb

Overview

Stores runtime configuration loaded from YAML or manual overrides.

Defined Under Namespace

Classes: AllocationConfig, EventBusConfig, MiddlewareConfig, Observability, PluginConfig, RouterConfig

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/takagi/config.rb', line 24

def initialize
  set_server_defaults
  set_observability_defaults
  set_event_bus_defaults
  set_router_defaults
  set_middleware_defaults
  set_allocation_defaults
  set_plugin_defaults
  @custom = {}
  @server_name = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/takagi/config.rb', line 44

def method_missing(name, *args, &block)
  key = name.to_s.chomp('=').to_sym
  if name.to_s.end_with?('=')
    @custom[key] = args.first
  elsif @custom.key?(key)
    @custom[key]
  else
    super(&block)
  end
end

Instance Attribute Details

#allocationObject

Returns the value of attribute allocation.



21
22
23
# File 'lib/takagi/config.rb', line 21

def allocation
  @allocation
end

#auto_migrateObject

Returns the value of attribute auto_migrate.



21
22
23
# File 'lib/takagi/config.rb', line 21

def auto_migrate
  @auto_migrate
end

#bind_addressObject

Returns the value of attribute bind_address.



21
22
23
# File 'lib/takagi/config.rb', line 21

def bind_address
  @bind_address
end

#customObject

Returns the value of attribute custom.



21
22
23
# File 'lib/takagi/config.rb', line 21

def custom
  @custom
end

#event_busObject

Returns the value of attribute event_bus.



21
22
23
# File 'lib/takagi/config.rb', line 21

def event_bus
  @event_bus
end

#loggerObject

Returns the value of attribute logger.



21
22
23
# File 'lib/takagi/config.rb', line 21

def logger
  @logger
end

#middlewareObject

Returns the value of attribute middleware.



21
22
23
# File 'lib/takagi/config.rb', line 21

def middleware
  @middleware
end

#observabilityObject

Returns the value of attribute observability.



21
22
23
# File 'lib/takagi/config.rb', line 21

def observability
  @observability
end

#pluginsObject

Returns the value of attribute plugins.



21
22
23
# File 'lib/takagi/config.rb', line 21

def plugins
  @plugins
end

#portObject

Returns the value of attribute port.



21
22
23
# File 'lib/takagi/config.rb', line 21

def port
  @port
end

#processesObject

Returns the value of attribute processes.



21
22
23
# File 'lib/takagi/config.rb', line 21

def processes
  @processes
end

#protocolsObject

Returns the value of attribute protocols.



21
22
23
# File 'lib/takagi/config.rb', line 21

def protocols
  @protocols
end

#routerObject

Returns the value of attribute router.



21
22
23
# File 'lib/takagi/config.rb', line 21

def router
  @router
end

#server_nameObject

Returns the value of attribute server_name.



21
22
23
# File 'lib/takagi/config.rb', line 21

def server_name
  @server_name
end

#threadsObject

Returns the value of attribute threads.



21
22
23
# File 'lib/takagi/config.rb', line 21

def threads
  @threads
end

Instance Method Details

#[](key) ⇒ Object



36
37
38
# File 'lib/takagi/config.rb', line 36

def [](key)
  @custom[key.to_sym]
end

#[]=(key, value) ⇒ Object



40
41
42
# File 'lib/takagi/config.rb', line 40

def []=(key, value)
  @custom[key.to_sym] = value
end

#load_file(path) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/takagi/config.rb', line 60

def load_file(path)
  data = load_yaml(path)

  apply_basic_settings(data)
  apply_logger(data)
  apply_observability(data)
  apply_event_bus(data)
  apply_router(data)
  apply_middleware(data)
  apply_allocation(data)
  apply_plugins(data)
  apply_custom_settings(data)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/takagi/config.rb', line 55

def respond_to_missing?(name, include_private = false)
  key = name.to_s.chomp('=').to_sym
  @custom.key?(key) || super
end