Class: Takagi::Controller::ConfigContext

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

Overview

Configuration DSL context

Instance Method Summary collapse

Constructor Details

#initialize(controller_class) ⇒ ConfigContext

Returns a new instance of ConfigContext.

Parameters:



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

This method returns an undefined value.

Set mount path

Parameters:

  • path (String)
  • nested_from: (singleton(Controller), nil) (defaults to: nil)


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

This method returns an undefined value.

Nest child controllers

Parameters:



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

This method returns an undefined value.

Set load profile

Parameters:

  • name (Symbol)


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

This method returns an undefined value.

Set configuration value

Parameters:

  • key (Symbol)
  • value (Object)


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