Project

dm-money

0.0
No commit activity in last 3 years
No release in over 3 years
BigMoney backed DataMapper money plugin.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.1
~> 1.0
 Project Readme

dm-money¶ ↑

Description¶ ↑

BigMoney backed DataMapper money properties.

Todo¶ ↑

  • Validations.

  • Precision and scale options should also be applied to underlying BigMoney/BigDecimal amount.

  • A rounding mode option, see BigDecimal#mode.

Synopsis¶ ↑

Basic¶ ↑

require 'dm-core'
require 'dm-money'

class Cake
  include DataMapper::Resource
  # ... other properties.

  money :gst
  # public
  #   gst #=> BigMoney
  #   gst=(value)
  #
  # property :gst_amount,   BigDecimal, accessor: private
  # property :gst_currency, String,     accessor: private, length: 3
end

Property Options¶ ↑

require 'dm-core'
require 'dm-money'

class Cake
  include DataMapper::Resource
  # ... other properties.

  money :price, required: true, accessor: protected
  # protected
  #   price #=> BigMoney
  #   price=(value)
  #
  # property :price_amount,   BigDecimal, accessor: private, required: true
  # property :price_currency, String,     accessor: private, required: true, length: 3
end

Precision and Scale¶ ↑

“The SQL standard requires a default scale of 0, i.e. coercion to integer precision. We find this a bit useless. If you’re concerned about portability, always specify the precision and scale explicitly.” – PostgreSQL Documentation.

DataMapper’s bread and butter is SQL and old school relational databases so unsurprisingly a default numeric/decimal scale of 0 is used (where the default precision comes from I do not know).

If you require any fractional money amounts remember to explicitly set the precision and scale options for each money property.

Install¶ ↑

  • Via git:

    git clone git://github.com/shanna/dm-money.git
    cd dm-money && rake install
  • Via gem:

    gem install dm-money
    

License¶ ↑

See LICENSE.