Module: Utopia::Controller::Actions::ClassMethods
- Defined in:
- lib/utopia/controller/actions.rb
Overview
Exposed to the controller class.
Class Method Summary collapse
Instance Method Summary collapse
-
#actions ⇒ Object
-
#dispatch(controller, request, path) ⇒ Object
-
#on(first, *path, **options, &block) ⇒ Object
-
#otherwise(&block) ⇒ Object
Class Method Details
.extended(klass) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/utopia/controller/actions.rb', line 126 def self.extended(klass) klass.instance_eval do @actions = nil @otherwise = nil end end |
Instance Method Details
#actions ⇒ Object
133 134 135 |
# File 'lib/utopia/controller/actions.rb', line 133 def actions @actions ||= Action.new end |
#dispatch(controller, request, path) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/utopia/controller/actions.rb', line 149 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
137 138 139 140 141 142 143 |
# File 'lib/utopia/controller/actions.rb', line 137 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
145 146 147 |
# File 'lib/utopia/controller/actions.rb', line 145 def otherwise(&block) @otherwise = block end |