Sha256: 4cd21243d3040b248461113f588d1f2bd8a96d0d0daf03dbd9a2ee4edd5832ac
Contents?: true
Size: 1.14 KB
Versions: 3
Compression:
Stored size: 1.14 KB
Contents
require "propertybase_id" require "active_record" require "active_support/concern" require "activerecord/propertybase_id/version" require "activerecord/propertybase_id/patches" require "activerecord/propertybase_id/railtie" if defined?(Rails::Railtie) module ActiveRecord module PropertybaseId extend ActiveSupport::Concern included do class_attribute :_propertybase_object, instance_writer: false self._propertybase_object = self.name.underscore before_create :generate_propertybase_id_if_needed end def propertybase_id pb_id_string = send(self.class.primary_key) ::PropertybaseId.parse(pb_id_string) end def generate_propertybase_id ::PropertybaseId.generate(object: _propertybase_object.to_s).to_s end def generate_propertybase_id_if_needed primary_key = self.class.primary_key send("#{primary_key}=", generate_propertybase_id) unless send("#{primary_key}?") end module ClassMethods def propertybase_object(proeprtybase_object) self._propertybase_object = proeprtybase_object end end end end ActiveRecord::PropertybaseId::Patches.apply!
Version data entries
3 entries across 3 versions & 1 rubygems