Class: Takagi::Application::ConfigContext

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

Overview

Configuration DSL context for Application

Instance Method Summary collapse

Constructor Details

#initialize(app_class) ⇒ ConfigContext

Returns a new instance of ConfigContext.



208
209
210
# File 'lib/takagi/application.rb', line 208

def initialize(app_class)
  @app = app_class
end

Instance Method Details

#allocation(mode, threads: nil) ⇒ Object

Configure worker allocation mode

Examples:

Manual allocation (controllers specify their own thread counts)

allocation :manual

Automatic allocation (divide 40 threads among controllers)

allocation :automatic, threads: 40

Parameters:

  • mode (Symbol)

    :manual or :automatic

  • threads (Integer) (defaults to: nil)

    Total threads for automatic mode



242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/takagi/application.rb', line 242

def allocation(mode, threads: nil)
  unless [:manual, :automatic].include?(mode)
    raise ArgumentError, "Invalid allocation mode: #{mode}. Use :manual or :automatic"
  end

  if mode == :automatic && threads.nil?
    raise ArgumentError, "Automatic allocation requires threads: parameter"
  end

  @app.config[:allocation_mode] = mode
  @app.config[:total_threads] = threads
end

#auto_load(pattern) ⇒ Object

Auto-load controllers from file pattern

Examples:

auto_load 'app/controllers/**/*_controller.rb'

Parameters:

  • pattern (String)

    Glob pattern for controller files



228
229
230
# File 'lib/takagi/application.rb', line 228

def auto_load(pattern)
  @app.config[:auto_load_patterns] << pattern
end

#load_controllers(*controllers) ⇒ Object

Load specific controller classes

Examples:

load_controllers TelemetryController, ConfigController

Parameters:

  • controllers (Array<Class>)

    Controller classes to load



218
219
220
# File 'lib/takagi/application.rb', line 218

def load_controllers(*controllers)
  @app.config[:controllers].concat(controllers)
end