ree_lib 1.0.87 → 1.0.88

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.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/ree_lib/packages/ree_http/package/ree_http/functions/execute_request.rb +27 -20
  4. data/lib/ree_lib/packages/ree_http/schemas/ree_http/functions/execute_request.schema.json +8 -0
  5. data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_delete_spec.rb +10 -8
  6. data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_get_spec.rb +79 -18
  7. data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_options_spec.rb +6 -5
  8. data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_patch_spec.rb +8 -4
  9. data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_post_spec.rb +5 -10
  10. data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_put_spec.rb +5 -3
  11. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper.rb +22 -6
  12. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/benchmarks/mapper_benchmark_spec.rb +31 -0
  13. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/bool_spec.rb +8 -8
  14. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/date_spec.rb +10 -10
  15. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/date_time_spec.rb +16 -16
  16. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/float_spec.rb +13 -13
  17. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/hash_spec.rb +2 -2
  18. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/integer_spec.rb +14 -14
  19. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/rational_spec.rb +12 -12
  20. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/string_spec.rb +12 -12
  21. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/time_spec.rb +16 -16
  22. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/type_options_spec.rb +4 -4
  23. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/wrappers/array_spec.rb +6 -6
  24. data/lib/ree_lib/version.rb +1 -1
  25. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5c70eda05d58f496b0eca7cbc95f853dd51c8b9e33b23c1fa1b51a74eb58104
4
- data.tar.gz: bf15e2be0aa79c7696ec9bfb074c3748c7061a5aec1079c5fa208aa1cbc16f1c
3
+ metadata.gz: 5617079115b4c9fb7431a6d2e81d7eb34c378173809508312b6f58de711ae0fc
4
+ data.tar.gz: e0a0dc4c0dc92bab997e1ce44b4ea7d888ab616be535f011b3e5c9dbfb66a829
5
5
  SHA512:
6
- metadata.gz: c068ce8ba9567eab38bd06c0bdc01731f223f1f4126ac70f5d49c9fc40a9e5034cb7e3cfb2fd84ef578018a31dd5934b6c9283b9a72b3d58e69bdf265af481ca
7
- data.tar.gz: e2f1b8a4428e46d27e40f98d9134d47139c5de080eef52eeee63cf5cf9eb86fb76fdc54b6d437c810f8a8d5b71889e180903ee8dce4463e82ec2f2769c3bffdf
6
+ metadata.gz: faa26811f3b74b634f7726887530bc106eea6576cf4ebc4496bba6f68f2e567c5a9511ea786396f1324a8474c539b40e64d8c12710b92e72d757b1a46727091e
7
+ data.tar.gz: 2543ee6346775abed1525a450ba6b203c09e618954092eafff0bda78d395674f3d2005b9f959abeac89bf5fdcfb9399c8b70c1bcb6ce37ddcc0b84622ddfa547
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.87)
4
+ ree_lib (1.0.88)
5
5
  bigdecimal (~> 3.1.6)
6
6
  binding_of_caller (~> 1.0.0)
7
7
  i18n (~> 1.12.0)
@@ -4,13 +4,13 @@ class ReeHttp::ExecuteRequest
4
4
  include Ree::FnDSL
5
5
 
6
6
  fn :execute_request do
7
+ link :build_request
7
8
  link :build_request_executor
8
9
  link :slice, from: :ree_hash
9
- link 'ree_http/http_exceptions', -> { HttpExceptions }
10
-
11
10
  link 'ree_http/constants', -> {
12
11
  DEFAULT_TIMEOUT & DEFAULT_WRITE_TIMEOUT & DEFAULT_FORCE_SSL
13
12
  }
13
+ link 'ree_http/http_exceptions', -> { HttpExceptions }
14
14
  end
15
15
 
16
16
  include HttpExceptions
@@ -89,7 +89,9 @@ class ReeHttp::ExecuteRequest
89
89
  "Got #{response.code} response on request URI #{request.uri}\n With BODY: #{response.body}\n"
