Class: WorkShaper::OffsetHolder
- Inherits:
-
Object
- Object
- WorkShaper::OffsetHolder
- Defined in:
- lib/work_shaper/offset_holder.rb
Constant Summary collapse
- STATES =
{enqueued: 2, acked: 1, completed: 0}
Instance Attribute Summary collapse
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#partition ⇒ Object
readonly
Returns the value of attribute partition.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #<(other) ⇒ Object
- #<=(other) ⇒ Object
- #<=>(other) ⇒ Object
- #ack! ⇒ Object
- #complete! ⇒ Object
- #completed? ⇒ Boolean
-
#initialize(partition, offset, at: Time.now.to_f) ⇒ OffsetHolder
constructor
A new instance of OffsetHolder.
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(partition, offset, at: Time.now.to_f) ⇒ OffsetHolder
Returns a new instance of OffsetHolder.
6 7 8 9 10 11 12 |
# File 'lib/work_shaper/offset_holder.rb', line 6 def initialize(partition, offset, at: Time.now.to_f) @partition = partition @offset = offset @at = at @state = :enqueued end |
Instance Attribute Details
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
3 4 5 |
# File 'lib/work_shaper/offset_holder.rb', line 3 def offset @offset end |
#partition ⇒ Object (readonly)
Returns the value of attribute partition.
3 4 5 |
# File 'lib/work_shaper/offset_holder.rb', line 3 def partition @partition end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
3 4 5 |
# File 'lib/work_shaper/offset_holder.rb', line 3 def state @state end |
Instance Method Details
#<(other) ⇒ Object
18 19 20 |
# File 'lib/work_shaper/offset_holder.rb', line 18 def <(other) self.<=>(other) == -1 end |
#<=(other) ⇒ Object
14 15 16 |
# File 'lib/work_shaper/offset_holder.rb', line 14 def <=(other) self.<=>(other) <= 0 end |
#<=>(other) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/work_shaper/offset_holder.rb', line 22 def <=>(other) r = offset <=> other.offset if r == 0 r = STATES[state] <=> STATES[other.state] WorkShaper.logger.debug "States: #{r} | #{STATES[state]} #{STATES[other.state]}" end if r == 0 r = @at <=> other.instance_variable_get(:@at) WorkShaper.logger.debug "At: #{r}" end WorkShaper.logger.debug "Final: #{r}" r end |
#ack! ⇒ Object
38 39 40 |
# File 'lib/work_shaper/offset_holder.rb', line 38 def ack! @state = :acked end |
#complete! ⇒ Object
42 43 44 |
# File 'lib/work_shaper/offset_holder.rb', line 42 def complete! @state = :completed end |
#completed? ⇒ Boolean
46 47 48 |
# File 'lib/work_shaper/offset_holder.rb', line 46 def completed? @state == :completed end |
#to_i ⇒ Object
50 51 52 |
# File 'lib/work_shaper/offset_holder.rb', line 50 def to_i offset end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/work_shaper/offset_holder.rb', line 54 def to_s "#{partition}/#{offset}:#{STATES[state]}" end |