Module: SF6

Defined in:
lib/sf6.rb

Defined Under Namespace

Modules: Breaker, Limiter Classes: Unavailable

Class Method Summary collapse

Class Method Details

.increment(data, attr, timestamp) ⇒ Object



12
13
14
15
# File 'lib/sf6.rb', line 12

def self.increment(data, attr, timestamp)
  data[:timestamps][attr] = timestamp
  data[:counts][attr] += 1
end

.stamp(data, attr, bucket) ⇒ Object



6
7
8
9
10
# File 'lib/sf6.rb', line 6

def self.stamp(data, attr, bucket)
  timestamp = Time.now.to_i / bucket
  data[:counts][attr] = 0 unless data[:timestamps][attr] == timestamp
  timestamp
end

.test(data, attr, value, &blk) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/sf6.rb', line 17

def self.test(data, attr, value, &blk)
  if value == 0 || data[:counts][attr] < value
    yield
  else
    raise(Unavailable, attr)
  end
end