Sha256: 262f850db42c44a8cfd58fd1f26092d5d5d4ff07ad33051b3766bf9d56a73ec3

Contents?: true

Size: 880 Bytes

Versions: 1

Compression:

Stored size: 880 Bytes

Contents

# frozen_string_literal: true

module TableSync::ORMAdapter
  module ActiveRecord
    module_function

    def model
      ::TableSync::Model::ActiveRecord
    end

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

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

    def attributes(object)
      object.attributes
    end

    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::Publisher.new(self.class.name, attributes,
                                     state: state, debounce_time: debounce_time).publish
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
table_sync-2.3.0 lib/table_sync/orm_adapter/active_record.rb