Sha256: d9025414269bf9e8ce0a657b3e75d5acde5bad50f598bb98cf1b40ffcc4f428d

Contents?: true

Size: 1.04 KB

Versions: 69

Compression:

Stored size: 1.04 KB

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

69 entries across 69 versions & 21 rubygems

Version Path
dguettler-god-0.7.13.2 lib/god/conditions/tries.rb
dguettler-god-0.7.13.3 lib/god/conditions/tries.rb
dosire-god-0.7.10 lib/god/conditions/tries.rb
dosire-god-0.7.12 lib/god/conditions/tries.rb
dosire-god-0.7.9 lib/god/conditions/tries.rb
dunedain289-god-0.7.12.1 lib/god/conditions/tries.rb
dustin-god-0.7.7.1 lib/god/conditions/tries.rb
eric-god-0.7.10 lib/god/conditions/tries.rb
eric-god-0.7.11 lib/god/conditions/tries.rb
eric-god-0.7.12 lib/god/conditions/tries.rb
eric-god-0.7.14 lib/god/conditions/tries.rb
eric-god-0.7.7 lib/god/conditions/tries.rb
fotonauts-god-0.7.10 lib/god/conditions/tries.rb
fotonauts-god-0.7.12 lib/god/conditions/tries.rb
gohanlonllc-god-0.7.9 lib/god/conditions/tries.rb
gordoncww-god-0.7.11.1 lib/god/conditions/tries.rb
jreynolds-god-0.7.13 lib/god/conditions/tries.rb
jwilkins-god-0.7.9 lib/god/conditions/tries.rb
mathieuravaux-god-0.7.11 lib/god/conditions/tries.rb
mojombo-god-0.7.10 lib/god/conditions/tries.rb