Sha256: cb90ca65cfa37c36f4e94cfa80226f608293e3cc89d171148b6cc7429d9cbc56
Contents?: true
Size: 1.73 KB
Versions: 4
Compression:
Stored size: 1.73 KB
Contents
module Lockdown module Orms module ActiveRecord class << self def use_me? Object.const_defined?("ActiveRecord") && ::ActiveRecord.const_defined?("Base") end def included(mod) mod.extend Lockdown::Orms::ActiveRecord::Helper mixin end def mixin Lockdown.orm_parent.send :include, Lockdown::Orms::ActiveRecord::Stamps end end # class block module Helper def orm_parent ::ActiveRecord::Base end def database_execute(query) orm_parent.connection.execute(query) end def database_query(query) orm_parent.connection.execute(query) end def database_table_exists?(klass) klass.table_exists? end end module Stamps def self.included(base) base.class_eval do alias_method :create_without_stamps, :create alias_method :create, :create_with_stamps alias_method :update_without_stamps, :update alias_method :update, :update_with_stamps end end def current_profile_id Thread.current[:profile_id] end def create_with_stamps profile_id = current_profile_id || Profile::SYSTEM self[:created_by] = profile_id if self.respond_to?(:created_by) self[:updated_by] = profile_id if self.respond_to?(:updated_by) create_without_stamps end def update_with_stamps profile_id = current_profile_id || Profile::SYSTEM self[:updated_by] = profile_id if self.respond_to?(:updated_by) update_without_stamps end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems