require_relative 'provider' module Ca module DataStore # # All method from this model is prefixed with cads_ # to separate the call with included/extended class. # Notably case in mind is ActiveRecord # module Model include TR::CondUtils include TeLogger::TeLogHelper teLogger_tag :cads_model module ClassMethods def cads_find(*args, &block) Provider.instance.provider.handle(:find, self, *args, &block) end # unstable relationship between mid and potential keys inside data store such as ActiveRecord # The name cannot be same and it is up to user to define or link if there is #def cads_find_by_mid(*args, &block) # Provider.instance.provider.handle(:find_by_mid, self, *args, &block) #end def cads_find_all(*args, &block) Provider.instance.provider.handle(:find_all, self, *args, &block) end def cads_schema(*args, &block) Provider.instance.provider.handle(:schema, self, *args, &block) end end # ClassMethods def self.included(klass) klass.extend(ClassMethods) end def Model.init(*args, &block) Provider.instance.provider.handle(:init, *args, &block) end def Model.reset(*args, &block) Provider.instance.provider.handle(:reset, *args, &block) end attr_accessor :mid, :ts_created, :ts_updated, :cads_new_record def cads_save(*args, &block) if is_cads_new_record? and is_empty?(@mid) @mid = SecureRandom.hex(16) end Provider.instance.provider.handle(:save, self, *args, &block) end def cads_delete(*args, &block) Provider.instance.provider.handle(:delete, self, *args, &block) end def is_cads_new_record?(*args, &block) @cads_new_record = Provider.instance.provider.handle(:is_new_record?, self, *args, &block) @cads_new_record = true if is_empty?(@cads_new_record) or not is_bool?(@cads_new_record) @cads_new_record end end # Model end # DataStore end #Ca