class CompositionEngine::Middleware

Attributes

app[RW]
env[RW]

Public Class Methods

new(_app) click to toggle source
# File lib/composition_engine.rb, line 27
def initialize(_app)
  self.app = _app
end

Public Instance Methods

call(_env) click to toggle source
# File lib/composition_engine.rb, line 31
def call(_env)
  self.env = _env
  call_override || app.call(_env)
end
call_override() click to toggle source
# 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() click to toggle source
# 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