Class: Rack::Counter
- Inherits:
-
Object
- Object
- Rack::Counter
- Defined in:
- lib/rack_counter.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Counter
constructor
A new instance of Counter.
Constructor Details
#initialize(app, options = {}) ⇒ Counter
Returns a new instance of Counter.
8 9 10 11 12 13 |
# File 'lib/rack_counter.rb', line 8 def initialize(app, ={}) @app = app @options = reset_stats! unless initialized? end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
6 7 8 |
# File 'lib/rack_counter.rb', line 6 def app @app end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/rack_counter.rb', line 6 def @options end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/rack_counter.rb', line 15 def call(env) case env['PATH_INFO'] when '/_stats.json' then [200, {}, [stats.to_json]] when '/_stats/reset' then reset_stats! else record_hit!; app.call(env) end end |