90
90
  )
91
91
 
92
- process_redirect_response(response, request, opts, &block)
92
+ if response.is_a?(Net::HTTPRedirection)
93
+ return process_redirect_response(response, request, opts, &block)
94
+ end
93
95
 
94
96
  response
95
97
  end
@@ -97,27 +99,32 @@ class ReeHttp::ExecuteRequest
97
99
  private
98
100
 
99
101
  def process_redirect_response(response, request, opts, &block)
100
- if response.is_a?(Net::HTTPRedirection)
101
- if opts[:redirects_count] == 0
102
- raise TooManyRedirectsError, "Got too match redirects, if you want more redirects, use redirects_count"
103
- end
102
+ if opts[:redirects_count] == 0
103
+ raise TooManyRedirectsError, "Got too match redirects, if you want more redirects, use redirects_count"
104
+ end
104
105
 
105
- if opts[:strict_redirect_mode] && STRICT_SENSITIVE_CODES.include?(response.code.to_i) && UNSAFE_VERBS.include?(request.method.to_sym)
106
- raise RedirectMethodError, "Got #{response.code.to_i} with strict_mode"
107
- end
106
+ if opts[:strict_redirect_mode] && STRICT_SENSITIVE_CODES.include?(response.code.to_i) && UNSAFE_VERBS.include?(request.method.to_sym)
107
+ raise RedirectMethodError, "Got #{response.code.to_i} with strict_mode"
108
+ end
108
109
 
109
- if (ALWAYS_GET_CODES.include?(response.code.to_i) || STRICT_SENSITIVE_CODES.include?(response.code.to_i)) && UNSAFE_VERBS.include?(request.method.downcase.to_sym)
110
- request.instance_variable_set(:@method, 'GET')
111
- end
110
+ if (ALWAYS_GET_CODES.include?(response.code.to_i) || STRICT_SENSITIVE_CODES.include?(response.code.to_i)) && UNSAFE_VERBS.include?(request.method.downcase.to_sym)
111
+ new_request_method = :get
112
+ end
112
113
 
113
- request.instance_variable_set(:@uri, URI(response['Location']))
114
- request.instance_variable_set(:@path, request.uri.path)
114
+ new_request_method ||= request.method.downcase.to_sym
115
115
 
116
- opts[:redirects_count] -= 1
116
+ new_uri = URI(response['Location'] || response['location'])
117
+ new_request = build_request(
118
+ new_request_method,
119
+ new_uri.to_s,
120
+ **slice(opts, [
121
+ :headers, :body, :form_data, :query_params,
122
+ :force_ssl, :ca_certs, :basic_auth, :bearer_token
123
+ ])
124
+ )
117
125
 
118
- return call(request, **opts, &block)
119
- end
126
+ opts[:redirects_count] -= 1
120
127
 
121
- response
128
+ call(new_request, **opts, &block)
122
129
  end
123
- end
130
+ end
@@ -34,6 +34,14 @@
34
34
  }
35
35
  ],
