Sha256: a8855229f301a71d98cbfefab092ecd5dfb8bf28a86630cb74b0af2a7f08ff52

Contents?: true

Size: 823 Bytes

Versions: 8

Compression:

Stored size: 823 Bytes

Contents

module Typhoeus
  class Hydra

    # This module provides a way to hook into before
    # a request gets queued in hydra. This is very powerful
    # and you should be careful because when you accidently
    # return a falsy value the request won't be executed.
    #
    # @api private
    module Before

      # Overrride add in order to execute callbacks in
      # Typhoeus.before. Will break and return when a
      # callback returns nil or false. Calls super
      # otherwise.
      #
      # @example Add the request.
      #   hydra.add(request)
      def add(request)
        Typhoeus.before.each do |callback|
          value = callback.call(request)
          if value.nil? || value == false || value.is_a?(Response)
            return value
          end
        end
        super
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
typhoeus-0.6.3 lib/typhoeus/hydra/before.rb
typhoeus-0.6.2 lib/typhoeus/hydra/before.rb
typhoeus-0.6.1 lib/typhoeus/hydra/before.rb
typhoeus-0.6.0 lib/typhoeus/hydra/before.rb
typhoeus-0.6 lib/typhoeus/hydra/before.rb
typhoeus-0.5.4 lib/typhoeus/hydra/before.rb
typhoeus-0.5.3 lib/typhoeus/hydra/before.rb
typhoeus-0.5.2 lib/typhoeus/hydra/before.rb