File: base.rb

package info (click to toggle)
ruby-geocoder 1.8.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 900 kB
  • sloc: ruby: 8,419; makefile: 3
file content (40 lines) | stat: -rw-r--r-- 765 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
30
31
32
33
34
35
36
37
38
39
40
module Geocoder::CacheStore
  class Base
    def initialize(store, options)
      @store = store
      @config = options
      @prefix = config[:prefix]
    end

    ##
    # Array of keys with the currently configured prefix
    # that have non-nil values.
    def keys
      store.keys.select { |k| k.match(/^#{prefix}/) and self[k] }
    end

    ##
    # Array of cached URLs.
    #
    def urls
      keys
    end

    protected # ----------------------------------------------------------------

    def prefix; @prefix; end
    def store; @store; end
    def config; @config; end

    ##
    # Cache key for a given URL.
    #
    def key_for(url)
      if url.match(/^#{prefix}/)
        url
      else
        [prefix, url].join
      end
    end
  end
end