Class: Offroad::SendableRecordState
Constant Summary
ModelExtensions::OFFROAD_GROUP_MODES, ModelExtensions::OFFROAD_VALID_MODES
Class Method Summary
collapse
Instance Method Summary
collapse
#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_record_created_or_updated(record) ⇒ Object
62
63
64
|
# File 'lib/app/models/offroad/sendable_record_state.rb', line 62
def self.note_record_created_or_updated(record)
mark_record_changes(record)
end
|
.note_record_destroyed(record) ⇒ Object
56
57
58
59
60
|
# File 'lib/app/models/offroad/sendable_record_state.rb', line 56
def self.note_record_destroyed(record)
mark_record_changes(record) do |rec|
rec.deleted = true
end
end
|
.safe_to_load_from_cargo_stream? ⇒ Boolean
We put SRS records in mirror files to represent deleted records
52
53
54
|
# File 'lib/app/models/offroad/sendable_record_state.rb', line 52
def self.safe_to_load_from_cargo_stream?
true
end
|
.setup_imported(model, batch) ⇒ Object
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/app/models/offroad/sendable_record_state.rb', line 66
def self.setup_imported(model, batch)
model_state_id = model.offroad_model_state.id
mirror_version = SystemState::current_mirror_version
self.import(
[:model_state_id, :local_record_id, :mirror_version],
batch.map{|r| [model_state_id, r.id, mirror_version]},
:validate => false,
:timestamps => false
)
end
|
Instance Method Details
#app_record ⇒ Object
47
48
49
|
# File 'lib/app/models/offroad/sendable_record_state.rb', line 47
def app_record
model_state.app_model.find(local_record_id)
end
|
#validate ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/app/models/offroad/sendable_record_state.rb', line 9
def validate
unless model_state
errors.add_to_base "Cannot find associated model state"
return
end
rec = nil
unless deleted
begin
rec = app_record
rescue ActiveRecord::RecordNotFound
errors.add_to_base "Cannot find associated app record"
end
end
if rec
if Offroad::app_offline? && app_record.class.offroad_global_data?
errors.add_to_base "Cannot create sendable record state for global data in offline app"
elsif Offroad::app_online? && app_record.class.offroad_group_data?
errors.add_to_base "Cannot create sendable record state for group data in online app"
end
end
end
|