Class: Money::Bank::GoogleCurrencyRailsCache
- Inherits:
-
VariableExchange
- Object
- VariableExchange
- Money::Bank::GoogleCurrencyRailsCache
- Defined in:
- lib/money/bank/google_currency_rails_cache.rb
Constant Summary collapse
- SERVICE_HOST =
"www.google.com"
- SERVICE_PATH =
"/finance/converter"
Instance Method Summary collapse
-
#cached_rates ⇒ Array
Lists all rates currency cached.
-
#flush_rate(from, to) ⇒ Boolean
Clears the specified rate stored in @rates.
-
#flush_rates ⇒ Object
Clears all rates stored in @rates.
-
#get_rate(from, to) ⇒ Float
Returns the requested rate.
Instance Method Details
#cached_rates ⇒ Array
Lists all rates currency cached.
71 72 73 |
# File 'lib/money/bank/google_currency_rails_cache.rb', line 71 def cached_rates Rails.cache.read("exchange_rate/all_rates") end |
#flush_rate(from, to) ⇒ Boolean
Clears the specified rate stored in @rates.
43 44 45 46 47 |
# File 'lib/money/bank/google_currency_rails_cache.rb', line 43 def flush_rate(from, to) rate_key = rate_key_for(from, to) Rails.cache.delete("exchange_rate/#{rate_key}") remove_from_stored_rates(rate_key) end |
#flush_rates ⇒ Object
Clears all rates stored in @rates
19 20 21 22 23 24 25 26 27 |
# File 'lib/money/bank/google_currency_rails_cache.rb', line 19 def flush_rates rates = Rails.cache.read("exchange_rate/all_rates") unless rates.nil? rates.each do |rate_key| Rails.cache.delete "exchange_rate/#{rate_key}" end end Rails.cache.delete("exchange_rate/all_rates") end |
#get_rate(from, to) ⇒ Float
Returns the requested rate.
60 61 62 63 64 |
# File 'lib/money/bank/google_currency_rails_cache.rb', line 60 def get_rate(from, to) Rails.cache.fetch("exchange_rate/#{rate_key_for(from, to)}", :expires_in => 12.hours ) { fetch_rate(from, to) } end |