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 =
'5.1.0'

Class Method Summary collapse

Class Method Details

.cacheObject



18
19
20
# File 'lib/economy.rb', line 18

def cache
  @cache ||= Cache.new
end

.configurationObject



26
27
28
# File 'lib/economy.rb', line 26

def configuration
  @configuration ||= Configuration.new
end

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

Yields:



30
31
32
# File 'lib/economy.rb', line 30

def configure
  yield configuration
end

.currenciesObject



22
23
24
# File 'lib/economy.rb', line 22

def currencies
  @currencies ||= Currencies.new
end

.rate(*args) ⇒ Object



34
35
36
# File 'lib/economy.rb', line 34

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

.update_ratesObject



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

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