class Moonrope::DSL::ControllerDSL

Attributes

controller[R]

@return [Moonrope::Controller] the associated controller

Public Class Methods

new(controller) click to toggle source

Initialize a new ControllerDSL

@param controller [Moonrope::Controller]

# File lib/moonrope/dsl/controller_dsl.rb, line 13
def initialize(controller)
  @controller = controller
end

Public Instance Methods

access_rule(name) click to toggle source

Set the name of the access rule to use for all actions in this controller

@param name [Symbol]

# File lib/moonrope/dsl/controller_dsl.rb, line 73
def access_rule(name)
  if name.is_a?(Hash)
    authenticator name.first[0]
    access_rule name.first[1]
  else
    @controller.access_rule = name
  end
end
action(name, &block) click to toggle source

Defines a new action within the controller.

@param name [Symbol] @yield instance evals the block within the ActionDSL @return [Moonrope::Action] the new action instance

# File lib/moonrope/dsl/controller_dsl.rb, line 52
def action(name, &block)
  action = Moonrope::Action.new(@controller, name)
  action.dsl.instance_eval(&block) if block_given?
  @controller.actions[name] = action
  action
end
authenticator(name) click to toggle source

Set the name of the authenticator to use for all actions in this controller

@param name [Symbol]

# File lib/moonrope/dsl/controller_dsl.rb, line 64
def authenticator(name)
  @controller.authenticator = name
end
before(*actions, &block) click to toggle source

Defines a new before action within the controller.

@param actions [Symbol] the names of the actions to apply to (none for all) @yield stores the block as the block to be executed @return [Moonrope::BeforeAction]

# File lib/moonrope/dsl/controller_dsl.rb, line 89
def before(*actions, &block)
  before_action = Moonrope::BeforeAction.new(@controller)
  before_action.block = block
  before_action.actions = actions
  @controller.befores << before_action
  before_action
end
description(description) click to toggle source

Set the description for the controller

@param description [String]

# File lib/moonrope/dsl/controller_dsl.rb, line 41
def description(description)
  @controller.description = description
end
friendly_name(string) click to toggle source

Set the friendly name for the controller

@param name [String]

# File lib/moonrope/dsl/controller_dsl.rb, line 32
def friendly_name(string)
  @controller.friendly_name = string
end
helper(name, options = {}, &block) click to toggle source

Defines a new helper for this controller.

@param name [Symbol] the name of the helper @yield stores the block to execute for the helper

# File lib/moonrope/dsl/controller_dsl.rb, line 103
def helper(name, options = {}, &block)
  if @controller.base.helper(name, @controller)
    raise Moonrope::Errors::HelperAlreadyDefined, "Helper has already been defined with name `#{name}`"
  end
  @controller.base.helpers << Moonrope::Helper.new(name, @controller, options, &block)
end
no_doc!() click to toggle source

Stop this controller frmo being documented

# File lib/moonrope/dsl/controller_dsl.rb, line 23
def no_doc!
  @controller.doc = false
end
shared_action(name, &block) click to toggle source

Define a shared action which can be used by any action

@param name the name of the shared action

# File lib/moonrope/dsl/controller_dsl.rb, line 115
def shared_action(name, &block)
  @controller.shared_actions[name] = block
end