Class: Tzispa::Middleware
- Inherits:
-
Object
- Object
- Tzispa::Middleware
- Defined in:
- lib/tzispa/middleware.rb
Instance Attribute Summary collapse
-
#application ⇒ Object
readonly
Returns the value of attribute application.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #builder ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
- #load(middleware) ⇒ Object
- #load_default_stack ⇒ Object
- #use(middleware, *args, &blk) ⇒ Object
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
11 12 13 14 |
# File 'lib/tzispa/middleware.rb', line 11 def initialize(app) @stack = [] @application = app end |
Instance Attribute Details
#application ⇒ Object (readonly)
Returns the value of attribute application.
9 10 11 |
# File 'lib/tzispa/middleware.rb', line 9 def application @application end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
9 10 11 |
# File 'lib/tzispa/middleware.rb', line 9 def stack @stack end |
Instance Method Details
#builder ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/tzispa/middleware.rb', line 16 def builder midw = self @builder ||= ::Rack::Builder.new do #mw.load_default_stack midw.application.load! midw.stack.each { |m, args, block| use midw.load(m), *args, &block } run midw.application.routes.router end end |
#load(middleware) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/tzispa/middleware.rb', line 30 def load(middleware) case middleware when String Object.const_get(middleware) else middleware end end |
#load_default_stack ⇒ Object
39 40 41 42 43 44 |
# File 'lib/tzispa/middleware.rb', line 39 def load_default_stack @default_stack_loaded ||= begin application.load! #use TzispaEnv, app end end |
#use(middleware, *args, &blk) ⇒ Object
26 27 28 |
# File 'lib/tzispa/middleware.rb', line 26 def use(middleware, *args, &blk) @stack.unshift [middleware, args, blk] end |