Sha256: 0c0a9a7d41a78cc8248b2f3de66ec86389c7394a083a702387786c92329a9680
Contents?: true
Size: 1.65 KB
Versions: 4
Compression:
Stored size: 1.65 KB
Contents
# frozen_string_literal: true module TableSync::ORMAdapter class Base attr_reader :object, :object_class, :object_data def initialize(object_class, object_data) @object_class = object_class @object_data = object_data.symbolize_keys validate! end # VALIDATE def validate! if (primary_key_columns - object_data.keys).any? raise TableSync::NoPrimaryKeyError.new(object_class, object_data, primary_key_columns) end end # FIND OR INIT OBJECT def init self end def find self end def needle object_data.slice(*primary_key_columns) end # ATTRIBUTES def attributes_for_update if object.respond_to?(:attributes_for_sync) object.attributes_for_sync else attributes end end def attributes_for_destroy if object.respond_to?(:attributes_for_destroy) object.attributes_for_destroy else needle end end def attributes_for_routing_key if object.respond_to?(:attributes_for_routing_key) object.attributes_for_routing_key else attributes end end def attributes_for_headers if object.respond_to?(:attributes_for_headers) object.attributes_for_headers else attributes end end def primary_key_columns Array.wrap(object_class.primary_key).map(&:to_sym) end # MISC def empty? object.nil? end # NOT IMPLEMENTED # :nocov: def attributes raise NotImplementedError end def self.model_naming raise NotImplementedError end # :nocov: end end
Version data entries
4 entries across 4 versions & 1 rubygems