Sha256: ed32c2f297ca2ba543b1aa6d164af90796b7b868df1b9861cbe476b4308f4e66

Contents?: true

Size: 737 Bytes

Versions: 12

Compression:

Stored size: 737 Bytes

Contents

module Carter
  module ActiveRecord
    module Extensions
      def money_converter
        Proc.new { |value| value.respond_to?(:to_money) ? value.to_money : Money.empty }
      end
      
      def money_constructor
        Proc.new { |value| value.respond_to?(:to_money) && !value.blank? ? Money.new(value) : Money.empty }
      end
      
      def money_composed_column(*args)
        options = args.extract_options!
        args.each do |column_name|
          composed_options = {:class_name => '::Money', :mapping => ["#{column_name}", "cents"],
          :converter => money_converter, :constructor => money_constructor}.update(options)
          composed_of column_name, composed_options
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
carter-0.8.1 lib/carter/active_record/extensions.rb
carter-0.8.0 lib/carter/active_record/extensions.rb
carter-0.7.2 lib/carter/active_record/extensions.rb
carter-0.7.1 lib/carter/active_record/extensions.rb
carter-0.7.0 lib/carter/active_record/extensions.rb
carter-0.6.4 lib/carter/active_record/extensions.rb
carter-0.6.3 lib/carter/active_record/extensions.rb
carter-0.6.2 lib/carter/active_record/extensions.rb
carter-0.6.1 lib/carter/active_record/extensions.rb
carter-0.6.0 lib/carter/active_record/extensions.rb
carter-0.5.6 lib/carter/active_record/extensions.rb
carter-0.5.5 lib/carter/active_record/extensions.rb