Sha256: c0fc1d2e00389c1dc1ffc19a2108a7870aa180dd1121d81180ea6b1c711577ec

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

module Chuckle
  module Options
    DEFAULT_OPTIONS = {
      cache_dir: nil,
      cache_errors: true,
      cookies: false,
      expires_in: :never,
      nretries: 2,
      rate_limit: 1,
      timeout: 30,
      user_agent: "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0",
      verbose: false,
    }

    # cache root directory
    def cache_dir
      @cache_dir ||= begin
        dir = options[:cache_dir]
        dir ||= begin
          if home = ENV["HOME"]
            if File.exists?(home) && File.stat(home).writable?
              "#{home}/.chuckle"
            end
          end
        end
        dir ||= "/tmp/chuckle"
        dir
      end
    end

    # should errors be cached?
    def cache_errors?
      options[:cache_errors]
    end

    # are cookies enabled?
    def cookies?
      options[:cookies]
    end

    # number of seconds to cache responses and cookies, or :never
    def expires_in
      options[:expires_in]
    end

    # number of retries to attempt
    def nretries
      options[:nretries]
    end

    # number of seconds between requests
    def rate_limit
      options[:rate_limit]
    end

    # timeout per retry
    def timeout
      options[:timeout]
    end

    # user agent
    def user_agent
      options[:user_agent]
    end

    # verbose output?
    def verbose?
      options[:verbose]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chuckle-1.0.3 lib/chuckle/options.rb
chuckle-1.0.2 lib/chuckle/options.rb
chuckle-1.0.1 lib/chuckle/options.rb
chuckle-1.0.0 lib/chuckle/options.rb