Class: Sources::Local::CachedLoader
- Inherits:
-
Object
- Object
- Sources::Local::CachedLoader
- Defined in:
- lib/countries/sources/local/cached_loader.rb
Overview
Loader for locally-cached data, to allow merging Unicode CLDR data with existing local data
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #from_cache(country_code) ⇒ Object
-
#initialize(klass) ⇒ CachedLoader
constructor
A new instance of CachedLoader.
- #load(country_code) ⇒ Object
- #save(country_code, data) ⇒ Object
Constructor Details
#initialize(klass) ⇒ CachedLoader
Returns a new instance of CachedLoader.
10 11 12 13 |
# File 'lib/countries/sources/local/cached_loader.rb', line 10 def initialize(klass) @klass = klass @loaded_countries = {} end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
8 9 10 |
# File 'lib/countries/sources/local/cached_loader.rb', line 8 def klass @klass end |
Instance Method Details
#from_cache(country_code) ⇒ Object
15 16 17 |
# File 'lib/countries/sources/local/cached_loader.rb', line 15 def from_cache(country_code) @loaded_countries[country_code] end |
#load(country_code) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/countries/sources/local/cached_loader.rb', line 19 def load(country_code) if (data = from_cache(country_code)) data else @loaded_countries[country_code] = klass.load(country_code) end end |
#save(country_code, data) ⇒ Object
27 28 29 |
# File 'lib/countries/sources/local/cached_loader.rb', line 27 def save(country_code, data) klass.new(country_code).save(data) end |