Sha256: 4d3be7c49b41f71882e31345a56fa2d906399142f04473ed9e3f619eb4950800

Contents?: true

Size: 1.64 KB

Versions: 4

Compression:

Stored size: 1.64 KB

Contents

module ErpWorkEffort
	module Extensions
		module ActiveRecord
			module ActsAsSupportEffort
			  
        def self.included(base)
          base.extend(ClassMethods)
        end

        module ClassMethods
          def acts_as_support_effort
            extend ActsAsSupportEffort::SingletonMethods
            include ActsAsSupportEffort::InstanceMethods
        
            after_initialize :new_support_effort
            after_update     :save_support_effort
            after_save       :save_support_effort
    				after_destroy    :destroy_support_effort
        
            has_one :support_effort, :as => :work_effort_record

            [
              :facility, 
              :facility=,
              :work_effort_assignments,
              :work_effort_statuses,
              :projected_cost,
              :actual_cost
            ].each do |m| delegate m, :to => :support_effort end
        
          end
        end

        module SingletonMethods
        end

        module InstanceMethods
          def method_missing(name, *args)
             self.support_effort.respond_to?(name) ? self.support_effort.send(name, *args) : super
          end
          
          def save_support_effort
            self.support_effort.save
          end

          def destroy_support_effort
            self.support_effort.destroy
          end

          def new_support_effort
            if self.new_record? and self.support_effort.nil?
              support_effort = SupportEffort.new
              self.support_effort = support_effort
              support_effort.work_effort_record = self
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
erp_work_effort-3.1.1 lib/erp_work_effort/extensions/active_record/acts_as_support_effort.rb
erp_work_effort-3.1.0 lib/erp_work_effort/extensions/active_record/acts_as_support_effort.rb
erp_work_effort-3.0.4 lib/erp_work_effort/extensions/active_record/acts_as_support_effort.rb
erp_work_effort-3.0.3 lib/erp_work_effort/extensions/active_record/acts_as_support_effort.rb