request-builder 0.1.115 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0aeab800037782c3d71136146a447705d471b8cfa8a2bba2461ecbd157af7ca4
4
- data.tar.gz: b417f235d042e847817ad4f733c0f99783358e1fc78d528199f3836a7ddb207b
3
+ metadata.gz: e110bc438cf71ea590974b59776f31f98a83f813aa0a6ec71b4d89dc6270b0c0
4
+ data.tar.gz: a9b9b7561de2f5c881eb79e2b4c616bb44a97251a76f022712fc4368a91b4175
5
5
  SHA512:
6
- metadata.gz: 020b0311138c359c007f736158dc3a6b7a550f95b59e0e490421b21f3926dbc0c61a27aac9daddb520ed50ce4faeef62cb8c9e3aebdb43f9656e366fff2926dc
7
- data.tar.gz: 89813f649c084295e3bb33853663272c620b4c840ce35f0c7eaae3ea10f8623d5a744b6c4d65a2107730647e3d8f3120778291e6da91c1a5acf8824c60e711b8
6
+ metadata.gz: 067b073a76fc2b3f075e911b063fc27fef20c824013829757925856e33b7bf1c6b3b5307862e152c39e2e85fb035b2ece4c884be9b87152a5ffbfe375cae680a
7
+ data.tar.gz: '04238bd2df8e87d966a8267162ad140228391aacda7d5de3de50f6d4a543bc58eaa80e010f2aa644722bf365c3ddee383739d194f97026c0f1e56ac49bca381b'
@@ -11,12 +11,12 @@ module Request
11
11
  end
12
12
 
13
13
  module ClassMethods
14
- def config
15
- @config ||= RequestConfig.new
14
+ def config(conf=nil)
15
+ @config ||= conf.deep_dup || RequestConfig.new
16
16
  end
17
17
 
18
18
  def configure(conf = nil, &block)
19
- @config = conf.dup if conf
19
+ config(conf)
20
20
 
21
21
  config.instance_eval(&block) if block
22
22
  end
@@ -7,28 +7,26 @@ module Request
7
7
 
8
8
  attrs = [:params, :callbacks, :headers, :body, :host, :path, :method, :request_middleware, :response_middleware, :adapter, :logger, :timeout]
9
9
 
10
- attr_reader :context, :body_conf, :headers_conf, :params_conf, :callbacks_conf, :stubs
10
+ attr_reader :context, :stubs
11
11
  attr_writer *attrs, :stubs, :context
12
12
 
13
- alias callbacks callbacks_conf
14
-
15
- def initialize
16
- @body = nil
17
- @host = nil
18
- @path = '/'
19
- @method = :get
20
- @request_middleware = :json
21
- @response_middleware = :json
22
- @adapter = Request::Builder.default_adapter
23
- @stubs = Faraday::Adapter::Test::Stubs.new
24
- @logger = nil
25
- @timeout = 30
26
- @body = nil
27
- @response_schema = Dry::Schema.Params
28
- @headers = HashWithIndifferentAccess.new
29
- @params = HashWithIndifferentAccess.new
30
- @callbacks = HashWithIndifferentAccess.new
13
+ def initialize(**params)
14
+ @body = params[:body]
15
+ @host = params[:host]
16
+ @path = params[:path] || '/'
17
+ @method = params[:method] ||:get
18
+ @request_middleware = params[:request_middleware] || :json
19
+ @response_middleware = params[:response_middleware] || :json
20
+ @adapter = params[:adapter] || Request::Builder.default_adapter
21
+ @stubs = params[:stubs] || Faraday::Adapter::Test::Stubs.new
22
+ @logger = params[:logger]
23
+ @timeout = params[:timeout] || 30
24
+ @response_schema = params[:response_schema] || Dry::Schema.Params
31
25
  @context = nil
26
+ @body = params[:body]
27
+ @params = params[:params] || HashWithIndifferentAccess.new
28
+ @headers = params[:headers] || HashWithIndifferentAccess.new
29
+ @callbacks = params[:callbacks] || HashWithIndifferentAccess.new
32
30
  end
33
31
 
34
32
  attrs.each do |attr|
@@ -43,7 +41,7 @@ module Request
43
41
 
44
42
  [:before_validate].each do |name|
45
43
  define_method name do |&block|
46
- @callbacks[name] = block
44
+ callbacks[name] = block
47
45
  end
48
46
  end
49
47
 
@@ -69,28 +67,28 @@ module Request
69
67
 
70
68
  def header(key, value = nil, &block)
71
69
  if value.nil? && block.nil?
72
- value_with_context(@headers[key])
70
+ value_with_context(headers[key])
73
71
  else
74
- @headers[key] = block || value
72
+ headers[key] = block || value
75
73
  end
76
74
  end
77
75
 
78
76
  def param(key, value = nil, &block)
79
77
  if value.nil? && block.nil?
80
- value_with_context(@params[key])
78
+ value_with_context(params[key])
81
79
  else
82
- @params[key] = block || value
80
+ params[key] = block || value
83
81
  end
84
82
  end
85
83
 
86
84
  def each_header
87
- @headers.each do |key, value|
85
+ headers.each do |key, value|
88
86
  yield key, value_with_context(value)
89
87
  end
90
88
  end
91
89
 
92
90
  def each_param
93
- @params.each do |key, value|
91
+ params.each do |key, value|
94
92
  yield key, value_with_context(value)
95
93
  end
96
94
  end
@@ -99,6 +97,26 @@ module Request
99
97
  instance_variable_get("@#{property}".to_sym)
100
98
  end
101
99
 
100
+ def dup
101
+ Request::Builder::RequestConfig.new(
102
+ body: @body.dup,
103
+ host: @host.dup,
104
+ path: @path.dup,
105
+ method: @method,
106
+ request_middleware: @request_middleware,
107
+ response_middleware: @response_middleware,
108
+ adapter: @adapter,
109
+ stubs: @stubs,
110
+ logger: @logger,
111
+ timeout: @timeout,
112
+ response_schema: @response_schema,
113
+ body: @body.dup,
114
+ params: @params.dup,
115
+ headers: @headers.dup,
116
+ callbacks: @callbacks.dup
117
+ )
118
+ end
119
+
102
120
  Module.new do
103
121
  singleton_class.send :define_method, :included do |host_class|
104
122
  host_class.extend class_methods
@@ -1,5 +1,5 @@
1
1
  module Request
2
2
  module Builder
3
- VERSION = "0.1.115"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.115
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Kostyuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-26 00:00:00.000000000 Z
11
+ date: 2022-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday