Sha256: 8542bcac3d05f41fc22a16d2dc76df2a138664422c985f9a277d858940fbe7da

Contents?: true

Size: 951 Bytes

Versions: 2

Compression:

Stored size: 951 Bytes

Contents

require "faraday/detailed_logger"
require "faraday_middleware"
require "active_support"

module HubLink
  class Configuration
    def initialize(cache_time: 3600)
      @cache_time = cache_time
    end

    def apply
      Octokit.middleware = middleware
      Octokit.auto_paginate = true
    end

    private

      attr_reader :cache_time

      def middleware
        Faraday::RackBuilder.new do |builder|
          builder.response :detailed_logger, logger
          builder.response :caching, cache
          builder.use Octokit::Response::RaiseError
          builder.adapter Faraday.default_adapter
        end
      end

      def cache
        ActiveSupport::Cache::FileStore.new "tmp/cache", expires_in: cache_time
      end

      def logger
        logger = Logger.new(STDOUT)
        logger.formatter = ->(_, datetime, _, msg) { "#{datetime.to_s(:db)} - #{msg}\n" }
        logger.level = Logger::INFO
        logger
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hub_link-0.2.0 lib/hub_link/configuration.rb
hub_link-0.1.0 lib/hub_link/configuration.rb