Module: Nsync::ActiveRecord::Consumer::InstanceMethods

Defined in:
lib/nsync/active_record/consumer/methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



24
25
26
# File 'lib/nsync/active_record/consumer/methods.rb', line 24

def self.included(base)
  base.send(:extend, ClassMethods)
end

Instance Method Details

#nsync_update(consumer, event_type, filename, data) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/nsync/active_record/consumer/methods.rb', line 27

def nsync_update(consumer, event_type, filename, data)
  data = data.dup
  if event_type == :deleted
    destroy
  else
    nsync_opts = self.class.nsync_opts
    if nsync_opts[:id_key].to_s != "id"
      data[nsync_opts[:id_key].to_s] = data.delete("id")
    else
      self.id = data.delete("id")
      update_attributes(data)
    end
  end
end