Sha256: c59e35f91c1e86f26bc48971a3e02d4cddbade0bfd04604c63bd00280ea57bce

Contents?: true

Size: 944 Bytes

Versions: 1

Compression:

Stored size: 944 Bytes

Contents

module DeathAndTaxes
  module Taxable
    def self.included(base)
      base.extend ClassMethods
    end
    
    
    module ClassMethods
      
      ##
      # Makes this model taxable
      # It will then be able to have taxations applied
      # Example:
      #   class Invoicing < ActiveRecord::Base
      #     acts_as_taxable
      #   end
      def acts_as_taxable(*args)
        
        class_eval do
          has_many :taxations, :as => :taxable, :class_name => 'DeathAndTaxes::Taxation'
        end
        
        include DeathAndTaxes::Taxable::InstanceMethods
      end
    end
    
    module InstanceMethods
      def apply_taxes(taxes)
        taxes = [taxes] unless taxes.is_a? Array
        
        self.taxations = taxes.collect do |tax|
          Taxation.new :amount => tax.apply(amount), :percentage => tax.multiplier, :name => tax.name, :account_number => tax.account_number
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
death_and_taxes-0.0.1 lib/death_and_taxes/taxable.rb