Class: Request::Builder::RequestConfig
- Inherits:
-
Object
- Object
- Request::Builder::RequestConfig
- Includes:
- ValueWithContext
- Defined in:
- lib/request/builder/request_config.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#stubs(value = nil, &block) ⇒ Object
readonly
Returns the value of attribute stubs.
Instance Method Summary collapse
- #[](property) ⇒ Object
- #dup ⇒ Object
- #each_header ⇒ Object
- #each_param ⇒ Object
- #header(key, value = nil, &block) ⇒ Object
-
#initialize(**params) ⇒ RequestConfig
constructor
A new instance of RequestConfig.
- #param(key, value = nil, &block) ⇒ Object
- #schema(value = nil, &block) ⇒ Object
Methods included from ValueWithContext
Constructor Details
#initialize(**params) ⇒ RequestConfig
Returns a new instance of RequestConfig.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/request/builder/request_config.rb', line 13 def initialize(**params) @body = params[:body] @host = params[:host] @path = params[:path] || '/' @method = params[:method] ||:get @request_middleware = params[:request_middleware] || :json @response_middleware = params[:response_middleware] || :json @adapter = params[:adapter] || Request::Builder.default_adapter @stubs = params[:stubs] || Faraday::Adapter::Test::Stubs.new @logger = params[:logger] @timeout = params[:timeout] || 30 @response_schema = params[:response_schema] || Dry::Schema.Params @context = nil @body = params[:body] @params = params[:params] || HashWithIndifferentAccess.new @headers = params[:headers] || HashWithIndifferentAccess.new @callbacks = params[:callbacks] || HashWithIndifferentAccess.new @proxy = params[:proxy] @ssl = params[:ssl] || {} end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
10 11 12 |
# File 'lib/request/builder/request_config.rb', line 10 def context @context end |
#stubs(value = nil, &block) ⇒ Object (readonly)
Returns the value of attribute stubs.
10 11 12 |
# File 'lib/request/builder/request_config.rb', line 10 def stubs @stubs end |
Instance Method Details
#[](property) ⇒ Object
98 99 100 |
# File 'lib/request/builder/request_config.rb', line 98 def [] property instance_variable_get("@#{property}".to_sym) end |
#dup ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/request/builder/request_config.rb', line 102 def dup Request::Builder::RequestConfig.new( body: @body.dup, host: @host.dup, path: @path.dup, method: @method, request_middleware: @request_middleware, response_middleware: @response_middleware, adapter: @adapter, stubs: @stubs, logger: @logger, timeout: @timeout, response_schema: @response_schema, body: @body.dup, params: @params.dup, headers: @headers.dup, callbacks: @callbacks.dup, proxy: @proxy.dup, ssl: @ssl.dup ) end |
#each_header ⇒ Object
86 87 88 89 90 |
# File 'lib/request/builder/request_config.rb', line 86 def each_header headers.each do |key, value| yield key, value_with_context(value) end end |
#each_param ⇒ Object
92 93 94 95 96 |
# File 'lib/request/builder/request_config.rb', line 92 def each_param params.each do |key, value| yield key, value_with_context(value) end end |
#header(key, value = nil, &block) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/request/builder/request_config.rb', line 70 def header(key, value = nil, &block) if value.nil? && block.nil? value_with_context(headers[key]) else headers[key] = block || value end end |
#param(key, value = nil, &block) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/request/builder/request_config.rb', line 78 def param(key, value = nil, &block) if value.nil? && block.nil? value_with_context(params[key]) else params[key] = block || value end end |
#schema(value = nil, &block) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/request/builder/request_config.rb', line 60 def schema(value = nil, &block) if block_given? @response_schema = Dry::Schema.Params(&block) elsif value @response_schema = value else @response_schema end end |