Class: Lockfile::SleepCycle
- Inherits:
-
Array
- Object
- Array
- Lockfile::SleepCycle
- Defined in:
- lib/scout/open/lock/lockfile.rb
Instance Attribute Summary collapse
-
#inc ⇒ Object
readonly
Returns the value of attribute inc.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Instance Method Summary collapse
-
#initialize(min, max, inc) ⇒ SleepCycle
constructor
A new instance of SleepCycle.
- #next ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(min, max, inc) ⇒ SleepCycle
Returns a new instance of SleepCycle.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/scout/open/lock/lockfile.rb', line 36 def initialize(min, max, inc) @min, @max, @inc = Float(min), Float(max), Float(inc) @range = @max - @min raise RangeError, "max(#{ @max }) <= min(#{ @min })" if @max <= @min raise RangeError, "inc(#{ @inc }) > range(#{ @range })" if @inc > @range raise RangeError, "inc(#{ @inc }) <= 0" if @inc <= 0 raise RangeError, "range(#{ @range }) <= 0" if @range <= 0 s = @min push(s) and s += @inc while(s <= @max) self[-1] = @max if self[-1] < @max reset end |
Instance Attribute Details
#inc ⇒ Object (readonly)
Returns the value of attribute inc.
34 35 36 |
# File 'lib/scout/open/lock/lockfile.rb', line 34 def inc @inc end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
32 33 34 |
# File 'lib/scout/open/lock/lockfile.rb', line 32 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
31 32 33 |
# File 'lib/scout/open/lock/lockfile.rb', line 31 def min @min end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
33 34 35 |
# File 'lib/scout/open/lock/lockfile.rb', line 33 def range @range end |
Instance Method Details
#next ⇒ Object
49 50 51 52 53 |
# File 'lib/scout/open/lock/lockfile.rb', line 49 def next ret = self[@idx] @idx = ((@idx + 1) % self.size) ret end |
#reset ⇒ Object
55 56 57 |
# File 'lib/scout/open/lock/lockfile.rb', line 55 def reset @idx = 0 end |