Class: Moonrope::DSL::ControllerDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/moonrope/dsl/controller_dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ ControllerDSL

Initialize a new ControllerDSL

Parameters:



13
14
15
# File 'lib/moonrope/dsl/controller_dsl.rb', line 13

def initialize(controller)
  @controller = controller
end

Instance Attribute Details

#controllerMoonrope::Controller (readonly)

Returns the associated controller.

Returns:



18
19
20
# File 'lib/moonrope/dsl/controller_dsl.rb', line 18

def controller
  @controller
end

Instance Method Details

#access_rule(name) ⇒ Object

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

Parameters:

  • name (Symbol)


73
74
75
76
77
78
79
80
# 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) { ... } ⇒ Moonrope::Action

Defines a new action within the controller.

Parameters:

  • name (Symbol)

Yields:

  • instance evals the block within the ActionDSL

Returns:



52
53
54
55
56
57
# 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) ⇒ Object

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

Parameters:

  • name (Symbol)


64
65
66
# File 'lib/moonrope/dsl/controller_dsl.rb', line 64

def authenticator(name)
  @controller.authenticator = name
end

#before(*actions) { ... } ⇒ Moonrope::BeforeAction

Defines a new before action within the controller.

Parameters:

  • actions (Symbol)

    the names of the actions to apply to (none for all)

Yields:

  • stores the block as the block to be executed

Returns:



89
90
91
92
93
94
95
# 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) ⇒ Object

Set the description for the controller

Parameters:

  • description (String)


41
42
43
# File 'lib/moonrope/dsl/controller_dsl.rb', line 41

def description(description)
  @controller.description = description
end

#friendly_name(string) ⇒ Object

Set the friendly name for the controller

Parameters:

  • name (String)


32
33
34
# File 'lib/moonrope/dsl/controller_dsl.rb', line 32

def friendly_name(string)
  @controller.friendly_name = string
end

#helper(name, options = {}) { ... } ⇒ Object

Defines a new helper for this controller.

Parameters:

  • name (Symbol)

    the name of the helper

Yields:

  • stores the block to execute for the helper



103
104
105
106
107
108
# 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!Object

Stop this controller frmo being documented



23
24
25
# File 'lib/moonrope/dsl/controller_dsl.rb', line 23

def no_doc!
  @controller.doc = false
end

#shared_action(name, &block) ⇒ Object

Define a shared action which can be used by any action

Parameters:

  • name (Symbol)

    the name of the shared action



115
116
117
# File 'lib/moonrope/dsl/controller_dsl.rb', line 115

def shared_action(name, &block)
  @controller.shared_actions[name] = block
end