class Promiscuous::BlackHole::Record
Attributes
attributes[R]
table_name[R]
Public Class Methods
new(table_name, attributes)
click to toggle source
# File lib/promiscuous_black_hole/record.rb, line 8 def initialize(table_name, attributes) @table_name = table_name @attributes = attributes end
Public Instance Methods
destroy()
click to toggle source
# File lib/promiscuous_black_hole/record.rb, line 17 def destroy Promiscuous.debug "Deleting record: #{ table_name }: #{ attributes['id'] }" Promiscuous::Subscriber::Worker::EventualDestroyer.postpone_destroy(table_name, attributes['id']) end
message_version_newer_than_persisted?()
click to toggle source
# File lib/promiscuous_black_hole/record.rb, line 22 def message_version_newer_than_persisted? # _v can be nil when records come in via a manual sync existing_record.nil? || existing_record[:_v].nil? || existing_record[:_v] <= attributes['_v'].to_i end
upsert()
click to toggle source
# File lib/promiscuous_black_hole/record.rb, line 13 def upsert existing_record ? update : create end
Private Instance Methods
create()
click to toggle source
# File lib/promiscuous_black_hole/record.rb, line 40 def create Promiscuous.debug "Creating record: #{attributes.values}" DB[table_name].insert(formatted_attributes) end
criteria()
click to toggle source
# File lib/promiscuous_black_hole/record.rb, line 51 def criteria DB[table_name].where('id = ?', attributes['id']) end
existing_record()
click to toggle source
# File lib/promiscuous_black_hole/record.rb, line 31 def existing_record @existing_record ||= criteria.first end
formatted_attributes()
click to toggle source
# File lib/promiscuous_black_hole/record.rb, line 45 def formatted_attributes attrs = {} attributes.each { |k, v| attrs[k] = sql_representation_for(v) } attrs end
update()
click to toggle source
# File lib/promiscuous_black_hole/record.rb, line 35 def update Promiscuous.debug "Updating record: [ #{attributes} ]" criteria.update(formatted_attributes) end