Class: TShield::Counter

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

Instance Method Summary collapse

Constructor Details

#initializeCounter

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(options = {})
  @requests.to_json
end