Method: Osm::Model.configure

Defined in:
lib/osm/model.rb

.configure(options) ⇒ Object

Configure the options used by all models

Parameters:

  • options (Hash)

Options Hash (options):

  • :cache (Class, nil)

    An instance of a cache class, must provide the methods (exist?, delete, write, read), for details see Rails.cache. Set to nil to disable caching.

  • :ttl (Fixnum) — default: optional, default = 1800 (30 minutes)

    The default TTL value for the cache, note that some items are cached for twice this time and others are cached for half this time (in seconds)

  • :prepend_to_key (String) — default: optional, default = 'OSMAPI'

    Text to prepend to the key used to store data in the cache

Returns:

  • nil

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/osm/model.rb', line 27

def self.configure(options)
  raise ArgumentError, ":ttl must be a FixNum greater than 0" if options[:ttl] && !(options[:ttl].is_a?(Fixnum) && options[:ttl] > 0)
  raise ArgumentError, ":prepend_to_key must be a String" if options[:prepend_to_key] && !options[:prepend_to_key].is_a?(String)
  if options[:cache]
    [:exist?, :delete, :write, :read].each do |method|
      raise ArgumentError, ":cache must have a #{method} method" unless options[:cache].methods.include?(method)
    end
  end

  @@cache = options[:cache]
  @@cache_prepend = options[:prepend_to_key] || 'OSMAPI'
  @@cache_ttl = options[:ttl] || 600
  nil
end