Class: TShield::Counter
- Inherits:
-
Object
- Object
- TShield::Counter
- Defined in:
- lib/tshield/counter.rb
Overview
Increment counter for sessions requests
Instance Method Summary collapse
- #add(callid, method) ⇒ Object
- #current(callid, method) ⇒ Object
-
#initialize ⇒ Counter
constructor
A new instance of Counter.
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Counter
Returns a new instance of Counter.
6 7 8 |
# File 'lib/tshield/counter.rb', line 6 def initialize @requests = {} end |
Instance Method Details
#add(callid, method) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/tshield/counter.rb', line 10 def add(callid, method) requests_to_callid = @requests.fetch(callid, {}) requests_to_method = requests_to_callid.fetch(method, 0) requests_to_callid[method] = requests_to_method + 1 @requests[callid] = requests_to_callid end |
#current(callid, method) ⇒ Object
18 19 20 |
# File 'lib/tshield/counter.rb', line 18 def current(callid, method) @requests.fetch(callid, {}).fetch(method, 0) end |
#to_json(options = {}) ⇒ Object
22 23 24 |
# File 'lib/tshield/counter.rb', line 22 def to_json( = {}) @requests.to_json() end |