Class: Takagi::Controller::ConfigContext

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

Overview

Configuration DSL context

Provides methods for configuring controllers within configure blocks.

Instance Method Summary collapse

Constructor Details

#initialize(controller_class) ⇒ ConfigContext

Returns a new instance of ConfigContext.



244
245
246
# File 'lib/takagi/controller.rb', line 244

def initialize(controller_class)
  @controller = controller_class
end

Instance Method Details

#mount(path, nested_from: nil) ⇒ Object

Set the mount path for this controller

Examples:

mount '/telemetry'
mount '/devices', nested_from: ApiController

Parameters:

  • path (String)

    The mount path (e.g., ‘/telemetry’)

  • nested_from (Class, nil) (defaults to: nil)

    Optional parent controller



256
257
258
259
# File 'lib/takagi/controller.rb', line 256

def mount(path, nested_from: nil)
  @controller.config[:mount_path] = path
  @controller.config[:nested_from] = nested_from if nested_from
end

#nest(*controllers) ⇒ Object

Nest child controllers under this controller

Examples:

nest SensorDataController, MetricsController

Parameters:

  • controllers (Array<Class>)

    Controller classes to nest



267
268
269
270
271
272
273
274
# File 'lib/takagi/controller.rb', line 267

def nest(*controllers)
  @controller.config[:nested_controllers].concat(controllers)

  # Update each nested controller to reference this parent
  controllers.each do |controller|
    controller.config[:nested_from] = @controller
  end
end

#profile(name) ⇒ Object

Set a load profile for this controller

Examples:

profile :high_throughput

Parameters:

  • name (Symbol)

    Profile name



282
283
284
285
286
287
288
289
# File 'lib/takagi/controller.rb', line 282

def profile(name)
  unless Profiles.exists?(name)
    error = Errors::ConfigurationError.invalid_profile(name, Profiles.available)
    raise ArgumentError, error.message
  end

  @controller.config[:profile] = name
end

#set(key, value) ⇒ Object

Set a configuration value

Examples:

set :processes, 16
set :threads, 4

Parameters:

  • key (Symbol)

    Configuration key

  • value (Object)

    Configuration value



314
315
316
# File 'lib/takagi/controller.rb', line 314

def set(key, value)
  @controller.config[key] = value
end

#threads(count) ⇒ Object

Set the number of threads for this controller

Examples:

threads 8

Parameters:

  • count (Integer)

    Number of threads



297
298
299
300
301
302
303
304
# File 'lib/takagi/controller.rb', line 297

def threads(count)
  unless count.is_a?(Integer) && count.positive?
    error = Errors::ValidationError.invalid_thread_count(count)
    raise ArgumentError, error.message
  end

  @controller.config[:threads] = count
end