Module: Hobbit::Filter

Defined in:
lib/hobbit/filter.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(othermod) ⇒ Object



50
51
52
# File 'lib/hobbit/filter.rb', line 50

def self.included(othermod)
  othermod.extend ClassMethods
end

Instance Method Details

#_call(env) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hobbit/filter.rb', line 27

def _call(env)
  env['PATH_INFO'] = '/' if env['PATH_INFO'].empty?
  @env = env
  @request = Rack::Request.new(@env)
  @response = Hobbit::Response.new
  catch :halt do
    filter :before
    unless @response.status == 302
      # we have to do this because `super` will override @response and @request
      prev_response = @response
      current_response = super
      @response = Hobbit::Response.new current_response[2], current_response[0], current_response[1].merge!(prev_response.headers)
      filter :after unless @halted
    end
    @response.finish
  end
end

#halt(response) ⇒ Object



45
46
47
48
# File 'lib/hobbit/filter.rb', line 45

def halt(response)
  @halted = true
  super
end