Class: TShield::Counter
- Inherits:
-
Object
- Object
- TShield::Counter
- Defined in:
- lib/tshield/counter.rb
Instance Method Summary collapse
- #add(path, method) ⇒ Object
- #current(path, method) ⇒ Object
-
#initialize ⇒ Counter
constructor
A new instance of Counter.
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Counter
Returns a new instance of Counter.
4 5 6 |
# File 'lib/tshield/counter.rb', line 4 def initialize @requests = {} end |
Instance Method Details
#add(path, method) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/tshield/counter.rb', line 8 def add(path, method) requests_to_path = @requests.fetch(path, {}) requests_to_method = requests_to_path.fetch(method, 0) requests_to_path[method] = requests_to_method += 1 @requests[path] = requests_to_path end |
#current(path, method) ⇒ Object
16 17 18 |
# File 'lib/tshield/counter.rb', line 16 def current(path, method) @requests.fetch(path, {}).fetch(method, 0) end |
#to_json(options = {}) ⇒ Object
20 21 22 |
# File 'lib/tshield/counter.rb', line 20 def to_json( = {}) @requests.to_json end |