class Terrestrial::UpsertRecord

Attributes

attributes[R]
depth[R]
mapping[R]
object[R]

Public Class Methods

new(mapping, object, attributes, depth) click to toggle source
# File lib/terrestrial/upsert_record.rb, line 5
def initialize(mapping, object, attributes, depth)
  @mapping = mapping
  @object = object
  @attributes = attributes
  @depth = depth
end

Public Instance Methods

get(name) click to toggle source
# File lib/terrestrial/upsert_record.rb, line 23
def get(name)
  fetch(name)
end
id?() click to toggle source
# File lib/terrestrial/upsert_record.rb, line 14
def id?
  identity_values.reject(&:nil?).any?
end
if_upsert(&block) click to toggle source
# File lib/terrestrial/upsert_record.rb, line 31
def if_upsert(&block)
  block.call(self)
  self
end
include?(field_name) click to toggle source
# File lib/terrestrial/upsert_record.rb, line 44
def include?(field_name)
  keys.include?(field_name)
end
insertable() click to toggle source
# File lib/terrestrial/upsert_record.rb, line 40
def insertable
  to_h.reject { |k, v| v.nil? && identity_fields.include?(k) }
end
on_upsert(new_attributes) click to toggle source
# File lib/terrestrial/upsert_record.rb, line 36
def on_upsert(new_attributes)
  mapping.post_save(object, self, new_attributes)
end
set(name, value) click to toggle source
# File lib/terrestrial/upsert_record.rb, line 27
def set(name, value)
  merge!(name => value)
end
set_id(id) click to toggle source
# File lib/terrestrial/upsert_record.rb, line 18
def set_id(id)
  raise "Cannot use #set_id with composite key" if identity_fields.length > 1
  merge!(identity_fields[0] => id)
end

Private Instance Methods

new_with_attributes(new_attributes) click to toggle source
# File lib/terrestrial/upsert_record.rb, line 50
def new_with_attributes(new_attributes)
  self.class.new(mapping, object, new_attributes, depth)
end