Module: Economy

Defined in:
lib/economy.rb,
lib/economy/cache.rb,
lib/economy/money.rb,
lib/economy/builder.rb,
lib/economy/railtie.rb,
lib/economy/version.rb,
lib/economy/currency.rb,
lib/economy/exchange.rb,
lib/economy/currencies.rb,
lib/economy/rates/base.rb,
lib/economy/rates/yahoo.rb,
lib/economy/configuration.rb,
lib/economy/extensions/active_record/base.rb,
lib/generators/economy/install/install_generator.rb

Defined Under Namespace

Modules: Extensions, Generators, Rates Classes: Builder, Cache, Configuration, Currencies, Currency, Exchange, Money, Railtie

Constant Summary collapse

VERSION =
'4.0.2.2'

Class Method Summary collapse

Class Method Details

.cacheObject



16
17
18
# File 'lib/economy.rb', line 16

def cache
  @cache ||= Cache.new
end

.configurationObject



24
25
26
# File 'lib/economy.rb', line 24

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



28
29
30
# File 'lib/economy.rb', line 28

def configure
  yield configuration
end

.currenciesObject



20
21
22
# File 'lib/economy.rb', line 20

def currencies
  @currencies ||= Currencies.new
end

.rate(*args) ⇒ Object



32
33
34
# File 'lib/economy.rb', line 32

def rate(*args)
  cache.send :fetch, *args
end

.update_ratesObject



36
37
38
39
40
41
42
43
# File 'lib/economy.rb', line 36

def update_rates
  class_name = configuration.rates.to_s.classify
  rates = Rates.const_get(class_name).new
  rates.fetch.each do |from, to, rate|
    puts "Updating exchange #{from} => #{to} with rate #{rate}"
    Exchange.create service: class_name, from: from, to: to, rate: rate
  end
end