Module: Artifice

Defined in:
lib/artifice.rb

Defined Under Namespace

Modules: Net

Constant Summary collapse

NET_HTTP =
::Net::HTTP

Class Method Summary collapse

Class Method Details

.activate_with(endpoint) { ... } ⇒ Object

Activate Artifice with a particular Rack endpoint.

Calling this method will replace the Net::HTTP system with a replacement that routes all requests to the Rack endpoint.

Parameters:

  • endpoint (#call)

    A valid Rack endpoint

Yields:

  • An optional block that uses Net::HTTP In this case, Artifice will be used only for the duration of the block



18
19
20
21
22
23
24
25
26
# File 'lib/artifice.rb', line 18

def self.activate_with(endpoint)
  Net::HTTP.endpoint = endpoint
  replace_net_http(Artifice::Net::HTTP)

  if block_given?
    yield
    deactivate
  end
end

.deactivateObject

Deactivate the Artifice replacement.



29
30
31
# File 'lib/artifice.rb', line 29

def self.deactivate
  replace_net_http(NET_HTTP)
end