Class: Rack::IfProcessing

Inherits:
Object
  • Object
show all
Defined in:
lib/if.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}, all_or_any = :all, &block) ⇒ IfProcessing

Returns a new instance of IfProcessing.



5
6
7
8
9
10
11
12
# File 'lib/if.rb', line 5

def initialize(app, options={}, all_or_any = :all, &block)
  @methodology = all_or_any
  @options     = options
  @app         = app
  
  @middleware = []
  @block = block
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



3
4
5
# File 'lib/if.rb', line 3

def app
  @app
end

#envObject (readonly)

Returns the value of attribute env.



3
4
5
# File 'lib/if.rb', line 3

def env
  @env
end

Instance Method Details

#call(rack_environment) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/if.rb', line 24

def call(rack_environment)
  @env = rack_environment
  instance_eval(&@block)
  if @middleware.any?
    stack.call(env)
  else
    app.call(env)
  end
end

#hostObject



18
# File 'lib/if.rb', line 18

def host                 ; env["HTTP_HOST"]            ; end

#http_acceptObject



21
# File 'lib/if.rb', line 21

def http_accept          ; env["HTTP_ACCEPT"]          ; end

#http_accept_encodingObject



22
# File 'lib/if.rb', line 22

def http_accept_encoding ; env["HTTP_ACCEPT_ENCODING"] ; end

#methodObject



16
# File 'lib/if.rb', line 16

def method               ; env["REQUEST_METHOD"]       ; end

#pathObject

shortcuts



15
# File 'lib/if.rb', line 15

def path                 ; env["PATH_INFO"]            ; end

#portObject



19
# File 'lib/if.rb', line 19

def port                 ; env["SERVER_PORT"]          ; end

#query_stringObject



20
# File 'lib/if.rb', line 20

def query_string         ; env["QUERY_STRING"]         ; end

#stackObject



34
35
36
# File 'lib/if.rb', line 34

def stack
  @middleware.reverse.inject(app) { |app, mid| mid.call(app) }
end

#use(middleware, *args, &block) ⇒ Object



38
39
40
# File 'lib/if.rb', line 38

def use(middleware, *args, &block)
  @middleware << lambda { |app| middleware.new(app, *args, &block) }
end

#user_agentObject



17
# File 'lib/if.rb', line 17

def user_agent           ; env["HTTP_USER_AGENT"]      ; end