Class: CompositionEngine::Middleware
- Inherits:
-
Object
- Object
- CompositionEngine::Middleware
- Defined in:
- lib/composition_engine.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#env ⇒ Object
Returns the value of attribute env.
Instance Method Summary collapse
- #call(_env) ⇒ Object
- #call_override ⇒ Object
-
#initialize(_app) ⇒ Middleware
constructor
A new instance of Middleware.
- #scoped_path ⇒ Object
Constructor Details
#initialize(_app) ⇒ Middleware
Returns a new instance of Middleware.
27 28 29 |
# File 'lib/composition_engine.rb', line 27 def initialize(_app) self.app = _app end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
25 26 27 |
# File 'lib/composition_engine.rb', line 25 def app @app end |
#env ⇒ Object
Returns the value of attribute env.
25 26 27 |
# File 'lib/composition_engine.rb', line 25 def env @env end |
Instance Method Details
#call(_env) ⇒ Object
31 32 33 34 |
# File 'lib/composition_engine.rb', line 31 def call(_env) self.env = _env call_override || app.call(_env) end |
#call_override ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/composition_engine.rb', line 36 def call_override case scoped_path when false LoginHandler.force_login(env) #This returns false and defaults control to the next middleware if they're already logged in when '/inspect' [200,{'Content-Type' => 'text/plain'},[self.env.keys.map{|k| "#{k.inspect}: #{self.env[k].inspect}"}.join("\n")]] when /^#{LoginHandler.resource_path}/ LoginHandler.handle(env) else [404,{'ContentType' => 'text/plain'},['Not Found']] end end |
#scoped_path ⇒ Object
49 50 51 52 53 54 |
# File 'lib/composition_engine.rb', line 49 def scoped_path return false if !(env['PATH_INFO'] =~ /^#{PATH_PREFIX}(\/.*)?$/) return '/' if $1.nil? return $1 end |