File: cached_loader.rb

package info (click to toggle)
ruby-countries 4.2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 11,196 kB
  • sloc: ruby: 2,085; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 740 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Sources
  # Support code to allow updating subdivision data from the Unicode CLDR repository
  module Local
    # Loader for locally-cached data, to allow merging Unicode CLDR data with existing local data
    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