Sha256: 79f5b3ec7d8311f724dcac06356a5b8f5be50d14e977eae353f4135c27274494
Contents?: true
Size: 1.58 KB
Versions: 1
Compression:
Stored size: 1.58 KB
Contents
# frozen_string_literal: true module TableSync::ORMAdapter module Sequel module_function def model ::TableSync::Model::Sequel end def model_naming(object) ::TableSync::NamingResolver::Sequel.new(table_name: object.table_name, db: object.db) end def find(dataset, conditions) dataset.find(conditions) end def attributes(object) object.values end def setup_sync(klass, opts) if_predicate = to_predicate(opts.delete(:if), true) unless_predicate = to_predicate(opts.delete(:unless), false) debounce_time = opts.delete(:debounce_time) if opts.any? raise "Only :if, :skip_debounce and :unless options are currently " \ "supported for Sequel hooks" end register_callbacks(klass, if_predicate, unless_predicate, debounce_time) end def to_predicate(val, default) return val.to_proc if val.respond_to?(:to_proc) -> (*) { default } end def register_callbacks(klass, if_predicate, unless_predicate, debounce_time) { create: :created, update: :updated, destroy: :destroyed }.each do |event, state| klass.send(:define_method, :"after_#{event}") do if instance_eval(&if_predicate) && !instance_eval(&unless_predicate) db.after_commit do TableSync::Publisher.new( self.class.name, values, state: state, debounce_time: debounce_time, ).publish end end super() 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/sequel.rb |