class EventStore::HTTP::NetHTTP::Substitute
Attributes
active[RW]
error[RW]
Public Class Methods
build()
click to toggle source
# File lib/event_store/http/net_http/substitute.rb, line 16 def self.build telemetry_sink = Telemetry::Sink.new instance = new telemetry_sink telemetry = ::Telemetry.configure instance telemetry.register telemetry_sink instance end
Public Instance Methods
active?()
click to toggle source
# File lib/event_store/http/net_http/substitute.rb, line 10 def active? @active.nil? ? false : @active end
build_response(status_code, reason_phrase: nil, body: nil, headers: nil)
click to toggle source
# File lib/event_store/http/net_http/substitute.rb, line 69 def build_response(status_code, reason_phrase: nil, body: nil, headers: nil) reason_phrase ||= 'None' headers ||= {} body ||= '' response_cls = Net::HTTPResponse::CODE_TO_OBJ.fetch status_code.to_s do case status_code when (200...300) then Net::HTTPSuccess when (300...400) then Net::HTTPRedirection when (400...500) then Net::HTTPClientError when (500...600) then Net::HTTPServerError end end response = response_cls.new '1.1', status_code.to_s, reason_phrase headers.each do |name, value| response[name] = value end response.instance_exec do @read = true @body = body end response end
finish()
click to toggle source
# File lib/event_store/http/net_http/substitute.rb, line 105 def finish self.active = false end
next_response()
click to toggle source
# File lib/event_store/http/net_http/substitute.rb, line 55 def next_response return build_response 404 if responses.empty? response = responses.shift responses << response if responses.empty? response end
request(request, _=nil, &block)
click to toggle source
# File lib/event_store/http/net_http/substitute.rb, line 27 def request(request, _=nil, &block) telemetry.record :requested, Telemetry::Requested.new(request) request_headers.each do |name, value| request[name] = value end raise error if error response = next_response telemetry.record :responded, Telemetry::Responded.new(response, request) response end
request_headers()
click to toggle source
# File lib/event_store/http/net_http/substitute.rb, line 97 def request_headers @request_headers ||= {} end
responses()
click to toggle source
# File lib/event_store/http/net_http/substitute.rb, line 65 def responses @responses ||= [] end
set_error(error)
click to toggle source
# File lib/event_store/http/net_http/substitute.rb, line 43 def set_error(error) self.error = error end
set_response(*arguments)
click to toggle source
# File lib/event_store/http/net_http/substitute.rb, line 47 def set_response(*arguments) response = build_response *arguments responses << response response end
start()
click to toggle source
# File lib/event_store/http/net_http/substitute.rb, line 101 def start self.active = true end