Module: HttpVanilli::NetHttp
- Defined in:
- lib/http_vanilli/net_http/util.rb,
lib/http_vanilli/net_http/stubs.rb,
lib/http_vanilli/net_http/request.rb,
lib/http_vanilli/net_http/override.rb,
lib/http_vanilli/net_http/response.rb
Defined Under Namespace
Modules: ResponseMixin, YieldResponse
Classes: Request, Response, StubSocket
Class Method Summary
collapse
Class Method Details
.override! ⇒ Object
11
12
13
14
|
# File 'lib/http_vanilli/net_http/override.rb', line 11
def self.override!
record_loaded_net_http_replacement_libs
puts_warning_for_net_http_around_advice_libs_if_needed
end
|
.puts_warning_for_net_http_around_advice_libs_if_needed ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/http_vanilli/net_http/util.rb', line 3
def self.puts_warning_for_net_http_around_advice_libs_if_needed
libs = {"Samuel" => defined?(Samuel)}
warnings = libs.select { |_, loaded| loaded }.map do |name, _|
<<-TEXT.gsub(/ {10}/, '')
\e[1mWarning: HttpVanilli was loaded after #{name}\e[0m
* #{name}'s code is being ignored when a request is handled by HttpVanilli::NetHttp,
because both libraries work by patching Net::HTTP.
* To fix this, just reorder your requires so that HttpVanilli is before #{name}.
TEXT
end
$stderr.puts "\n" + warnings.join("\n") + "\n" if warnings.any?
end
|
.puts_warning_for_net_http_replacement_libs_if_needed ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/http_vanilli/net_http/util.rb', line 21
def self.puts_warning_for_net_http_replacement_libs_if_needed
libs = {"RightHttpConnection" => defined?(RightHttpConnection)}
warnings = libs.select { |_, loaded| loaded }.
reject { |name, _| @loaded_net_http_replacement_libs.include?(name) }.
map do |name, _|
<<-TEXT.gsub(/ {10}/, '')
\e[1mWarning: #{name} was loaded after HttpVanilli::NetHttp\e[0m
* HttpVanilli's code is being ignored, because #{name} replaces parts of
Net::HTTP without deferring to other libraries. This will break Net::HTTP requests.
* To fix this, just reorder your requires so that #{name} is before HttpVanilli.
TEXT
end
$stderr.puts "\n" + warnings.join("\n") + "\n" if warnings.any?
end
|
.record_loaded_net_http_replacement_libs ⇒ Object
16
17
18
19
|
# File 'lib/http_vanilli/net_http/util.rb', line 16
def self.record_loaded_net_http_replacement_libs
libs = {"RightHttpConnection" => defined?(RightHttpConnection)}
@loaded_net_http_replacement_libs = libs.map { |name, loaded| name if loaded }.compact
end
|