Class: Tynn
- Inherits:
-
Object
- Object
- Tynn
- Includes:
- Syro::Deck::API
- Defined in:
- lib/tynn/version.rb,
lib/tynn.rb,
lib/tynn/ssl.rb,
lib/tynn/json.rb,
lib/tynn/test.rb,
lib/tynn/hmote.rb,
lib/tynn/render.rb,
lib/tynn/static.rb,
lib/tynn/request.rb,
lib/tynn/session.rb,
lib/tynn/response.rb,
lib/tynn/settings.rb,
lib/tynn/not_found.rb,
lib/tynn/protection.rb,
lib/tynn/all_methods.rb,
lib/tynn/environment.rb,
lib/tynn/secure_headers.rb
Overview
:nodoc: all
Defined Under Namespace
Modules: AllMethods, Environment, HMote, JSON, NotFound, Protection, Render, SecureHeaders, Session, Settings, Static Classes: Request, Response, SSL, Test
Constant Summary collapse
- VERSION =
[ MAJOR_VERSION = 1, MINOR_VERSION = 3, PATCH_VERSION = 0, PRE_VERSION = nil ].compact.join(".")
Class Method Summary collapse
-
.build_app(syro) ⇒ Object
:nodoc:.
-
.call(env) ⇒ Object
:nodoc:.
-
.define(&block) ⇒ Object
Public: Sets the application handler.
-
.middleware ⇒ Object
Internal: Returns middleware stack.
-
.plugin(plugin, *args, &block) ⇒ Object
Public: Loads given
plugin
into the application. -
.reset! ⇒ Object
:nodoc:.
-
.set(option, value) ⇒ Object
Public: Sets an
option
to the givenvalue
. -
.use(middleware, *args, &block) ⇒ Object
Public: Adds given Rack
middleware
to the stack.
Instance Method Summary collapse
-
#default_headers ⇒ Object
:nodoc:.
-
#request_class ⇒ Object
:nodoc:.
-
#response_class ⇒ Object
:nodoc:.
Class Method Details
.build_app(syro) ⇒ Object
:nodoc:
79 80 81 82 83 84 85 |
# File 'lib/tynn.rb', line 79 def self.build_app(syro) # :nodoc: if middleware.empty? @app = syro else @app = middleware.reverse.inject(syro) { |a, m| m.call(a) } end end |
.call(env) ⇒ Object
:nodoc:
75 76 77 |
# File 'lib/tynn.rb', line 75 def self.call(env) # :nodoc: return @app.call(env) end |
.define(&block) ⇒ Object
Public: Sets the application handler.
Examples
class Users < Tynn
end
Users.define do
on(:id) do |id|
get do
res.write("GET /users")
end
post do
res.write("POST /users")
end
end
end
57 58 59 |
# File 'lib/tynn.rb', line 57 def self.define(&block) build_app(Syro.new(self, &block)) end |
.middleware ⇒ Object
Internal: Returns middleware stack.
88 89 90 |
# File 'lib/tynn.rb', line 88 def self.middleware return @middleware ||= [] end |
.plugin(plugin, *args, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tynn.rb', line 21 def self.plugin(plugin, *args, &block) if defined?(plugin::InstanceMethods) self.include(plugin::InstanceMethods) end if defined?(plugin::ClassMethods) self.extend(plugin::ClassMethods) end if plugin.respond_to?(:setup) plugin.setup(self, *args, &block) end end |
.reset! ⇒ Object
:nodoc:
92 93 94 95 |
# File 'lib/tynn.rb', line 92 def self.reset! # :nodoc: @app = nil @middleware = [] end |
.set(option, value) ⇒ Object
110 111 112 |
# File 'lib/tynn.rb', line 110 def self.set(option, value) settings[option] = value end |
.use(middleware, *args, &block) ⇒ Object
71 72 73 |
# File 'lib/tynn.rb', line 71 def self.use(middleware, *args, &block) self.middleware << proc { |app| middleware.new(app, *args, &block) } end |
Instance Method Details
#default_headers ⇒ Object
:nodoc:
116 117 118 |
# File 'lib/tynn.rb', line 116 def default_headers # :nodoc: return Hash[self.class.settings[:default_headers]] end |