Class: Takagi::Controller::ConfigContext
- Inherits:
-
Object
- Object
- Takagi::Controller::ConfigContext
- Defined in:
- lib/takagi/controller.rb
Overview
Configuration DSL context
Provides methods for configuring controllers within configure blocks.
Instance Method Summary collapse
-
#initialize(controller_class) ⇒ ConfigContext
constructor
A new instance of ConfigContext.
-
#mount(path, nested_from: nil) ⇒ Object
Set the mount path for this controller.
-
#nest(*controllers) ⇒ Object
Nest child controllers under this controller.
-
#profile(name) ⇒ Object
Set a load profile for this controller.
-
#set(key, value) ⇒ Object
Set a configuration value.
-
#threads(count) ⇒ Object
Set the number of threads for this controller.
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
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
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
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. end @controller.config[:profile] = name end |
#set(key, value) ⇒ Object
Set a 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
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. end @controller.config[:threads] = count end |