Sha256: 81ad0da504a35426ffd46ea68ae5a7befd27a3a19cbc1bd022578bd2966a6c47

Contents?: true

Size: 727 Bytes

Versions: 2

Compression:

Stored size: 727 Bytes

Contents

# monkeypatching Money class to catch Money::Bank::UnknownRate error

class Money  
  mattr_accessor :google_saved_the_day
  
  self.google_saved_the_day = false
  
  def self.google_to_the_rescue
    !google_saved_the_day && self.google_saved_the_day = true
  end
  
  def exchange_to_with_google(*args)
    exchange_to_without_google(*args)
  rescue Money::Bank::UnknownRate => e
    
    if @bank == Money::Bank::VariableExchange.instance &&
        self.class.google_to_the_rescue
        
      Money.default_bank = @bank = Money::Bank::GoogleCurrency.new
      retry
    else
      raise e
    end
  end
  
  alias_method :exchange_to_without_google, :exchange_to
  alias_method :exchange_to, :exchange_to_with_google
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
counterfeit-0.0.2 lib/counterfeit/money.rb
counterfeit-0.0.1 lib/counterfeit/money.rb