Class: Kawaii::SingletonApp

Inherits:
Base
  • Object
show all
Defined in:
lib/kawaii/singleton_app.rb

Overview

Class used to implement a standalone Kawaii app generated with top-level route helpers (e.g. monkey-patched onto the `main` object).

This lets you create a .rb file containing just route definitions and run it with `ruby` command.

Examples:

test.rb

require 'kawaii'

get '/' do
  'Hello, world'
end

Running from command line

ruby -r kawaii test.rb
...

Constant Summary

Constants included from ServerMethods

Kawaii::ServerMethods::WEBRICK

Class Method Summary (collapse)

Methods inherited from Base

call, #call, #initialize

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

This class inherits a constructor from Kawaii::Base

Class Method Details

+ (Object) maybe_start!(port)



21
22
23
24
# File 'lib/kawaii/singleton_app.rb', line 21

def maybe_start!(port)
  # Give routes a chance to install and app to initialize.
  at_exit { start!(port) unless $ERROR_INFO } if !running? && run_direct?
end