Sha256: c10ee44d2e83283c2e393160876ffd95b931a1671630e9292ab8a59576fc3d01

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

module Amfetamine
  class Config
    class << self

      attr_reader :memcached_instance, :rest_client, :base_uri, :resource_suffix, :logger, :disable_caching

      def configure
        yield(self)
        @base_uri ||= ""
      end

      def memcached_instance=(servers, options={})
        opts = default_memcached_options.merge(options)
        @memcached_instance ||= Dalli::Client.new(servers, opts)
      end

      def rest_client=(value)
        raise ConfigurationInvalid, 'Invalid value for rest_client' if ![:get,:put,:delete,:post].all? { |m| value.respond_to?(m) }
        @rest_client ||= value
      end

      # Shouldn't be needed as our favourite rest clients are based on httparty, still, added it for opensource reasons
      def base_uri=(value)
        raise ConfigurationInvalid, "Invalid value for base uri, should be a string" if !value.is_a?(String)
        @base_uri ||= value
      end

      def resource_suffix=(value)
        raise ConfigurationInvalid, "Invalid value for resource suffix, should be a string" if !value.is_a?(String)
        @resource_suffix ||= value
      end

      def disable_caching=(value)
        @disable_caching = value
      end

      def default_memcached_options
        {
          expires_in: expiration_time
        }
      end

      def expiration_time
        if defined?(::Rails) && Rails.env.development?
          60.seconds
        else
          10.minutes
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
amfetamine-0.4.2 lib/amfetamine/config.rb