Class: Kawaii::Base

Inherits:
Object
  • Object
show all
Extended by:
RoutingMethods, ServerMethods
Defined in:
lib/kawaii/base.rb

Overview

Base class for all Kawaii applications. Inherit from this class to create a modular application.

Examples:

my_app.rb

require 'kawaii'
class MyApp < Kawaii::Base
  get '/' do
    'Hello, world'
  end
end

config.ru

require 'my_app.rb'
run MyApp

Direct Known Subclasses

SingletonApp

Constant Summary

Constants included from ServerMethods

ServerMethods::WEBRICK

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from RoutingMethods

add_http_method, context, delete, get, head, link, match, methods_used, options, patch, post, put, route, trace, unlink

Methods included from ServerMethods

running?, start!, stop!

Constructor Details

- (Base) initialize(downstream_app = nil)

Returns a new instance of Base



17
18
19
# File 'lib/kawaii/base.rb', line 17

def initialize(downstream_app = nil)
  @downstream_app = downstream_app
end

Class Method Details

+ (Object) call(env)

Make it runnable via `run MyApp`.



32
33
34
35
# File 'lib/kawaii/base.rb', line 32

def call(env)
  @app ||= new
  @app.call(env)
end

Instance Method Details

- (Object) call(env)

Instances of classes derived from [Kawaii::Base] are Rack applications.



22
23
24
25
# File 'lib/kawaii/base.rb', line 22

def call(env)
  matching = self.class.match(env) || not_found
  matching.call(env)
end