Class: Money::Bank::PersistentBank

Inherits:
VariableExchange
  • Object
show all
Defined in:
lib/money/bank/persistent_bank.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage, key = 'persistent_bank/rates', format = :yaml) ⇒ PersistentBank

Returns a new instance of PersistentBank.



8
9
10
11
12
13
# File 'lib/money/bank/persistent_bank.rb', line 8

def initialize storage, key = 'persistent_bank/rates', format = :yaml
  super()
  @storage = storage
  @storage_key = key
  @storage_format = format
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



6
7
8
# File 'lib/money/bank/persistent_bank.rb', line 6

def storage
  @storage
end

Instance Method Details

#clearObject



25
26
27
# File 'lib/money/bank/persistent_bank.rb', line 25

def clear
  storage.delete(@storage_key)
end

#export_ratesObject



15
16
17
# File 'lib/money/bank/persistent_bank.rb', line 15

def export_rates
  storage.write(@storage_key, super(@storage_format))
end

#import_ratesObject



19
20
21
22
23
# File 'lib/money/bank/persistent_bank.rb', line 19

def import_rates
  rates.clear
  cache = storage.read(@storage_key)
  super(@storage_format, cache) if cache
end