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
128 129 130 131 132 133 |
# File 'lib/utopia/controller/actions.rb', line 128 def self.extended(klass) klass.instance_eval do @actions = nil @otherwise = nil end end |
Instance Method Details
#actions ⇒ Object
135 136 137 |
# File 'lib/utopia/controller/actions.rb', line 135 def actions @actions ||= Action.new end |
#dispatch(controller, request, path) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/utopia/controller/actions.rb', line 151 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
139 140 141 142 143 144 145 |
# File 'lib/utopia/controller/actions.rb', line 139 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
147 148 149 |
# File 'lib/utopia/controller/actions.rb', line 147 def otherwise(&block) @otherwise = block end |