Module: SeaShanty
- Defined in:
- lib/sea_shanty/response.rb,
lib/sea_shanty.rb,
lib/sea_shanty/errors.rb,
lib/sea_shanty/request.rb,
lib/sea_shanty/version.rb,
lib/sea_shanty/util/logger.rb,
lib/sea_shanty/configuration.rb,
lib/sea_shanty/request_store.rb,
lib/sea_shanty/faraday/middleware.rb,
lib/sea_shanty/request_serializer.rb,
lib/sea_shanty/faraday/interceptor.rb,
lib/sea_shanty/faraday/rack_builder.rb
Overview
frozen_literal_string: true
Defined Under Namespace
Modules: Faraday
Classes: Configuration, ConfigurationError, Error, Logger, Request, RequestSerializer, RequestStore, Response, UnknownInterceptor, UnknownRequest
Constant Summary
collapse
- TRUE_VALUES =
%w[1 yes y true]
- VERSION =
"0.2.0"
Class Method Summary
collapse
Class Method Details
.configuration ⇒ Object
13
14
15
|
# File 'lib/sea_shanty.rb', line 13
def configuration
@configuration ||= Configuration.new
end
|
.configuration_overwrite(env_var, value) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/sea_shanty.rb', line 67
def configuration_overwrite(env_var, value)
if env_var.nil? || env_var.empty?
value
else
TRUE_VALUES.include?(env_var.downcase)
end
end
|
17
18
19
20
21
22
|
# File 'lib/sea_shanty.rb', line 17
def configure(&block)
yield configuration
configuration.bypass = configuration_overwrite(ENV["SEA_SHANTY_BYPASS"], configuration.bypass)
configuration.readonly = configuration_overwrite(ENV["SEA_SHANTY_READONLY"], configuration.readonly)
end
|
.intercept(identifier) ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/sea_shanty.rb', line 24
def intercept(identifier)
return if intercepting.include?(identifier)
interceptors.fetch(identifier).intercept!(request_store)
intercepting << identifier
rescue KeyError
raise(
UnknownInterceptor,
"Cannot find an interceptor for #{identifier}. Available interceptors are: [#{interceptors.keys.join(", ")}]"
)
end
|
.intercepting ⇒ Object
35
36
37
|
# File 'lib/sea_shanty.rb', line 35
def intercepting
@intercepting ||= []
end
|
.interceptors ⇒ Object
39
40
41
|
# File 'lib/sea_shanty.rb', line 39
def interceptors
@interceptors ||= {}
end
|
.register_interceptor(identifier, interceptor) ⇒ Object
43
44
45
|
# File 'lib/sea_shanty.rb', line 43
def register_interceptor(identifier, interceptor)
interceptors[identifier] = interceptor
end
|
.remove(identifier) ⇒ Object
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/sea_shanty.rb', line 47
def remove(identifier)
return unless intercepting.include?(identifier)
interceptors.fetch(identifier).remove
intercepting.delete(identifier)
rescue KeyError
raise(
UnknownInterceptor,
"Cannot find an interceptor for #{identifier}. Available interceptors are: [#{interceptors.keys.join(", ")}]"
)
end
|
.request_store ⇒ Object
58
59
60
|
# File 'lib/sea_shanty.rb', line 58
def request_store
RequestStore.new(configuration)
end
|
.reset! ⇒ Object
62
63
64
65
|
# File 'lib/sea_shanty.rb', line 62
def reset!
@configuration = Configuration.new
configure {}
end
|