Sha256: 4345fc5410d86e303aa91a7552ecc389f43bc60acbeaeef3d4eddcf35d1e1333

Contents?: true

Size: 658 Bytes

Versions: 2

Compression:

Stored size: 658 Bytes

Contents

class Ur
  module Faraday
    class YieldUr < ::Faraday::Middleware
      def initialize(app, options = {}, &block)
        raise(ArgumentError, "no block given to yield ur") unless block
        raise(TypeError, "options must be a Hash") unless options.respond_to?(:to_hash)
        @app = app
        @options = options
        @yield_to = block
      end

      def call(request_env)
        ur = (@options[:ur_class] || Ur).from_faraday_request(request_env)
        ur.logger = @options[:logger] if @options[:logger]
        ur.faraday_on_complete(@app, request_env) do |response_env|
          @yield_to.call(ur)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ur-0.1.0 lib/ur/faraday/yield_ur.rb
ur-0.0.4 lib/ur/faraday/yield_ur.rb