Class: Offroad::GroupState

Inherits:
ActiveRecord::Base show all
Defined in:
lib/app/models/offroad/group_state.rb

Constant Summary

Constants included from ModelExtensions

ModelExtensions::OFFROAD_GROUP_MODES, ModelExtensions::OFFROAD_VALID_MODES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModelExtensions

#acts_as_offroadable, #acts_as_offroadable?, #offroad_global_data?, #offroad_group_base?, #offroad_group_data?, #offroad_model_state, #safe_to_load_from_cargo_stream?

Class Method Details

.note_group_destroyed(group) ⇒ Object



74
75
76
77
# File 'lib/app/models/offroad/group_state.rb', line 74

def self.note_group_destroyed(group)
  rec = find_by_app_group_id(group.id)
  rec.destroy
end

.safe_to_load_from_cargo_stream?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/app/models/offroad/group_state.rb', line 70

def self.safe_to_load_from_cargo_stream?
  true
end

Instance Method Details

#app_groupObject



13
14
15
# File 'lib/app/models/offroad/group_state.rb', line 13

def app_group
  Offroad::group_base_model.find_by_id(app_group_id)
end

#before_createObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/app/models/offroad/group_state.rb', line 23

def before_create
  if Offroad::app_offline?
    # FIXME : Fill in last_installation_at, launcher_version, app_version, etc
    self.operating_system ||= RUBY_PLATFORM
  end
  
  self.confirmed_group_data_version ||= 1
  
  # When first setting a group offline at online app, assume it will start out with at least current global data.
  # It should, since that's the earliest version that could be loaded into the initial down mirror file.
  self.confirmed_global_data_version ||= Offroad::app_online? ? SystemState::current_mirror_version : 1
end

#update_from_remote_group_state!(remote_gs) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/app/models/offroad/group_state.rb', line 36

def update_from_remote_group_state!(remote_gs)
  versioning_columns = [
    'confirmed_global_data_version',
    'confirmed_group_data_version'
  ]
  
  online_owned_columns = [
    'last_installer_downloaded_at',
    'last_down_mirror_created_at',
    'last_up_mirror_loaded_at'
  ]
  
  offline_owned_columns = [
    'last_installation_at',
    'last_down_mirror_loaded_at',
    'last_up_mirror_created_at',
    'launcher_version',
    'app_version',
    'operating_system'
  ]
  
  # Copy in values from columns owned by the remote environment that created remote_gs
  (Offroad::app_offline? ? online_owned_columns : offline_owned_columns).each do |col|
    self.send("#{col}=", remote_gs.send(col))
  end
  
  # If the remote side says they have a newer version of something than we currently think they have, update
  versioning_columns.each do |col|
    self.send("#{col}=", [self.send(col), remote_gs.send(col)].max)
  end
  
  save!
end

#validateObject



9
10
11
# File 'lib/app/models/offroad/group_state.rb', line 9

def validate
  errors.add_to_base "Cannot find associated app group record" unless app_group
end