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(value = nil, &block) ⇒ Object
Defines the access required for controller methods which do not define their own access.
-
#action(name) { ... } ⇒ Moonrope::Action
Defines a new action within the controller.
-
#before(*actions) { ... } ⇒ Moonrope::BeforeAction
Defines a new before action within the controller.
-
#helper(name, options = {}) { ... } ⇒ Object
Defines a new helper for this controller.
-
#initialize(controller) ⇒ ControllerDSL
constructor
Initialize a new ControllerDSL.
Constructor Details
#initialize(controller) ⇒ ControllerDSL
Initialize a new ControllerDSL
10 11 12 |
# File 'lib/moonrope/dsl/controller_dsl.rb', line 10 def initialize(controller) @controller = controller end |
Instance Attribute Details
#controller ⇒ Moonrope::Controller (readonly)
Returns the associated controller.
15 16 17 |
# File 'lib/moonrope/dsl/controller_dsl.rb', line 15 def controller @controller end |
Instance Method Details
#access(value = nil, &block) ⇒ Object
Defines the access required for controller methods which do not define their own access.
50 51 52 |
# File 'lib/moonrope/dsl/controller_dsl.rb', line 50 def access(value = nil, &block) @controller.access = block_given? ? block : value end |
#action(name) { ... } ⇒ Moonrope::Action
Defines a new action within the controller.
24 25 26 27 28 29 |
# File 'lib/moonrope/dsl/controller_dsl.rb', line 24 def action(name, &block) action = Moonrope::Action.new(@controller, name) action.dsl.instance_eval(&block) if block_given? @controller.actions[name] = action action end |
#before(*actions) { ... } ⇒ Moonrope::BeforeAction
Defines a new before action within the controller.
38 39 40 41 42 43 44 |
# File 'lib/moonrope/dsl/controller_dsl.rb', line 38 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 |
#helper(name, options = {}) { ... } ⇒ Object
Defines a new helper for this controller.
60 61 62 63 64 65 66 |
# File 'lib/moonrope/dsl/controller_dsl.rb', line 60 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 |