Class: Rack::IfProcessing
- Inherits:
-
Object
- Object
- Rack::IfProcessing
- Defined in:
- lib/if.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #call(rack_environment) ⇒ Object
- #host ⇒ Object
- #http_accept ⇒ Object
- #http_accept_encoding ⇒ Object
-
#initialize(app, options = {}, all_or_any = :all, &block) ⇒ IfProcessing
constructor
A new instance of IfProcessing.
- #method ⇒ Object
-
#path ⇒ Object
shortcuts.
- #port ⇒ Object
- #query_string ⇒ Object
- #stack ⇒ Object
- #use(middleware, *args, &block) ⇒ Object
- #user_agent ⇒ Object
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, ={}, all_or_any = :all, &block) @methodology = all_or_any @options = @app = app @middleware = [] @block = block end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
3 4 5 |
# File 'lib/if.rb', line 3 def app @app end |
#env ⇒ Object (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 |
#host ⇒ Object
18 |
# File 'lib/if.rb', line 18 def host ; env["HTTP_HOST"] ; end |
#http_accept ⇒ Object
21 |
# File 'lib/if.rb', line 21 def http_accept ; env["HTTP_ACCEPT"] ; end |
#http_accept_encoding ⇒ Object
22 |
# File 'lib/if.rb', line 22 def http_accept_encoding ; env["HTTP_ACCEPT_ENCODING"] ; end |
#method ⇒ Object
16 |
# File 'lib/if.rb', line 16 def method ; env["REQUEST_METHOD"] ; end |
#path ⇒ Object
shortcuts
15 |
# File 'lib/if.rb', line 15 def path ; env["PATH_INFO"] ; end |
#port ⇒ Object
19 |
# File 'lib/if.rb', line 19 def port ; env["SERVER_PORT"] ; end |
#query_string ⇒ Object
20 |
# File 'lib/if.rb', line 20 def query_string ; env["QUERY_STRING"] ; end |
#stack ⇒ Object
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_agent ⇒ Object
17 |
# File 'lib/if.rb', line 17 def user_agent ; env["HTTP_USER_AGENT"] ; end |