Class: Moonrope::DSL::ControllerDSL
- Inherits:
-
Object
- Object
- Moonrope::DSL::ControllerDSL
- Defined in:
- lib/moonrope/dsl/controller_dsl.rb
Instance Attribute Summary collapse
-
#controller ⇒ Moonrope::Controller
readonly
The associated controller.
Instance Method Summary collapse
-
#access_rule(name) ⇒ Object
Set the name of the access rule to use for all actions in this controller.
-
#action(name) { ... } ⇒ Moonrope::Action
Defines a new action within the controller.
-
#authenticator(name) ⇒ Object
Set the name of the authenticator to use for all actions in this controller.
-
#before(*actions) { ... } ⇒ Moonrope::BeforeAction
Defines a new before action within the controller.
-
#description(description) ⇒ Object
Set the description for the controller.
-
#friendly_name(string) ⇒ Object
Set the friendly name for the controller.
-
#helper(name, options = {}) { ... } ⇒ Object
Defines a new helper for this controller.
-
#initialize(controller) ⇒ ControllerDSL
constructor
Initialize a new ControllerDSL.
-
#no_doc! ⇒ Object
Stop this controller frmo being documented.
-
#shared_action(name, &block) ⇒ Object
Define a shared action which can be used by any action.
Constructor Details
#initialize(controller) ⇒ ControllerDSL
Initialize a new ControllerDSL
13 14 15 |
# File 'lib/moonrope/dsl/controller_dsl.rb', line 13 def initialize(controller) @controller = controller end |
Instance Attribute Details
#controller ⇒ Moonrope::Controller (readonly)
Returns the associated controller.
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
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.
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
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.
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
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
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.
103 104 105 106 107 108 |
# File 'lib/moonrope/dsl/controller_dsl.rb', line 103 def helper(name, = {}, &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, , &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
115 116 117 |
# File 'lib/moonrope/dsl/controller_dsl.rb', line 115 def shared_action(name, &block) @controller.shared_actions[name] = block end |