36
36
  "links": [
37
+ {
38
+ "target": "build_request",
39
+ "package_name": "ree_http",
40
+ "as": "build_request",
41
+ "imports": [
42
+
43
+ ]
44
+ },
37
45
  {
38
46
  "target": "build_request_executor",
39
47
  "package_name": "ree_http",
@@ -129,11 +129,11 @@ RSpec.describe :http_delete do
129
129
  headers: {
130
130
  'Accept'=>'*/*',
131
131
  'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
132
- 'User-Agent'=>'Ruby',
133
- 'Token'=>'123'
132
+ 'Host' => 'www.example.com',
133
+ 'User-Agent'=>'Ruby'
134
134
  }
135
135
  )
136
- .to_return(status: 200, headers: {'Token': '123'})
136
+ .to_return(status: 200)
137
137
  end
138
138
  after :all do
139
139
  WebMock.reset!
@@ -142,7 +142,7 @@ RSpec.describe :http_delete do
142
142
  let(:err_result) {
143
143
  http_delete(
144
144
  host_with_ssl + '/redirect_303_infinity',
145
- force_ssl: true, headers: { token: '123'}
145
+ force_ssl: true
146
146
  )
147
147
  }
148
148
 
@@ -151,15 +151,17 @@ RSpec.describe :http_delete do
151
151
 
152
152
  http_delete(
153
153
  host_with_ssl + '/redirect_307',
154
- force_ssl: true, headers: { token: '123'}
154
+ force_ssl: true, headers: { "Token" => 123 }
155
155
  )
156
- expect(WebMock).to have_requested(:delete, host_with_ssl).with(headers: { 'Token'=>'123' })
156
+ expect(WebMock).to have_requested(:delete, host_with_ssl + "/redirect_307").with(headers: { "Token" => 123}).once
157
+ expect(WebMock).to have_requested(:delete, host_with_ssl).once
157
158
 
158
159
  http_delete(
159
160
  host_with_ssl + '/redirect_303',
160
- force_ssl: true, headers: { token: '123'}
161
+ force_ssl: true, headers: { "Token" => 123 }
161
162
  )
162
- expect(WebMock).to have_requested(:get, host_with_ssl).with(headers: { 'Token'=>'123' })
163
+ expect(WebMock).to have_requested(:delete, host_with_ssl + "/redirect_303").with(headers: { "Token" => 123}).once
164
+ expect(WebMock).to have_requested(:get, host_with_ssl).once
163
165
  end
164
166
  end
165
167
  end
@@ -38,7 +38,7 @@ RSpec.describe :http_get do
38
38
 
39
39
  http_get(
40
40
  host,
41
- basic_auth: {username: 'user', password: 'pass'}
41
+ basic_auth: { username: 'user', password: 'pass' }
42
42
  )
43
43
  expect(WebMock).to have_requested(:get, host).with(basic_auth: ['user', 'pass'])
44
44
 
@@ -50,20 +50,20 @@ RSpec.describe :http_get do
50
50
 
51
51
  http_get(
52
52
  host,
53
- query_params: { q: 100, "s"=> 'simple'}
53
+ query_params: { q: 100, "s"=> 'simple' }
54
54
  )
55
- expect(WebMock).to have_requested(:get, host).with(query: { "q"=> 100, "s"=> "simple"})
55
+ expect(WebMock).to have_requested(:get, host).with(query: { "q"=> 100, "s"=> "simple" })
56
56
 
57
57
  http_get(
58
58
  host_with_path + '?a=200',
59
- query_params: { q: 100, "s"=> 'simple'}
59
+ query_params: { q: 100, "s"=> 'simple' }
60
60
  )
61
- expect(WebMock).to have_requested(:get, host_with_path).with(query: {"a"=>200, "q"=> 100, "s"=> "simple"})
61
+
62
+ expect(WebMock).to have_requested(:get, host_with_path).with(query: { "a"=>200, "q"=> 100, "s"=> "simple" })
62
63
  end
63
64
  end
64
65
 
65
66
  context "force ssl" do
66
-
67
67
  before :all do
68
68
  WebMock.reset!
69
69
  WebMock
@@ -84,6 +84,7 @@ RSpec.describe :http_get do
84
84
  host,
85
85
  force_ssl: true, headers: { token: '321'}
86
86
  )
87
+
87
88
  expect(WebMock).to have_requested(:get, host_with_ssl).with(headers: { 'Token'=>'321' })
88
89
  end
89
90
  end
@@ -100,7 +101,7 @@ RSpec.describe :http_get do
100
101
  'User-Agent'=>'Ruby',
101
102
  }
102
103
  )
103
- .to_return(status: 307, headers: {'Location': 'https://www.example.com/'})
104
+ .to_return(status: 307, headers: { 'Location': 'https://www.example.com/' })
104
105
 
105
106
  WebMock
106
107
  .stub_request(:get, 'https://www.example.com/redirect_303')
