module TableSync::Publishing::ORMAdapter::ActiveRecord

Public Instance Methods

attributes(object) click to toggle source
# File lib/table_sync/publishing/orm_adapter/active_record.rb, line 15
def attributes(object)
  object.attributes
end
find(dataset, conditions) click to toggle source
# File lib/table_sync/publishing/orm_adapter/active_record.rb, line 11
def find(dataset, conditions)
  dataset.find_by(conditions)
end
model_naming(object) click to toggle source
# 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) click to toggle source
# 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