module DeepUnrest::Concerns::MapTempIds

Public Instance Methods

attribute_diff() click to toggle source
# File lib/deep_unrest/concerns/map_temp_ids.rb, line 59
def attribute_diff
  saved_changes.each_with_object({}) do |(attr_name, (_old, val)), diff|
    diff[attr_name] = val
  end
end
map_temp_id() click to toggle source
# File lib/deep_unrest/concerns/map_temp_ids.rb, line 21
def map_temp_id
  temp_id_map = DeepUnrest::ApplicationController.class_variable_get(
    '@@temp_ids'
  )
  return unless temp_id_map && @deep_unrest_temp_id
  temp_id_map[@deep_unrest_context][@deep_unrest_temp_id] = pk
end
pk() click to toggle source
# File lib/deep_unrest/concerns/map_temp_ids.rb, line 17
def pk
  send self.class.primary_key
end
track_changes() click to toggle source

the client needs to know which items were charged so it can keep its local sync in store with the db

# File lib/deep_unrest/concerns/map_temp_ids.rb, line 46
def track_changes
  changed = DeepUnrest::ApplicationController.class_variable_get(
    '@@changed_entities'
  )
  return unless changed && saved_changes?
  changed << {
    klass: self.class,
    id: pk,
    attributes: attribute_diff,
    query_uuid: @deep_unrest_query_uuid
  }
end
track_destruction() click to toggle source

the client needs to know which items were destroyed so it can clean up the dead entities from its local store

# File lib/deep_unrest/concerns/map_temp_ids.rb, line 31
def track_destruction
  destroyed = DeepUnrest::ApplicationController.class_variable_get(
    '@@destroyed_entities'
  )
  return unless destroyed
  destroyed << {
    type: self.class.to_s.pluralize.camelize(:lower),
    id: pk,
    destroyed: true,
    query_uuid: @deep_unrest_query_uuid
  }
end