class Midori::API

This class provides methods to be inherited as route definition.

Constants

METHODS

Constants of supported methods in route definition

Attributes

routes[RW]

@!attribute routes

@return [Hash] merged routes defined in the instance

@!attribute scope_middlewares

@return [Array] global middlewares under the scope
scope_middlewares[RW]

@!attribute routes

@return [Hash] merged routes defined in the instance

@!attribute scope_middlewares

@return [Array] global middlewares under the scope

Public Class Methods

capture(error, &block) click to toggle source

Definitions for global error handler @param [Class] error Error class, must be inherited form StandardError @yield what to do to deal with error @yieldparam [StandardError] e the detailed error @example Basic Usage

capture Midori::InternalError do |e|
  Midori::Response(500, {}, e.backtrace)
end
# File lib/midori/api.rb, line 332
def capture(error, &block)
  Midori::Sandbox.add_rule(error, block)
  nil
end
checkout(path, &block) click to toggle source

Add CHECKOUT method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

checkout '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 200
def checkout(path, &block) end
class_initialize() click to toggle source

Init private variables of class @return [nil] nil

# 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, &block) click to toggle source

Add CONNECT method as a DSL for route definition @param [String] path Accepts as part of path in route definition @yield what to run when route matched @return [nil] nil @example String as router

connect '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 80
def connect(path, &block) end
copy(path, &block) click to toggle source

Add COPY method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

copy '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 109
def copy(path, &block) end
delete(path, &block) click to toggle source

Add DELETE method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

delete '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 30
def delete(path, &block) end
eventsource(path, &block) click to toggle source

Add EVENTSOURCE method as a DSL for route definition @param [String] path Accepts as part of path in route definition @yield what to run when route matched @return [nil] nil @example String as router

eventsource '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 312
def eventsource(path, &block) end
filter(middleware, *args) click to toggle source

Use a middleware in the next route @param [Class] middleware Inherited from Midori::Middleware @return [nil] nil

# File lib/midori/api.rb, line 368
def filter(middleware, *args)
  middleware = middleware.new(*args)
  @temp_middlewares << middleware
  nil
end
get(path, &block) click to toggle source

Add GET method as a DSL for route definition @param [String] path Accepts as part of path in route definition @yield what to run when route matched @return [nil] nil @example String as router

get '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 40
def get(path, &block) end
head(path, &block) click to toggle source

Add HEAD method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

head '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 50
def head(path, &block) end
helper(name, &block) click to toggle source

Helper block for defining methods in APIs @param [Symbol] name name of the method @yield define what to run in CleanRoom

# File lib/midori/api.rb, line 377
def helper(name, &block)
  Midori::CleanRoom.class_exec do
    define_method(name, &block)
  end
end
lock(path, &block) click to toggle source

Add LOCK method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

lock '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 119
def lock(path, &block) end
merge(path, &block) click to toggle source

Add MERGE method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

merge '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 210
def merge(path, &block) end
mkactivity(path, &block) click to toggle source

Add MKACTIVITY method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

mkactivity '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 190
def mkactivity(path, &block) end
mkcol(path, &block) click to toggle source

Add MKCOK method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

mkcol '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 129
def mkcol(path, &block) end
mount(prefix, api) click to toggle source

Mount a route prefix with another API defined @param [String] prefix prefix of the route String @param [Class] api inherited from Midori::API @return [nil] nil

# 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, &block) click to toggle source

Add MOVE method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

move '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 139
def move(path, &block) end
msearch(path, &block) click to toggle source

Add M-SEARCH method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

msearch '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 220
def msearch(path, &block)
  add_route(:'M-SEARCH', path, block)
end
notify(path, &block) click to toggle source

Add NOTIFY method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

notify '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 232
def notify(path, &block) end
options(path, &block) click to toggle source

Add OPTIONS method as a DSL for route definition @param [String] path Accepts as part of path in route definition @return [nil] nil @example String as router

options '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 89
def options(path, &block) end
patch(path, &block) click to toggle source

Add PATCH method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

patch '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 262
def patch(path, &block) end
post(path, &block) click to toggle source

Add POST method as a DSL for route definition @param [String] path Accepts as part of path in route definition @yield what to run when route matched @return [nil] nil @example String as router

post '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 60
def post(path, &block) end
propfind(path, &block) click to toggle source

Add PROPFIND method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

propfind '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 150
def propfind(path, &block) end
proppatch(path, &block) click to toggle source

Add PROPPATCH method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

proppatch '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 160
def proppatch(path, &block) end
purge(path, &block) click to toggle source

Add PURGE method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

purge '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 272
def purge(path, &block) end
put(path, &block) click to toggle source

Add PUT method as a DSL for route definition @param [String] path Accepts as part of path in route definition @yield what to run when route matched @return [nil] nil @example String as router

put '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 70
def put(path, &block) end
report(path, &block) click to toggle source

Add REPORT method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

report '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 180
def report(path, &block) end
subscribe(path, &block) click to toggle source

Add SUBSCRIBE method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

subscribe '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 242
def subscribe(path, &block) end
trace(path, &block) click to toggle source

Add TRACE method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

trace '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 99
def trace(path, &block) end
unlock(path, &block) click to toggle source

Add UNLOCK method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

unlock '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 170
def unlock(path, &block) end
unsubscribe(path, &block) click to toggle source

Add UNSUBSCRIBE method as a DSL for route definition @param [ String ] path Accepts as part of path in route definition @yield what to run when route matched @return [ nil ] nil @example String as router

unsubscribe '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 252
def unsubscribe(path, &block) end
use(middleware, *args) click to toggle source

Use a middleware in the all routes @param [Class] middleware Inherited from Midori::Middleware @return [nil] nil

# File lib/midori/api.rb, line 359
def use(middleware, *args)
  middleware = middleware.new(*args)
  @scope_middlewares << middleware
  nil
end
websocket(path, &block) click to toggle source

Add WEBSOCKET method as a DSL for route definition @param [String] path Accepts as part of path in route definition @yield what to run when route matched @return [nil] nil @example String as router

websocket '/' do
   puts 'Hello World'
end
# File lib/midori/api.rb, line 302
def websocket(path, &block) end

Private Class Methods

add_route(method, path, block) click to toggle source

Implementation of route DSL @param [String] method HTTP method @param [String, Regexp] path path definition @param [Proc] block process to run when route matched @return [nil] nil

# File lib/midori/api.rb, line 342
        def add_route(method, path, block)
  # Argument check
  raise ArgumentError unless path.is_a? String

  # Insert route to routes
  route = Midori::Route.new(method, path, block)
  route.middlewares = @scope_middlewares + @temp_middlewares
  @routes[method] << route

  # Clean up temp middleware
  @temp_middlewares = []
  nil
end
inherited(subclass) click to toggle source
# File lib/midori/api.rb, line 383
        def inherited(subclass)
  subclass.class_initialize
end