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
- #active? ⇒ Boolean
- #data_dirty? ⇒ Boolean
- #diagnostic_data ⇒ void
- #dirty? ⇒ Boolean
- #initialize(*_args) ⇒ void
- #mark_synced ⇒ void
- #new? ⇒ Boolean
- #set_sync_flag(flag) ⇒ void
- #status_dirty? ⇒ Boolean
- #sync_flag?(flag) ⇒ Boolean
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
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
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_data ⇒ void
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
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_synced ⇒ void
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
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
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
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 |