Sha256: 13a87608e05668dcf795f0d616d885f6f119a3276df24f9f0149e16c129e020d
Contents?: true
Size: 1009 Bytes
Versions: 12
Compression:
Stored size: 1009 Bytes
Contents
module God module Conditions class Tries < PollCondition attr_accessor :times, :within def prepare @timeline = Timeline.new(self.times) end def reset @timeline.clear end def valid? valid = true valid &= complain("Attribute 'times' must be specified", self) if self.times.nil? valid end def test @timeline << Time.now concensus = (@timeline.size == self.times) duration = self.within.nil? || (@timeline.last - @timeline.first) < self.within if within history = "[#{@timeline.size}/#{self.times} within #{(@timeline.last - @timeline.first).to_i}s]" else history = "[#{@timeline.size}/#{self.times}]" end if concensus && duration self.info = "tries exceeded #{history}" return true else self.info = "tries within bounds #{history}" return false end end end end end
Version data entries
12 entries across 12 versions & 3 rubygems