Module: Utopia::Controller::Actions::ClassMethods
- Defined in:
- lib/utopia/controller/actions.rb
Overview
Exposed to the controller class.
Class Method Summary collapse
-
.extended(klass) ⇒ Object
Initialize class-level state when this module is extended.
Instance Method Summary collapse
-
#actions ⇒ Object
Return the root of the action lookup tree.
-
#dispatch(controller, request, path) ⇒ Object
Dispatch the request to the first matching action.
-
#on(first, *path, **options, &block) ⇒ Object
Define an action for the given request path.
-
#otherwise(&block) ⇒ Object
Define the fallback action.
Class Method Details
.extended(klass) ⇒ Object
Initialize class-level state when this module is extended.
143 144 145 146 147 148 |
# File 'lib/utopia/controller/actions.rb', line 143 def self.extended(klass) klass.instance_eval do @actions = nil @otherwise = nil end end |
Instance Method Details
#actions ⇒ Object
Return the root of the action lookup tree.
152 153 154 |
# File 'lib/utopia/controller/actions.rb', line 152 def actions @actions ||= Action.new end |
#dispatch(controller, request, path) ⇒ Object
Dispatch the request to the first matching action.
182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/utopia/controller/actions.rb', line 182 def dispatch(controller, request, path) if @actions matched = @actions.apply(path.components) do |action| controller.instance_exec(request, path, &action.callback) end end if @otherwise and !matched controller.instance_exec(request, path, &@otherwise) end end |
#on(first, *path, **options, &block) ⇒ Object
Define an action for the given request path.
162 163 164 165 166 167 168 |
# File 'lib/utopia/controller/actions.rb', line 162 def on(first, *path, **, &block) if first.is_a? Symbol first = ["**", first.to_s] end actions.define(Path.split(first) + path, **, &block) end |
#otherwise(&block) ⇒ Object
Define the fallback action.
173 174 175 |
# File 'lib/utopia/controller/actions.rb', line 173 def otherwise(&block) @otherwise = block end |