Class: Midori::API
- Inherits:
-
Object
- Object
- Midori::API
- Defined in:
- lib/midori/api.rb
Overview
This class provides methods to be inherited as route definition.
Constant Summary collapse
- METHODS =
Constants of supported methods in route definition
%w( delete get head post put connect options trace copy lock mkcol move propfind proppatch unlock report mkactivity checkout merge notify subscribe unsubscribe patch purge websocket eventsource ).freeze
Class Attribute Summary collapse
-
.routes ⇒ Hash
Merged routes defined in the instance.
-
.scope_middlewares ⇒ Array
Global middlewares under the scope.
Class Method Summary collapse
-
.capture(error) {|e| ... } ⇒ Object
Definitions for global error handler.
-
.checkout(path) { ... } ⇒ nil
Add CHECKOUT method as a DSL for route definition.
-
.class_initialize ⇒ nil
Init private variables of class.
-
.connect(path) { ... } ⇒ nil
Add CONNECT method as a DSL for route definition.
-
.copy(path) { ... } ⇒ nil
Add COPY method as a DSL for route definition.
-
.delete(path) { ... } ⇒ nil
Add DELETE method as a DSL for route definition.
-
.eventsource(path) { ... } ⇒ nil
Add EVENTSOURCE method as a DSL for route definition.
-
.filter(middleware, *args) ⇒ nil
Use a middleware in the next route.
-
.get(path) { ... } ⇒ nil
Add GET method as a DSL for route definition.
-
.head(path) { ... } ⇒ nil
Add HEAD method as a DSL for route definition.
-
.helper(name) { ... } ⇒ Object
Helper block for defining methods in APIs.
-
.link(path) { ... } ⇒ nil
Add LINK method as a DSL for route definition.
-
.lock(path) { ... } ⇒ nil
Add LOCK method as a DSL for route definition.
-
.merge(path) { ... } ⇒ nil
Add MERGE method as a DSL for route definition.
-
.mkactivity(path) { ... } ⇒ nil
Add MKACTIVITY method as a DSL for route definition.
-
.mkcol(path) { ... } ⇒ nil
Add MKCOK method as a DSL for route definition.
-
.mount(prefix, api) ⇒ nil
Mount a route prefix with another API defined.
-
.move(path) { ... } ⇒ nil
Add MOVE method as a DSL for route definition.
-
.msearch(path) { ... } ⇒ nil
Add M-SEARCH method as a DSL for route definition.
-
.notify(path) { ... } ⇒ nil
Add NOTIFY method as a DSL for route definition.
-
.options(path, &block) ⇒ nil
Add OPTIONS method as a DSL for route definition.
-
.patch(path) { ... } ⇒ nil
Add PATCH method as a DSL for route definition.
-
.post(path) { ... } ⇒ nil
Add POST method as a DSL for route definition.
-
.propfind(path) { ... } ⇒ nil
Add PROPFIND method as a DSL for route definition.
-
.proppatch(path) { ... } ⇒ nil
Add PROPPATCH method as a DSL for route definition.
-
.purge(path) { ... } ⇒ nil
Add PURGE method as a DSL for route definition.
-
.put(path) { ... } ⇒ nil
Add PUT method as a DSL for route definition.
-
.report(path) { ... } ⇒ nil
Add REPORT method as a DSL for route definition.
-
.subscribe(path) { ... } ⇒ nil
Add SUBSCRIBE method as a DSL for route definition.
-
.trace(path) { ... } ⇒ nil
Add TRACE method as a DSL for route definition.
-
.unlink(path) { ... } ⇒ nil
Add UNLINK method as a DSL for route definition.
-
.unlock(path) { ... } ⇒ nil
Add UNLOCK method as a DSL for route definition.
-
.unsubscribe(path) { ... } ⇒ nil
Add UNSUBSCRIBE method as a DSL for route definition.
-
.use(middleware, *args) ⇒ nil
Use a middleware in the all routes.
-
.websocket(path) { ... } ⇒ nil
Add WEBSOCKET method as a DSL for route definition.
Class Attribute Details
.routes ⇒ Hash
Returns merged routes defined in the instance.
9 10 11 |
# File 'lib/midori/api.rb', line 9 def routes @routes end |
.scope_middlewares ⇒ Array
Returns global middlewares under the scope.
9 |
# File 'lib/midori/api.rb', line 9 attr_accessor :routes, :scope_middlewares |
Class Method Details
.capture(error) {|e| ... } ⇒ Object
Definitions for global error handler
332 333 334 335 |
# File 'lib/midori/api.rb', line 332 def capture(error, &block) Midori::Sandbox.add_rule(error, block) nil end |
.checkout(path) { ... } ⇒ nil
Add CHECKOUT method as a DSL for route definition
200 |
# File 'lib/midori/api.rb', line 200 def checkout(path, &block) end |
.class_initialize ⇒ nil
Init private variables of class
13 14 15 16 17 18 19 20 |
# File 'lib/midori/api.rb', line 13 def class_initialize @routes = {} Midori::Const::ROUTE_METHODS.map {|method| @routes[method] = []} @routes[:MOUNT] = [] @scope_middlewares = [] @temp_middlewares = [] nil end |
.connect(path) { ... } ⇒ nil
Add CONNECT method as a DSL for route definition
80 |
# File 'lib/midori/api.rb', line 80 def connect(path, &block) end |
.copy(path) { ... } ⇒ nil
Add COPY method as a DSL for route definition
109 |
# File 'lib/midori/api.rb', line 109 def copy(path, &block) end |
.delete(path) { ... } ⇒ nil
Add DELETE method as a DSL for route definition
30 |
# File 'lib/midori/api.rb', line 30 def delete(path, &block) end |
.eventsource(path) { ... } ⇒ nil
Add EVENTSOURCE method as a DSL for route definition
312 |
# File 'lib/midori/api.rb', line 312 def eventsource(path, &block) end |
.filter(middleware, *args) ⇒ nil
Use a middleware in the next route
368 369 370 371 372 |
# File 'lib/midori/api.rb', line 368 def filter(middleware, *args) middleware = middleware.new(*args) @temp_middlewares << middleware nil end |
.get(path) { ... } ⇒ nil
Add GET method as a DSL for route definition
40 |
# File 'lib/midori/api.rb', line 40 def get(path, &block) end |
.head(path) { ... } ⇒ nil
Add HEAD method as a DSL for route definition
50 |
# File 'lib/midori/api.rb', line 50 def head(path, &block) end |
.helper(name) { ... } ⇒ Object
Helper block for defining methods in APIs
377 378 379 380 381 |
# File 'lib/midori/api.rb', line 377 def helper(name, &block) Midori::CleanRoom.class_exec do define_method(name, &block) end end |
.link(path) { ... } ⇒ nil
Add LINK method as a DSL for route definition
282 |
# File 'lib/midori/api.rb', line 282 def link(path, &block) end |
.lock(path) { ... } ⇒ nil
Add LOCK method as a DSL for route definition
119 |
# File 'lib/midori/api.rb', line 119 def lock(path, &block) end |
.merge(path) { ... } ⇒ nil
Add MERGE method as a DSL for route definition
210 |
# File 'lib/midori/api.rb', line 210 def merge(path, &block) end |
.mkactivity(path) { ... } ⇒ nil
Add MKACTIVITY method as a DSL for route definition
190 |
# File 'lib/midori/api.rb', line 190 def mkactivity(path, &block) end |
.mkcol(path) { ... } ⇒ nil
Add MKCOK method as a DSL for route definition
129 |
# File 'lib/midori/api.rb', line 129 def mkcol(path, &block) end |
.mount(prefix, api) ⇒ nil
Mount a route prefix with another API defined
318 319 320 321 322 |
# File 'lib/midori/api.rb', line 318 def mount(prefix, api) raise ArgumentError if prefix == '/' # Cannot mount route API @routes[:MOUNT] << [prefix, api] nil end |
.move(path) { ... } ⇒ nil
Add MOVE method as a DSL for route definition
139 |
# File 'lib/midori/api.rb', line 139 def move(path, &block) end |
.msearch(path) { ... } ⇒ nil
Add M-SEARCH method as a DSL for route definition
220 221 222 |
# File 'lib/midori/api.rb', line 220 def msearch(path, &block) add_route(:'M-SEARCH', path, block) end |
.notify(path) { ... } ⇒ nil
Add NOTIFY method as a DSL for route definition
232 |
# File 'lib/midori/api.rb', line 232 def notify(path, &block) end |
.options(path, &block) ⇒ nil
Add OPTIONS method as a DSL for route definition
89 |
# File 'lib/midori/api.rb', line 89 def (path, &block) end |
.patch(path) { ... } ⇒ nil
Add PATCH method as a DSL for route definition
262 |
# File 'lib/midori/api.rb', line 262 def patch(path, &block) end |
.post(path) { ... } ⇒ nil
Add POST method as a DSL for route definition
60 |
# File 'lib/midori/api.rb', line 60 def post(path, &block) end |
.propfind(path) { ... } ⇒ nil
Add PROPFIND method as a DSL for route definition
150 |
# File 'lib/midori/api.rb', line 150 def propfind(path, &block) end |
.proppatch(path) { ... } ⇒ nil
Add PROPPATCH method as a DSL for route definition
160 |
# File 'lib/midori/api.rb', line 160 def proppatch(path, &block) end |
.purge(path) { ... } ⇒ nil
Add PURGE method as a DSL for route definition
272 |
# File 'lib/midori/api.rb', line 272 def purge(path, &block) end |
.put(path) { ... } ⇒ nil
Add PUT method as a DSL for route definition
70 |
# File 'lib/midori/api.rb', line 70 def put(path, &block) end |
.report(path) { ... } ⇒ nil
Add REPORT method as a DSL for route definition
180 |
# File 'lib/midori/api.rb', line 180 def report(path, &block) end |
.subscribe(path) { ... } ⇒ nil
Add SUBSCRIBE method as a DSL for route definition
242 |
# File 'lib/midori/api.rb', line 242 def subscribe(path, &block) end |
.trace(path) { ... } ⇒ nil
Add TRACE method as a DSL for route definition
99 |
# File 'lib/midori/api.rb', line 99 def trace(path, &block) end |
.unlink(path) { ... } ⇒ nil
Add UNLINK method as a DSL for route definition
292 |
# File 'lib/midori/api.rb', line 292 def unlink(path, &block) end |
.unlock(path) { ... } ⇒ nil
Add UNLOCK method as a DSL for route definition
170 |
# File 'lib/midori/api.rb', line 170 def unlock(path, &block) end |
.unsubscribe(path) { ... } ⇒ nil
Add UNSUBSCRIBE method as a DSL for route definition
252 |
# File 'lib/midori/api.rb', line 252 def unsubscribe(path, &block) end |
.use(middleware, *args) ⇒ nil
Use a middleware in the all routes
359 360 361 362 363 |
# File 'lib/midori/api.rb', line 359 def use(middleware, *args) middleware = middleware.new(*args) @scope_middlewares << middleware nil end |
.websocket(path) { ... } ⇒ nil
Add WEBSOCKET method as a DSL for route definition
302 |
# File 'lib/midori/api.rb', line 302 def websocket(path, &block) end |