Repository is archived
No commit activity in last 3 years
No release in over 3 years
Adds persistent bank to Money gem
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 4.0
 Project Readme

Money Persistent Bank

"Money" gem provides VariableExchange which is useful for converting money from one currency to another. This gem provides PersistentBank which can save rates to a local storage and automatically load from it in another place.

This can be useful in a Rails application. You fetch rates from external source once a day in a rake task and your running application picks up the new rates on the next request.

Usage in Rails

Add it to your gemfile:

gem "money_persistent_bank", "~> 0.2.0"

Now you can use it in a rake task.

task :fetch_rates => :environment do
  bank = Money.default_bank

  # Here goes your code that fetches the rates from external source.
  # Emulating this:
  sleep 1
  bank.set_rate(:usd, :eur, 0.8)

  bank.export_rates # you have to explicitly export after setting the rates
end

(See also money_bank_sources.)

And somewhere in your application:

Money.default_bank.import_rates
1.to_money(:usd).exchange_to(:eur).to_f # => 0.8

When the rates are updated it will automatically use them.