Module: TableSync::Publishing::ORMAdapter::ActiveRecord

Defined in:
lib/table_sync/publishing/orm_adapter/active_record.rb

Class Method Summary collapse

Class Method Details

.attributes(object) ⇒ Object



15
16
17
# File 'lib/table_sync/publishing/orm_adapter/active_record.rb', line 15

def attributes(object)
  object.attributes
end

.find(dataset, conditions) ⇒ Object



11
12
13
# File 'lib/table_sync/publishing/orm_adapter/active_record.rb', line 11

def find(dataset, conditions)
  dataset.find_by(conditions)
end

.model_naming(object) ⇒ Object



7
8
9
# File 'lib/table_sync/publishing/orm_adapter/active_record.rb', line 7

def model_naming(object)
  ::TableSync::NamingResolver::ActiveRecord.new(table_name: object.table_name)
end

.setup_sync(klass, opts) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/table_sync/publishing/orm_adapter/active_record.rb', line 19

def setup_sync(klass, opts)
  debounce_time = opts.delete(:debounce_time)

  klass.instance_exec do
    { create: :created, update: :updated, destroy: :destroyed }.each do |event, state|
      after_commit(on: event, **opts) do
        TableSync::Publishing::Publisher.new(self.class.name, attributes,
                                             state: state, debounce_time: debounce_time).publish
      end
    end
  end
end