Class: Takagi::Controller::ConfigContext
- Inherits:
-
Object
- Object
- Takagi::Controller::ConfigContext
- Defined in:
- lib/takagi/controller.rb,
sig/takagi/controller.rbs
Overview
Configuration DSL context
Instance Method Summary collapse
-
#initialize(controller_class) ⇒ ConfigContext
constructor
A new instance of ConfigContext.
-
#mount(path, nested_from: nil) ⇒ void
Set mount path.
-
#nest(*controllers) ⇒ void
Nest child controllers.
-
#profile(name) ⇒ void
Set load profile.
-
#set(key, value) ⇒ void
Set 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) ⇒ void
This method returns an undefined value.
Set mount path
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
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
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) ⇒ void
This method returns an undefined value.
Set 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 |