Method: Moonrope::DSL::BaseDSL#controller

Defined in:
lib/moonrope/dsl/base_dsl.rb

#controller(name) { ... } ⇒ Object

Define a new controller or append values to an existing controller if it has already been defined.

Parameters:

  • name (Symbol)

    the name of the controller

Yields:

  • instance evals the block within the ControllerDSL



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/moonrope/dsl/base_dsl.rb', line 42

def controller(name, &block)
  existing = @base.controllers.select { |a| a.name == name }.first
  if existing
    controller = existing
  else
    controller = Moonrope::Controller.new(@base, name)
    @base.controllers << controller
  end
  controller.dsl.instance_eval(&block) if block_given?
  controller
end