@@ -111,7 +112,51 @@ RSpec.describe :http_get do
111
112
  'User-Agent'=>'Ruby',
112
113
  }
113
114
  )
114
- .to_return(status: 303, headers: {'Location': 'https://www.example.com/'})
115
+ .to_return(status: 303, headers: { 'Location': 'https://www.example.com/' })
116
+
117
+ WebMock
118
+ .stub_request(:any, 'https://domain.com')
119
+ .with(
120
+ headers: {
121
+ 'Accept'=>'*/*',
122
+ 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
123
+ 'User-Agent'=>'Ruby',
124
+ }
125
+ )
126
+ .to_return(status: 302, headers: { 'Location': 'https://www.domain.com' })
127
+
128
+ WebMock
129
+ .stub_request(:any, 'https://www.domain.com')
130
+ .with(
131
+ headers: {
132
+ 'Accept'=>'*/*',
133
+ 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
134
+ 'User-Agent'=>'Ruby',
135
+ }
136
+ )
137
+ .to_return(status: 200, headers: {})
138
+
139
+ WebMock
140
+ .stub_request(:any, 'https://www.anotherdomain.com')
141
+ .with(
142
+ headers: {
143
+ 'Accept'=>'*/*',
144
+ 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
145
+ 'User-Agent'=>'Ruby',
146
+ }
147
+ )
148
+ .to_return(status: 302, headers: { 'Location': 'https://sub.anotherdomain.com' })
149
+
150
+ WebMock
151
+ .stub_request(:any, 'https://sub.anotherdomain.com')
152
+ .with(
153
+ headers: {
154
+ 'Accept'=>'*/*',
155
+ 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
156
+ 'User-Agent'=>'Ruby',
157
+ }
158
+ )
159
+ .to_return(status: 200, headers: {})
115
160
 
116
161
  WebMock
117
162
  .stub_request(:any, 'https://www.example.com/redirect_303_infinity')
@@ -122,7 +167,7 @@ RSpec.describe :http_get do
122
167
  'User-Agent'=>'Ruby',
123
168
  }
124
169
  )
125
- .to_return(status: 303, headers: {'Location': 'https://www.example.com/redirect_303_infinity'})
170
+ .to_return(status: 303, headers: { 'Location': 'https://www.example.com/redirect_303_infinity' })
126
171
 
127
172
  WebMock
128
173
  .stub_request(:any, 'https://www.example.com/')
@@ -130,36 +175,52 @@ RSpec.describe :http_get do
130
175
  headers: {
131
176
  'Accept'=>'*/*',
132
177
  'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
133
- 'User-Agent'=>'Ruby',
134
- 'Token'=>'123'
178
+ 'Host' => 'www.example.com',
179
+ 'User-Agent'=>'Ruby'
135
180
  }
136
181
  )
137
- .to_return(status: 200, headers: {'Token': '123'})
182
+ .to_return(status: 200, headers: { 'Token': '123' })
138
183
  end
184
+
139
185
  after :all do
140
186
  WebMock.reset!
141
187
  end
188
+
142
189
  include ReeHttp::HttpExceptions
190
+
143
191
  let(:err_result) {
144
192
  http_get(
145
- host_with_ssl + '/redirect_303_infinity',
193
+ 'https://www.example.com/redirect_303_infinity',
146
194
  force_ssl: true, headers: { token: '123'}
147
195
  )
148
196
  }
149
197
 
150
198
  it do
151
- expect{err_result}.to raise_error(ReeHttp::HttpExceptions::TooManyRedirectsError)
199
+ expect{ err_result }.to raise_error(ReeHttp::HttpExceptions::TooManyRedirectsError)
152
200
 
153
201
  http_get(
154
- host_with_ssl + '/redirect_307',
155
- force_ssl: true, headers: { token: '123'}
202
+ "https://domain.com",
203
+ force_ssl: true
156
204
  )
157
205
 
