ree_lib 1.0.87 → 1.0.89
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +22 -22
- data/lib/ree_lib/packages/ree_actions/package/ree_actions/dsl.rb +0 -12
- data/lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb +0 -90
- data/lib/ree_lib/packages/ree_dao/Package.schema.json +0 -28
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/dataset_extensions.rb +29 -21
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/build_pg_connection_spec.rb +10 -3
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/build_sqlite_connection_spec.rb +0 -37
- data/lib/ree_lib/packages/ree_http/package/ree_http/functions/execute_request.rb +27 -20
- data/lib/ree_lib/packages/ree_http/schemas/ree_http/functions/execute_request.schema.json +8 -0
- data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_delete_spec.rb +10 -8
- data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_get_spec.rb +79 -18
- data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_options_spec.rb +6 -5
- data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_patch_spec.rb +8 -4
- data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_post_spec.rb +5 -10
- data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_put_spec.rb +5 -3
- data/lib/ree_lib/packages/ree_i18n/spec/ree_i18n/functions/t_spec.rb +4 -4
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper.rb +22 -6
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/benchmarks/mapper_benchmark_spec.rb +31 -0
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/bool_spec.rb +8 -8
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/date_spec.rb +10 -10
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/date_time_spec.rb +16 -16
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/float_spec.rb +13 -13
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/hash_spec.rb +2 -2
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/integer_spec.rb +14 -14
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/rational_spec.rb +12 -12
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/string_spec.rb +12 -12
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/time_spec.rb +16 -16
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/type_options_spec.rb +4 -4
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/wrappers/array_spec.rb +6 -6
- data/lib/ree_lib/version.rb +1 -1
- metadata +17 -24
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/beans/dao_cache.rb +0 -81
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/functions/drop_cache.rb +0 -15
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/functions/extract_changes.rb +0 -26
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/functions/init_cache.rb +0 -15
- data/lib/ree_lib/packages/ree_dao/schemas/ree_dao/beans/dao_cache.schema.json +0 -22
- data/lib/ree_lib/packages/ree_dao/schemas/ree_dao/functions/drop_cache.schema.json +0 -31
- data/lib/ree_lib/packages/ree_dao/schemas/ree_dao/functions/extract_changes.schema.json +0 -45
- data/lib/ree_lib/packages/ree_dao/schemas/ree_dao/functions/init_cache.schema.json +0 -31
@@ -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
|
-
|
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
|
-
'
|
134
|
-
'
|
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
|
-
|
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
|
-
|
155
|
-
force_ssl: true
|
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
|
-
|
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
|
-
|
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
|
-
'
|
151
|
+
'Host' => 'www.example.com'
|
152
152
|
}
|
153
153
|
)
|
154
|
-
.to_return(status: 200
|
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(:
|
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
|
-
'
|
144
|
+
'Host' => 'www.example.com'
|
145
145
|
}
|
146
146
|
)
|
147
|
-
.to_return(status: 200
|
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
|
-
|
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
|
-
|
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
|
-
'
|
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(:
|
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
|
-
'
|
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(:
|
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,19 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe :t do
|
4
|
-
link :t, from: :ree_i18n
|
5
4
|
link :add_load_path, from: :ree_i18n
|
6
5
|
link :set_locale, from: :ree_i18n
|
6
|
+
link :t, from: :ree_i18n
|
7
7
|
|
8
8
|
before do
|
9
9
|
add_load_path(Dir[File.join(__dir__, 'locales/*.yml')])
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it {
|
13
13
|
set_locale(:ru)
|
14
14
|
|
15
15
|
expect(t('gender.male')).to eq("Мужской")
|
16
|
-
expect(t('gender.missing')).to eq("
|
16
|
+
expect(t('gender.missing')).to eq("Translation missing: ru.gender.missing")
|
17
17
|
|
18
18
|
expect {
|
19
19
|
t('gender.missing', raise: true)
|
@@ -110,4 +110,4 @@ RSpec.describe :t do
|
|
110
110
|
)
|
111
111
|
}
|
112
112
|
end
|
113
|
-
end
|
113
|
+
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:
|
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:
|
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 =
|
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(
|
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.
|
74
|
-
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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
|
@@ -27,20 +27,20 @@ RSpec.describe 'ReeMapper::Date' do
|
|
27
27
|
}
|
28
28
|
|
29
29
|
it {
|
30
|
-
expect { mapper.serialize({ date: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError,
|
30
|
+
expect { mapper.serialize({ date: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError, /`date` should be a date, got `#{Regexp.quote(DateTime.new(2020).inspect)}`/)
|
31
31
|
}
|
32
32
|
|
33
33
|
it {
|
34
|
-
expect { mapper.serialize({ date: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError,
|
34
|
+
expect { mapper.serialize({ date: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError, /`date` should be a date, got `#{Regexp.quote(Time.new(2020).inspect)}`/)
|
35
35
|
}
|
36
36
|
|
37
37
|
it {
|
38
|
-
expect { mapper.serialize({ date: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError,
|
38
|
+
expect { mapper.serialize({ date: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError, /`date` should be a date, got `\"2020-01-01\"`/)
|
39
39
|
}
|
40
40
|
|
41
41
|
it {
|
42
42
|
object = Object.new
|
43
|
-
expect { mapper.serialize({ date: object }) }.to raise_error(ReeMapper::TypeError,
|
43
|
+
expect { mapper.serialize({ date: object }) }.to raise_error(ReeMapper::TypeError, /`date` should be a date, got `#{object.inspect}`/)
|
44
44
|
}
|
45
45
|
end
|
46
46
|
|
@@ -62,7 +62,7 @@ RSpec.describe 'ReeMapper::Date' do
|
|
62
62
|
}
|
63
63
|
|
64
64
|
it {
|
65
|
-
expect { mapper.cast({ 'date' => 'no date' }) }.to raise_error(ReeMapper::CoercionError,
|
65
|
+
expect { mapper.cast({ 'date' => 'no date' }) }.to raise_error(ReeMapper::CoercionError, /`date` is invalid date, got `\"no date\"`/)
|
66
66
|
}
|
67
67
|
end
|
68
68
|
|
@@ -84,7 +84,7 @@ RSpec.describe 'ReeMapper::Date' do
|
|
84
84
|
}
|
85
85
|
|
86
86
|
it {
|
87
|
-
expect { mapper.db_load({ 'date' => 'no date' }) }.to raise_error(ReeMapper::CoercionError,
|
87
|
+
expect { mapper.db_load({ 'date' => 'no date' }) }.to raise_error(ReeMapper::CoercionError, /`date` is invalid date, got `\"no date\"`/)
|
88
88
|
}
|
89
89
|
end
|
90
90
|
|
@@ -94,20 +94,20 @@ RSpec.describe 'ReeMapper::Date' do
|
|
94
94
|
}
|
95
95
|
|
96
96
|
it {
|
97
|
-
expect { mapper.db_dump OpenStruct.new({ date: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError,
|
97
|
+
expect { mapper.db_dump OpenStruct.new({ date: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError, /`date` should be a date, got `#{Regexp.quote(DateTime.new(2020).inspect)}`/)
|
98
98
|
}
|
99
99
|
|
100
100
|
it {
|
101
|
-
expect { mapper.db_dump OpenStruct.new({ date: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError,
|
101
|
+
expect { mapper.db_dump OpenStruct.new({ date: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError, /`date` should be a date, got `#{Regexp.quote(Time.new(2020).inspect)}`/)
|
102
102
|
}
|
103
103
|
|
104
104
|
it {
|
105
|
-
expect { mapper.db_dump OpenStruct.new({ date: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError,
|
105
|
+
expect { mapper.db_dump OpenStruct.new({ date: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError, /`date` should be a date, got `\"2020-01-01\"`/)
|
106
106
|
}
|
107
107
|
|
108
108
|
it {
|
109
109
|
object = Object.new
|
110
|
-
expect { mapper.db_dump OpenStruct.new({ date: object }) }.to raise_error(ReeMapper::TypeError,
|
110
|
+
expect { mapper.db_dump OpenStruct.new({ date: object }) }.to raise_error(ReeMapper::TypeError, /`date` should be a date, got `#{object.inspect}`/)
|
111
111
|
}
|
112
112
|
end
|
113
113
|
end
|