Sha256: 80aa6de75dadd972be51d9a9d7b86a54946d0d3461a0327c1b3cc83dfd5f6232

Contents?: true

Size: 1.57 KB

Versions: 9

Compression:

Stored size: 1.57 KB

Contents

module ErpInventory
	module Extensions
		module ActiveRecord
			module ActsAsInventoryEntry
		    def self.included(base)
          base.extend(ClassMethods)  	        	      	
        end

    		module ClassMethods
      		def acts_as_inventory_entry
  		      extend ActsAsInventoryEntry::SingletonMethods
    			  include ActsAsInventoryEntry::InstanceMethods
  		      
  		      after_initialize :new_inventory_entry
            after_update     :save_inventory
            after_save       :save_inventory
    				after_destroy    :destroy_inventory
  		      
            has_one :inventory_entry, :as => :inventory_entry_record  		

            [
              :product_type,:product_type=,
              :product_instances,
              :number_available,:number_available=
            ].each do |m|
              delegate m, :to => :inventory_entry
            end			     			
    		  end
    		end
  		
    		module SingletonMethods			
    		end
				
    		module InstanceMethods
    		  def new_inventory_entry
            if self.new_record? && self.inventory_entry == nil
              self.inventory_entry = InventoryEntry.new
              self.inventory_entry.inventory_entry_record = self
            end
          end

          def save_inventory
            self.inventory_entry.save
          end 
    
          def destroy_inventory
            if self.inventory_entry && !self.inventory_entry.frozen?
              self.inventory_entry.destroy
            end          
          end		  
		  
    	  end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
erp_inventory-4.2.0 lib/erp_inventory/extensions/active_record/acts_as_inventory_entry.rb
erp_inventory-4.0.0 lib/erp_inventory/extensions/active_record/acts_as_inventory_entry.rb
erp_inventory-3.1.0 lib/erp_inventory/extensions/active_record/acts_as_inventory_entry.rb
erp_inventory-3.0.5 lib/erp_inventory/extensions/active_record/acts_as_inventory_entry.rb
erp_inventory-3.0.4 lib/erp_inventory/extensions/active_record/acts_as_inventory_entry.rb
erp_inventory-3.0.3 lib/erp_inventory/extensions/active_record/acts_as_inventory_entry.rb
erp_inventory-3.0.2 lib/erp_inventory/extensions/active_record/acts_as_inventory_entry.rb
erp_inventory-3.0.1 lib/erp_inventory/extensions/active_record/acts_as_inventory_entry.rb
erp_inventory-3.0.0 lib/erp_inventory/extensions/active_record/acts_as_inventory_entry.rb