206
+ expect(WebMock).to have_requested(:get, "https://domain.com").once
207
+ expect(WebMock).to have_requested(:get, "https://www.domain.com").once
208
+
158
209
  http_get(
159
- host_with_ssl + '/redirect_303',
210
+ "https://www.anotherdomain.com",
211
+ force_ssl: true
212
+ )
213
+
214
+ expect(WebMock).to have_requested(:get, "https://www.anotherdomain.com").once
215
+ expect(WebMock).to have_requested(:get, "https://sub.anotherdomain.com").once
216
+
217
+ http_get(
218
+ host_with_ssl + '/redirect_307',
160
219
  force_ssl: true, headers: { token: '123'}
161
220
  )
162
- expect(WebMock).to have_requested(:get, host_with_ssl).with(headers: { 'Token'=>'123' }).twice
221
+
222
+ expect(WebMock).to have_requested(:get, 'https://www.example.com/redirect_307').with(headers: { token: '123'}).once
223
+ expect(WebMock).to have_requested(:get, 'https://www.example.com').once
163
224
  end
164
225
  end
165
226
  end
@@ -148,10 +148,10 @@ RSpec.describe :http_options do
148
148
  'Accept'=>'*/*',
149
149
  'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
150
150
  'User-Agent'=>'Ruby',
151
- 'Token'=>'123'
151
+ 'Host' => 'www.example.com'
152
152
  }
153
153
  )
154
- .to_return(status: 200, headers: {'Token': '123'})
154
+ .to_return(status: 200)
155
155
  end
156
156
  after :all do
157
157
  WebMock.reset!
@@ -171,14 +171,15 @@ RSpec.describe :http_options do
171
171
  host_with_ssl + '/redirect_307',
172
172
  force_ssl: true, headers: { token: '123'}
173
173
  )
174
- expect(WebMock).to have_requested(:options, host_with_ssl).with(headers: { 'Token'=>'123' })
174
+ expect(WebMock).to have_requested(:options, host_with_ssl + '/redirect_307').with(headers: { 'Token'=>'123' }).once
175
+ expect(WebMock).to have_requested(:options, host_with_ssl).once
175
176
 
176
177
  http_options(
177
178
  host_with_ssl + '/redirect_303',
178
179
  force_ssl: true, headers: { token: '123'}
179
180
  )
180
- expect(WebMock).to have_requested(:get, host_with_ssl).with(headers: { 'Token'=>'123' })
181
+ expect(WebMock).to have_requested(:options, host_with_ssl + '/redirect_303').with(headers: { 'Token'=>'123' })
182
+ expect(WebMock).to have_requested(:get, host_with_ssl).once
181
183
  end
182
184
  end
183
185
  end
184
-
@@ -141,10 +141,10 @@ RSpec.describe :http_patch do
141
141
  'Accept'=>'*/*',
142
142
  'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
143
143
  'User-Agent'=>'Ruby',
144
- 'Token'=>'123'
144
+ 'Host' => 'www.example.com'
145
145
  }
146
146
  )
147
- .to_return(status: 200, headers: {'Token': '123'})
147
+ .to_return(status: 200)
148
148
  end
149
149
  after :all do
150
150
  WebMock.reset!
@@ -164,13 +164,17 @@ RSpec.describe :http_patch do
164
164
  host_with_ssl + '/redirect_307',
165
165
  force_ssl: true, headers: { token: '123'}
166
166
  )
167
- expect(WebMock).to have_requested(:patch, host_with_ssl).with(headers: { 'Token'=>'123' })
167
+
168
+ expect(WebMock).to have_requested(:patch, host_with_ssl + '/redirect_307').with(headers: { 'Token'=>'123' }).once
169
+ expect(WebMock).to have_requested(:patch, host_with_ssl).once
168
170
 
169
171
  http_patch(
170
172
  host_with_ssl + '/redirect_303',
171
173
  force_ssl: true, headers: { token: '123'}
172
174
  )
