Module: Typhoeus::Request::BlockConnection Private

Included in:
Typhoeus::Request
Defined in:
lib/typhoeus/request/block_connection.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

This module handles the blocked connection request mode on the request side, where only stubbed requests are allowed. Connection blocking needs to be turned on:

Typhoeus.configure do |config|
  config.block_connection = true
end

When trying to do real requests a NoStub error is raised.

Since:

  • 0.5.0

Instance Method Summary collapse

Instance Method Details

#blocked?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns wether a request is blocked or not. Takes request.block_connection and Typhoeus::Config.block_connection into consideration.

Examples:

Blocked?

request.blocked?

Returns:

  • (Boolean)

    True if blocked, false else.

Since:

  • 0.5.0



43
44
45
46
47
48
49
# File 'lib/typhoeus/request/block_connection.rb', line 43

def blocked?
  if block_connection.nil?
    Typhoeus::Config.block_connection
  else
    block_connection
  end
end

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Overrides run in order to check before if block connection is turned on. If thats the case a NoStub error is raised.

Examples:

Run request.

request.run

Raises:

Since:

  • 0.5.0



27
28
29
30
31
32
33
# File 'lib/typhoeus/request/block_connection.rb', line 27

def run
  if blocked?
    raise Typhoeus::Errors::NoStub.new(self)
  else
    super
  end
end