Sha256: f587a7fcb76be9c1e70be47c9b00ddc504a716b6d185bd68d6b6d1c0f8eb6e0f

Contents?: true

Size: 634 Bytes

Versions: 2

Compression:

Stored size: 634 Bytes

Contents

require "acts_as_money/version"
require "acts_as_money/money"

module ActsAsMoney
  def self.included(base)
    base.extend(ClassMethods)
  end

  module ClassMethods
    def money(*attr_names)
      attr_names.each do |attr_name|
        generator = lambda { |x|
          decimals = columns.detect { |c| c.name == attr_name.to_s }.scale
          Money.new(x, decimals)
        }
        composed_of attr_name, class_name: "ActsAsMoney::Money", mapping: [attr_name, :amount], 
          allow_nil: true, converter: generator, constructor: generator
      end
    end
  end
end

ActiveRecord::Base.class_eval { include ActsAsMoney }

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eeng-money-0.1.0 lib/acts_as_money.rb
eeng-money-0.0.1 lib/acts_as_money.rb