module PatronusFati::DataModels::CommonState

Public Class Methods

included(klass) click to toggle source
# File lib/patronus_fati/data_models/common_state.rb, line 18
def self.included(klass)
  klass.extend(KlassMethods)
  klass.class_eval do
    attr_accessor :presence, :sync_status
  end
end
new(*_args) click to toggle source
# File lib/patronus_fati/data_models/common_state.rb, line 46
def initialize(*_args)
  self.presence = Presence.new
  self.sync_status = 0
end

Public Instance Methods

active?() click to toggle source
# File lib/patronus_fati/data_models/common_state.rb, line 25
def active?
  presence.visible_since?(self.class.current_expiration_threshold)
end
data_dirty?() click to toggle source
# File lib/patronus_fati/data_models/common_state.rb, line 29
def data_dirty?
  sync_flag?(:dirtyAttributes) || sync_flag?(:dirtyChildren)
end
diagnostic_data() click to toggle source
# File lib/patronus_fati/data_models/common_state.rb, line 33
def diagnostic_data
  {
    sync_status: sync_status,
    presence_bit_offset: presence.current_bit_offset,
    current_presence: presence.current_presence.bits,
    last_presence: presence.last_presence.bits
  }
end
dirty?() click to toggle source
# File lib/patronus_fati/data_models/common_state.rb, line 42
def dirty?
  new? || data_dirty? || status_dirty?
end
mark_synced() click to toggle source
# File lib/patronus_fati/data_models/common_state.rb, line 51
def mark_synced
  flag = active? ? :syncedOnline : :syncedOffline
  self.sync_status = SYNC_FLAGS[flag]
end
new?() click to toggle source
# File lib/patronus_fati/data_models/common_state.rb, line 56
def new?
  !(sync_flag?(:syncedOnline) || sync_flag?(:syncedOffline))
end
set_sync_flag(flag) click to toggle source
# File lib/patronus_fati/data_models/common_state.rb, line 60
def set_sync_flag(flag)
  self.sync_status |= SYNC_FLAGS[flag]
end
status_dirty?() click to toggle source
# File lib/patronus_fati/data_models/common_state.rb, line 64
def status_dirty?
  sync_flag?(:syncedOnline) && !active? ||
    sync_flag?(:syncedOffline) && active?
end
sync_flag?(flag) click to toggle source
# File lib/patronus_fati/data_models/common_state.rb, line 69
def sync_flag?(flag)
  (sync_status & SYNC_FLAGS[flag]) > 0
end