Class: Takagi::Application::ConfigContext

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

Overview

Configuration DSL context

Instance Method Summary collapse

Constructor Details

#initialize(app_class) ⇒ ConfigContext

Returns a new instance of ConfigContext.

Parameters:



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) ⇒ void

This method returns an undefined value.

Auto-load controllers from file pattern

Parameters:

  • pattern (String)


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

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

#load_controllers(*controllers) ⇒ void

This method returns an undefined value.

Load specific controller classes

Parameters:



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

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