Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ud_sync/rails/model_extension.rb

Direct Known Subclasses

UdSync::Operation

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ud_sync(entity: nil, id: :id, owner: nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ud_sync/rails/model_extension.rb', line 4

def ud_sync(entity: nil, id: :id, owner: nil)
  @@ud_sync_options ||= {}

  class_name = self.name
  @@ud_sync_options[class_name] = {
    entity: entity,
    id: id,
    owner: owner
  }

  self.after_save :save_operation
  self.after_destroy :save_operation
end

Instance Method Details

#save_operationObject



19
20
21
# File 'lib/ud_sync/rails/model_extension.rb', line 19

def save_operation
  UdSync::Sentinel.new(self, @@ud_sync_options[self.class.name]).save_operation
end