173
- expect(WebMock).to have_requested(:get, host_with_ssl).with(headers: { 'Token'=>'123' })
175
+
176
+ expect(WebMock).to have_requested(:patch, host_with_ssl + '/redirect_303').with(headers: { 'Token'=>'123' }).once
177
+ expect(WebMock).to have_requested(:get, host_with_ssl).once
174
178
  end
175
179
  end
176
180
  end
@@ -90,13 +90,6 @@ RSpec.describe :http_post do
90
90
  ensure
91
91
  tempfile&.close!
92
92
  end
93
-
94
- # works !
95
- # response = http_post(
96
- # 'http://127.0.0.1:8085/end',
97
- # query_params: { q: 100, "s"=> 'simple'},
98
- # form_data: {arg: "abc"}
99
- # )
100
93
  end
101
94
  end
102
95
 
@@ -169,7 +162,7 @@ RSpec.describe :http_post do
169
162
  'Accept'=>'*/*',
170
163
  'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
171
164
  'User-Agent'=>'Ruby',
172
- 'Token'=>'123'
165
+ 'Host'=>'www.example.com'
173
166
  }
174
167
  )
175
168
  .to_return(status: 200, headers: {'Token': '123'})
@@ -192,13 +185,15 @@ RSpec.describe :http_post do
192
185
  host_with_ssl + '/redirect_307',
193
186
  force_ssl: true, headers: { token: '123'}
194
187
  )
195
- expect(WebMock).to have_requested(:post, host_with_ssl).with(headers: { 'Token'=>'123' })
188
+ expect(WebMock).to have_requested(:post, host_with_ssl + "/redirect_307").with(headers: { 'Token'=>'123' }).once
189
+ expect(WebMock).to have_requested(:post, host_with_ssl).once
196
190
 
197
191
  http_post(
198
192
  host_with_ssl + '/redirect_303',
199
193
  force_ssl: true, headers: { token: '123'}
200
194
  )
201
- expect(WebMock).to have_requested(:get, host_with_ssl).with(headers: { 'Token'=>'123' })
195
+ expect(WebMock).to have_requested(:post, host_with_ssl + "/redirect_303").with(headers: { 'Token'=>'123' }).once
196
+ expect(WebMock).to have_requested(:get, host_with_ssl).once
202
197
  end
203
198
  end
204
199
  end
@@ -141,7 +141,7 @@ RSpec.describe :http_put do
141
141
  'Accept'=>'*/*',
142
142
  'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
143
143
  'User-Agent'=>'Ruby',
144
- 'Token'=>'123'
144
+ 'Host' => 'www.example.com'
145
145
  }
146
146
  )
147
147
  .to_return(status: 200, headers: {'Token': '123'})
@@ -164,13 +164,15 @@ RSpec.describe :http_put do
164
164
  host_with_ssl + '/redirect_307',
165
165
  force_ssl: true, headers: { token: '123'}
166
166
  )
167
- expect(WebMock).to have_requested(:put, host_with_ssl).with(headers: { 'Token'=>'123' })
167
+ expect(WebMock).to have_requested(:put, host_with_ssl + '/redirect_307').with(headers: { 'Token'=>'123' }).once
168
+ expect(WebMock).to have_requested(:put, host_with_ssl).once
168
169
 
169
170
  http_put(
170
171
  host_with_ssl + '/redirect_303',
171
172
  force_ssl: true, headers: { token: '123'}
172
173
  )
173
- expect(WebMock).to have_requested(:get, host_with_ssl).with(headers: { 'Token'=>'123' })
174
+ expect(WebMock).to have_requested(:put, host_with_ssl + '/redirect_303').with(headers: { 'Token'=>'123' }).once
175
+ expect(WebMock).to have_requested(:get, host_with_ssl).once
174
176
  end
175
177
  end
