Sha256: 356a4533b355b01d827ac517682c6b771e3187215df64194ec4c7c170be4bf2c
Contents?: true
Size: 1.42 KB
Versions: 8
Compression:
Stored size: 1.42 KB
Contents
module ErpProducts module Extensions module ActiveRecord module ActsAsProductInstance def self.included(base) base.extend(ClassMethods) end module ClassMethods def acts_as_product_instance extend ActsAsProductInstance::SingletonMethods include ActsAsProductInstance::InstanceMethods after_initialize :initialize_product_instance after_create :save_product_instance after_update :save_product_instance after_destroy :destroy_product_instance has_one :product_instance, :as => :product_instance_record [:product_type,:product_type=,:description,:description=].each do |m| delegate m, :to => :product_instance end end end module SingletonMethods end module InstanceMethods def save_product_instance self.product_instance.save end def initialize_product_instance if self.new_record? && self.product_instance.nil? product_instance = ProductInstance.new self.product_instance = product_instance product_instance.product_instance_record = self end end def destroy_product_instance self.product_instance.destroy if (self.product_instance && !self.product_instance.frozen?) end end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems