Sha256: dbac28e23440f3b38fbad0cd4507fe2339b9d56bdfa4041f7888e8a2ef53e9e5

Contents?: true

Size: 557 Bytes

Versions: 12

Compression:

Stored size: 557 Bytes

Contents

module Sources
  module Local
    class CachedLoader
      attr_reader :klass
      def initialize(klass)
        @klass = klass
        @loaded_countries = {}
      end

      def from_cache(country_code)
        @loaded_countries[country_code]
      end

      def load(country_code)
        if (data = from_cache(country_code))
          data
        else
          @loaded_countries[country_code] = klass.load(country_code)
        end
      end

      def save(country_code, data)
        klass.new(country_code).save(data)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
countries-4.2.0 lib/countries/sources/local/cached_loader.rb
countries-4.1.3 lib/countries/sources/local/cached_loader.rb
countries-4.1.2 lib/countries/sources/local/cached_loader.rb
countries-4.1.1 lib/countries/sources/local/cached_loader.rb
countries-4.1.0 lib/countries/sources/local/cached_loader.rb
countries-4.0.1 lib/countries/sources/local/cached_loader.rb
countries-4.0.0 lib/countries/sources/local/cached_loader.rb
countries-3.1.0 lib/countries/sources/local/cached_loader.rb
countries-3.0.1 lib/countries/sources/local/cached_loader.rb
countries-3.0.0 lib/countries/sources/local/cached_loader.rb
countries-2.1.4 lib/countries/sources/local/cached_loader.rb
countries-2.1.3 lib/countries/sources/local/cached_loader.rb