176
178
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ReeMapper::Mapper
4
+ EMPTY_ARY = [].freeze
5
+
4
6
  contract(
5
7
  ArrayOf[ReeMapper::MapperStrategy],
6
8
  Nilor[ReeMapper::AbstractType, ReeMapper::AbstractWrapper] => self
@@ -23,7 +25,7 @@ class ReeMapper::Mapper
23
25
 
24
26
  if type
25
27
  class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
26
- def #{method}(obj, name: nil, role: nil, only: nil, except: nil, fields_filters: [], location: nil)
28
+ def #{method}(obj, name: nil, role: nil, only: nil, except: nil, fields_filters: EMPTY_ARY, location: nil)
27
29
  #{
28
30
  if type.is_a?(ReeMapper::AbstractWrapper)
29
31
  "@type.#{method}(obj, name: name, role: role, fields_filters: fields_filters, location: location)"
@@ -35,7 +37,7 @@ class ReeMapper::Mapper
35
37
  RUBY
36
38
  else
37
39
  class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
38
- def #{method}(obj, name: nil, role: nil, only: nil, except: nil, fields_filters: [], location: nil)
40
+ def #{method}(obj, name: nil, role: nil, only: nil, except: nil, fields_filters: EMPTY_ARY, location: nil)
39
41
  if only && !ReeMapper::FilterFieldsContract.valid?(only)
40
42
  raise ReeMapper::ArgumentError, "Invalid `only` format"
41
43
  end
@@ -47,7 +49,11 @@ class ReeMapper::Mapper
47
49
  user_fields_filter = ReeMapper::FieldsFilter.build(only: only, except: except)
48
50
 
49
51
  @fields.each_with_object(@#{method}_strategy.build_object) do |(_, field), acc|
50
- field_fields_filters = fields_filters + [user_fields_filter]
52
+ field_fields_filters = if user_fields_filter == ReeMapper::FieldsFilter::NoneStrategy
53
+ fields_filters
54
+ else
55
+ fields_filters + [user_fields_filter]
56
+ end
51
57
 
52
58
  next unless field_fields_filters.all? { _1.allow? field.name }
53
59
  next unless field.has_role?(role)
@@ -56,7 +62,10 @@ class ReeMapper::Mapper
56
62
  is_optional = field.optional || @#{method}_strategy.always_optional
57
63
 
58
64
  if !is_with_value && !is_optional
59
- raise ReeMapper::TypeError.new("Missing required field `\#{field.from_as_str}` for `\#{name || 'root'}`", field.location)
65
+ raise ReeMapper::TypeError.new(
66
+ "Missing required field `\#{field.from_as_str}` for `\#{name || 'root'}`",
67
+ field.location
68
+ )
60
69
  end
61
70
 
62
71
  next if !is_with_value && !field.has_default?
@@ -70,8 +79,15 @@ class ReeMapper::Mapper
70
79
  unless value.nil? && field.null
71
80
  nested_name = name ? "\#{name}[\#{field.name_as_str}]" : field.name_as_str
72
81
 
73
- nested_fields_filters = field_fields_filters.map { _1.filter_for(field.name) }
74
- nested_fields_filters += [field.fields_filter]
82
+ nested_fields_filters = if field_fields_filters.empty?
83
+ field_fields_filters
84
+ else
85
+ field_fields_filters.map { _1.filter_for(field.name) }
86
+ end
87
+
88
+ if field.fields_filter != ReeMapper::FieldsFilter::NoneStrategy
89
+ nested_fields_filters += [field.fields_filter]
90
+ end
75
91
 
76
92
  value = field.type.#{method}(
77
93
  value,
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ require 'benchmark'
3
+
4
+ package_require "ree_mapper"
5
+
6
+ RSpec.xdescribe 'Mapper Benchmark' do
7
+ link :build_mapper_factory, from: :ree_mapper
8
+ link :build_mapper_strategy, from: :ree_mapper
9
+
10
+ let(:mapper) do
11
+ build_mapper_factory(
12
+ strategies: [
13
+ build_mapper_strategy(method: :cast, dto: Hash),
14
+ ]
15
+ ).call.use(:cast) do
16
+ hash :my_field do
17
+ hash :my_field do
18
+ integer :my_field
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ it do
25
+ obj = { my_field: { my_field: { my_field: 1 } } }
26
+
27
+ _benchmark_res = Benchmark.bmbm do |x|
28
+ x.report('cast') { 1000.times { mapper.cast(obj) } }
29
+ end
30
+ end
31
+ end
@@ -31,11 +31,11 @@ RSpec.describe 'ReeMapper::Bool' do
31
31
  }
32
32
 
33
33
  it {
34
- expect { mapper.serialize({ bool: 'true' }) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean, got `\"true\"`")
34
+ expect { mapper.serialize({ bool: 'true' }) }.to raise_error(ReeMapper::TypeError, /`bool` should be a boolean, got `\"true\"`/)
35
35
  }
36
36
 
37
37
  it {
38
- expect { mapper.serialize({ bool: 1 }) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean, got `1`")
38
+ expect { mapper.serialize({ bool: 1 }) }.to raise_error(ReeMapper::TypeError, /`bool` should be a boolean, got `1`/)
39
39
  }
40
40
  end
41
41
 
@@ -81,12 +81,12 @@ RSpec.describe 'ReeMapper::Bool' do
81
81
  }
82
82
 
83
83
  it {
84
- expect { mapper.cast({ 'bool' => 'right' }) }.to raise_error(ReeMapper::CoercionError, "`bool` is invalid boolean, got `\"right\"`")
84
+ expect { mapper.cast({ 'bool' => 'right' }) }.to raise_error(ReeMapper::CoercionError, /`bool` is invalid boolean, got `\"right\"`/)
85
85
  }
86
86
 
87
87
  it {
88
88
  object = Object.new
89
- expect { mapper.cast({ 'bool' => object }) }.to raise_error(ReeMapper::CoercionError, "`bool` is invalid boolean, got `#{object.inspect}`")
89
+ expect { mapper.cast({ 'bool' => object }) }.to raise_error(ReeMapper::CoercionError, /`bool` is invalid boolean, got `#{object.inspect}`/)
90
90
  }
91
91
  end
92
92
 
@@ -100,11 +100,11 @@ RSpec.describe 'ReeMapper::Bool' do
100
100
  }
101
101
 
102
102
  it {
103
- expect { mapper.db_dump(OpenStruct.new({ bool: 'true' })) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean, got `\"true\"`")
103
+ expect { mapper.db_dump(OpenStruct.new({ bool: 'true' })) }.to raise_error(ReeMapper::TypeError, /`bool` should be a boolean, got `\"true\"`/)
104
104
  }
105
105
 
106
106
  it {
107
- expect { mapper.db_dump(OpenStruct.new({ bool: 1 })) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean, got `1`")
107
+ expect { mapper.db_dump(OpenStruct.new({ bool: 1 })) }.to raise_error(ReeMapper::TypeError, /`bool` should be a boolean, got `1`/)
108
108
  }
109
109
  end
110
110
 
@@ -150,12 +150,12 @@ RSpec.describe 'ReeMapper::Bool' do
150
150
  }
151
151
 
152
152
  it {
153
- expect { mapper.db_load({ 'bool' => 'right' }) }.to raise_error(ReeMapper::CoercionError, "`bool` is invalid boolean, got `\"right\"`")
153
+ expect { mapper.db_load({ 'bool' => 'right' }) }.to raise_error(ReeMapper::CoercionError, /`bool` is invalid boolean, got `\"right\"`/)
154
154
  }
155
155
 
156
156
  it {
157
157
  object = Object.new
158
- expect { mapper.db_load({ 'bool' => object }) }.to raise_error(ReeMapper::CoercionError, "`bool` is invalid boolean, got `#{object.inspect}`")
158
+ expect { mapper.db_load({ 'bool' => object }) }.to raise_error(ReeMapper::CoercionError, /`bool` is invalid boolean, got `#{object.inspect}`/)
159
159
  }
160
160
  end
161
161
  end