Module: PatronusFati::DataModels::CommonState

Included in:
AccessPoint, Client, Connection, Ssid
Defined in:
lib/patronus_fati/data_models/common_state.rb

Defined Under Namespace

Modules: KlassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ void



18
19
20
21
22
23
# 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

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/patronus_fati/data_models/common_state.rb', line 25

def active?
  presence.visible_since?(self.class.current_expiration_threshold)
end

#data_dirty?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/patronus_fati/data_models/common_state.rb', line 29

def data_dirty?
  sync_flag?(:dirtyAttributes) || sync_flag?(:dirtyChildren)
end

#diagnostic_datavoid



33
34
35
36
37
38
39
40
# 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?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/patronus_fati/data_models/common_state.rb', line 42

def dirty?
  new? || data_dirty? || status_dirty?
end

#initialize(*_args) ⇒ void



46
47
48
49
# File 'lib/patronus_fati/data_models/common_state.rb', line 46

def initialize(*_args)
  self.presence = Presence.new
  self.sync_status = 0
end

#mark_syncedvoid



51
52
53
54
# 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?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/patronus_fati/data_models/common_state.rb', line 56

def new?
  !(sync_flag?(:syncedOnline) || sync_flag?(:syncedOffline))
end

#set_sync_flag(flag) ⇒ void



60
61
62
# 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?Boolean

Returns:

  • (Boolean)


64
65
66
67
# 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) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/patronus_fati/data_models/common_state.rb', line 69

def sync_flag?(flag)
  (sync_status & SYNC_FLAGS[flag]) > 0
end