request_handler 1.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +75 -0
  3. data/CHANGELOG.md +35 -0
  4. data/CODE_OF_CONDUCT.md +69 -0
  5. data/Gemfile +3 -0
  6. data/{LICENSE.txt → LICENSE} +0 -0
  7. data/README.md +241 -45
  8. data/lib/request_handler.rb +8 -16
  9. data/lib/request_handler/base.rb +44 -35
  10. data/lib/request_handler/base_parser.rb +9 -0
  11. data/lib/request_handler/builder/base.rb +23 -0
  12. data/lib/request_handler/builder/body_builder.rb +27 -0
  13. data/lib/request_handler/builder/fieldsets_builder.rb +28 -0
  14. data/lib/request_handler/builder/fieldsets_resource_builder.rb +17 -0
  15. data/lib/request_handler/builder/filter_builder.rb +31 -0
  16. data/lib/request_handler/builder/headers_builder.rb +23 -0
  17. data/lib/request_handler/builder/include_options_builder.rb +23 -0
  18. data/lib/request_handler/builder/multipart_builder.rb +22 -0
  19. data/lib/request_handler/builder/multipart_resource_builder.rb +35 -0
  20. data/lib/request_handler/builder/options_builder.rb +97 -0
  21. data/lib/request_handler/builder/page_builder.rb +30 -0
  22. data/lib/request_handler/builder/page_resource_builder.rb +23 -0
  23. data/lib/request_handler/builder/query_builder.rb +23 -0
  24. data/lib/request_handler/builder/sort_options_builder.rb +23 -0
  25. data/lib/request_handler/concerns/config_helper.rb +25 -0
  26. data/lib/request_handler/config.rb +33 -0
  27. data/lib/request_handler/error.rb +14 -3
  28. data/lib/request_handler/fieldsets_parser.rb +35 -11
  29. data/lib/request_handler/filter_parser.rb +25 -1
  30. data/lib/request_handler/header_parser.rb +30 -3
  31. data/lib/request_handler/include_option_parser.rb +19 -6
  32. data/lib/request_handler/json_api_document_parser.rb +15 -1
  33. data/lib/request_handler/multipart_parser.rb +25 -17
  34. data/lib/request_handler/option_parser.rb +3 -3
  35. data/lib/request_handler/page_parser.rb +33 -17
  36. data/lib/request_handler/query_parser.rb +8 -0
  37. data/lib/request_handler/schema_parser.rb +41 -21
  38. data/lib/request_handler/sort_option_parser.rb +18 -7
  39. data/lib/request_handler/validation/definition_engine.rb +35 -0
  40. data/lib/request_handler/validation/dry_engine.rb +58 -0
  41. data/lib/request_handler/validation/engine.rb +32 -0
  42. data/lib/request_handler/validation/errors.rb +5 -0
  43. data/lib/request_handler/validation/result.rb +17 -0
  44. data/lib/request_handler/version.rb +1 -1
  45. data/request_handler.gemspec +9 -8
  46. metadata +66 -42
  47. data/.travis.yml +0 -40
@@ -0,0 +1,35 @@
1
+ require_relative 'errors'
2
+ require_relative 'engine'
3
+ require_relative 'result'
4
+ require 'active_support/core_ext/hash/keys'
5
+
6
+ module RequestHandler
7
+ module Validation
8
+ class DefinitionEngine < Engine
9
+ def self.valid_schema?(definition)
10
+ definition.is_a?(::Definition::Types::Base)
11
+ end
12
+
13
+ def self.validate(value, schema, options: {}) # rubocop:disable Lint/UnusedMethodArgument
14
+ value = value.deep_symbolize_keys if value.is_a?(Hash)
15
+ result = schema.conform(value)
16
+ Result.new(output: result.value, errors: result.error_hash)
17
+ end
18
+
19
+ def self.validate!(value, schema, options: {})
20
+ validate(value, schema, options).tap do |result|
21
+ valid = result.respond_to?(:valid?) ? result.valid? : result.success?
22
+ raise Validation::Error unless valid
23
+ end
24
+ end
25
+
26
+ def self.error_message(validation_error)
27
+ validation_error.message
28
+ end
29
+
30
+ def self.error_pointer(validation_error)
31
+ validation_error.error_path.join('/')
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,58 @@
1
+ require_relative 'errors'
2
+ require_relative 'engine'
3
+ require_relative 'result'
4
+ require 'active_support/core_ext/hash/keys'
5
+
6
+ module RequestHandler
7
+ module Validation
8
+ class DryEngine < Engine
9
+ def self.valid_schema?(schema)
10
+ schema_instance?(schema) || schema_class?(schema)
11
+ end
12
+
13
+ def self.validate(value, schema, options: {})
14
+ value = value.deep_symbolize_keys if value.is_a?(Hash)
15
+ to_result(call_schema(value, schema, options))
16
+ rescue Dry::Types::ConstraintError => e
17
+ Result.new(output: nil, errors: { '' => e })
18
+ end
19
+
20
+ def self.call_schema(value, schema, options)
21
+ if options.empty?
22
+ schema_instance?(schema) ? schema.call(value) : schema.new.call(value)
23
+ else
24
+ schema_instance?(schema) ? schema.with(options).call(value) : schema.new(options).call(value)
25
+ end
26
+ end
27
+
28
+ def self.schema_instance?(schema)
29
+ schema.respond_to?(:call)
30
+ end
31
+
32
+ def self.schema_class?(schema)
33
+ schema.respond_to?(:schema)
34
+ end
35
+
36
+ def self.validate!(value, schema, options: {})
37
+ validate(value, schema, options).tap do |result|
38
+ valid = result.respond_to?(:valid?) ? result.valid? : result.success?
39
+ raise Validation::Error unless valid
40
+ end
41
+ end
42
+
43
+ def self.to_result(result)
44
+ output = result.respond_to?(:to_h) ? result.to_h : result
45
+ errors = result.respond_to?(:errors) ? result.errors.to_h : {}
46
+ Result.new(output: output, errors: errors)
47
+ end
48
+
49
+ def self.error_message(validation_error)
50
+ validation_error
51
+ end
52
+
53
+ def self.error_pointer(_validation_error)
54
+ nil
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,32 @@
1
+
2
+ require_relative 'errors'
3
+
4
+ module RequestHandler
5
+ module Validation
6
+ class Engine
7
+ def self.valid_schema?(_schema)
8
+ raise NotImplementedError
9
+ end
10
+
11
+ def self.validate(_value, _schema, options: {}) # rubocop:disable Lint/UnusedMethodArgument
12
+ raise NotImplementedError
13
+ end
14
+
15
+ def self.validate!(_value, _schema, options: {}) # rubocop:disable Lint/UnusedMethodArgument
16
+ raise NotImplementedError
17
+ end
18
+
19
+ def self.error_message(_validation_error)
20
+ raise NotImplementedError
21
+ end
22
+
23
+ def self.error_pointer(_validation_error)
24
+ raise NotImplementedError
25
+ end
26
+
27
+ private
28
+
29
+ attr_accessor :value, :schema, :options
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ module RequestHandler
2
+ module Validation
3
+ class Error < StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+
2
+ module RequestHandler
3
+ module Validation
4
+ class Result
5
+ attr_accessor :errors, :output
6
+
7
+ def initialize(errors:, output:)
8
+ self.errors = errors
9
+ self.output = output
10
+ end
11
+
12
+ def valid?
13
+ errors.empty?
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RequestHandler
4
- VERSION = '1.1.0'.freeze
4
+ VERSION = '2.1.1'.freeze
5
5
  end
@@ -7,14 +7,14 @@ require 'request_handler/version'
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'request_handler'
9
9
  spec.version = RequestHandler::VERSION
10
- spec.authors = ['Andreas Eger', 'Raphael Hetzel']
11
- spec.email = ['andreas.eger@runtastic.com', 'raphael.hetzel@runtastic.com']
10
+ spec.authors = ['Andreas Eger', 'Dominik Goltermann']
11
+ spec.email = ['andreas.eger@runtastic.com', 'dominik.goltermann@runtastic.com']
12
12
 
13
13
  spec.summary = 'shared base for request_handler using dry-* gems'
14
14
  spec.description = 'shared base for request_handler using dry-* gems'
15
15
  spec.homepage = 'https://github.com/runtastic/request_handler'
16
16
  spec.license = 'MIT'
17
- spec.required_ruby_version = '~> 2.2'
17
+ spec.required_ruby_version = '~> 2.4'
18
18
 
19
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
20
  f.match(%r{^(test|spec|features)/})
@@ -23,13 +23,12 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ['lib']
25
25
 
26
- spec.add_dependency 'dry-validation', '~> 0.11', '>= 0.11.0'
27
- spec.add_dependency 'dry-types', '~> 0.11', '>= 0.11.0'
28
-
29
- spec.add_dependency 'confstruct', '~> 1.0.2'
26
+ spec.add_dependency 'docile', '~> 1.3'
30
27
  spec.add_dependency 'multi_json', '~> 1.12'
28
+ spec.add_dependency 'activesupport', '> 4.0'
29
+ spec.add_dependency 'gem_config', '~> 0.3 '
31
30
 
32
- spec.add_development_dependency 'bundler', '~> 1.13'
31
+ spec.add_development_dependency 'bundler'
33
32
  spec.add_development_dependency 'rake', '~> 10.0'
34
33
  spec.add_development_dependency 'rspec', '~> 3.5'
35
34
  spec.add_development_dependency 'fuubar', '~> 2.2'
@@ -44,4 +43,6 @@ Gem::Specification.new do |spec|
44
43
  spec.add_development_dependency 'guard-rubocop'
45
44
 
46
45
  spec.add_development_dependency 'rack'
46
+
47
+ spec.add_development_dependency 'definition', '~> 0.5'
47
48
  end
metadata CHANGED
@@ -1,98 +1,86 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Eger
8
- - Raphael Hetzel
9
- autorequire:
8
+ - Dominik Goltermann
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-07-13 00:00:00.000000000 Z
12
+ date: 2021-06-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: dry-validation
15
+ name: docile
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0.11'
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 0.11.0
20
+ version: '1.3'
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
25
  - - "~>"
29
26
  - !ruby/object:Gem::Version
30
- version: '0.11'
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.11.0
27
+ version: '1.3'
34
28
  - !ruby/object:Gem::Dependency
35
- name: dry-types
29
+ name: multi_json
36
30
  requirement: !ruby/object:Gem::Requirement
37
31
  requirements:
38
32
  - - "~>"
39
33
  - !ruby/object:Gem::Version
40
- version: '0.11'
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: 0.11.0
34
+ version: '1.12'
44
35
  type: :runtime
45
36
  prerelease: false
46
37
  version_requirements: !ruby/object:Gem::Requirement
47
38
  requirements:
48
39
  - - "~>"
49
40
  - !ruby/object:Gem::Version
50
- version: '0.11'
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: 0.11.0
41
+ version: '1.12'
54
42
  - !ruby/object:Gem::Dependency
55
- name: confstruct
43
+ name: activesupport
56
44
  requirement: !ruby/object:Gem::Requirement
57
45
  requirements:
58
- - - "~>"
46
+ - - ">"
59
47
  - !ruby/object:Gem::Version
60
- version: 1.0.2
48
+ version: '4.0'
61
49
  type: :runtime
62
50
  prerelease: false
63
51
  version_requirements: !ruby/object:Gem::Requirement
64
52
  requirements:
65
- - - "~>"
53
+ - - ">"
66
54
  - !ruby/object:Gem::Version
67
- version: 1.0.2
55
+ version: '4.0'
68
56
  - !ruby/object:Gem::Dependency
69
- name: multi_json
57
+ name: gem_config
70
58
  requirement: !ruby/object:Gem::Requirement
71
59
  requirements:
72
60
  - - "~>"
73
61
  - !ruby/object:Gem::Version
74
- version: '1.12'
62
+ version: '0.3'
75
63
  type: :runtime
76
64
  prerelease: false
77
65
  version_requirements: !ruby/object:Gem::Requirement
78
66
  requirements:
79
67
  - - "~>"
80
68
  - !ruby/object:Gem::Version
81
- version: '1.12'
69
+ version: '0.3'
82
70
  - !ruby/object:Gem::Dependency
83
71
  name: bundler
84
72
  requirement: !ruby/object:Gem::Requirement
85
73
  requirements:
86
- - - "~>"
74
+ - - ">="
87
75
  - !ruby/object:Gem::Version
88
- version: '1.13'
76
+ version: '0'
89
77
  type: :development
90
78
  prerelease: false
91
79
  version_requirements: !ruby/object:Gem::Requirement
92
80
  requirements:
93
- - - "~>"
81
+ - - ">="
94
82
  - !ruby/object:Gem::Version
95
- version: '1.13'
83
+ version: '0'
96
84
  - !ruby/object:Gem::Dependency
97
85
  name: rake
98
86
  requirement: !ruby/object:Gem::Requirement
@@ -247,23 +235,38 @@ dependencies:
247
235
  - - ">="
248
236
  - !ruby/object:Gem::Version
249
237
  version: '0'
238
+ - !ruby/object:Gem::Dependency
239
+ name: definition
240
+ requirement: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - "~>"
243
+ - !ruby/object:Gem::Version
244
+ version: '0.5'
245
+ type: :development
246
+ prerelease: false
247
+ version_requirements: !ruby/object:Gem::Requirement
248
+ requirements:
249
+ - - "~>"
250
+ - !ruby/object:Gem::Version
251
+ version: '0.5'
250
252
  description: shared base for request_handler using dry-* gems
251
253
  email:
252
254
  - andreas.eger@runtastic.com
253
- - raphael.hetzel@runtastic.com
255
+ - dominik.goltermann@runtastic.com
254
256
  executables: []
255
257
  extensions: []
256
258
  extra_rdoc_files: []
257
259
  files:
260
+ - ".circleci/config.yml"
258
261
  - ".gitignore"
259
262
  - ".rspec"
260
263
  - ".rubocop.yml"
261
- - ".travis.yml"
262
264
  - CHANGELOG.md
265
+ - CODE_OF_CONDUCT.md
263
266
  - Dangerfile
264
267
  - Gemfile
265
268
  - Guardfile
266
- - LICENSE.txt
269
+ - LICENSE
267
270
  - README.md
268
271
  - Rakefile
269
272
  - bin/ci
@@ -271,7 +274,24 @@ files:
271
274
  - bin/setup
272
275
  - lib/request_handler.rb
273
276
  - lib/request_handler/base.rb
277
+ - lib/request_handler/base_parser.rb
274
278
  - lib/request_handler/body_parser.rb
279
+ - lib/request_handler/builder/base.rb
280
+ - lib/request_handler/builder/body_builder.rb
281
+ - lib/request_handler/builder/fieldsets_builder.rb
282
+ - lib/request_handler/builder/fieldsets_resource_builder.rb
283
+ - lib/request_handler/builder/filter_builder.rb
284
+ - lib/request_handler/builder/headers_builder.rb
285
+ - lib/request_handler/builder/include_options_builder.rb
286
+ - lib/request_handler/builder/multipart_builder.rb
287
+ - lib/request_handler/builder/multipart_resource_builder.rb
288
+ - lib/request_handler/builder/options_builder.rb
289
+ - lib/request_handler/builder/page_builder.rb
290
+ - lib/request_handler/builder/page_resource_builder.rb
291
+ - lib/request_handler/builder/query_builder.rb
292
+ - lib/request_handler/builder/sort_options_builder.rb
293
+ - lib/request_handler/concerns/config_helper.rb
294
+ - lib/request_handler/config.rb
275
295
  - lib/request_handler/document_parser.rb
276
296
  - lib/request_handler/error.rb
277
297
  - lib/request_handler/fieldsets_parser.rb
@@ -288,13 +308,18 @@ files:
288
308
  - lib/request_handler/schema_parser.rb
289
309
  - lib/request_handler/sort_option.rb
290
310
  - lib/request_handler/sort_option_parser.rb
311
+ - lib/request_handler/validation/definition_engine.rb
312
+ - lib/request_handler/validation/dry_engine.rb
313
+ - lib/request_handler/validation/engine.rb
314
+ - lib/request_handler/validation/errors.rb
315
+ - lib/request_handler/validation/result.rb
291
316
  - lib/request_handler/version.rb
292
317
  - request_handler.gemspec
293
318
  homepage: https://github.com/runtastic/request_handler
294
319
  licenses:
295
320
  - MIT
296
321
  metadata: {}
297
- post_install_message:
322
+ post_install_message:
298
323
  rdoc_options: []
299
324
  require_paths:
300
325
  - lib
@@ -302,16 +327,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
302
327
  requirements:
303
328
  - - "~>"
304
329
  - !ruby/object:Gem::Version
305
- version: '2.2'
330
+ version: '2.4'
306
331
  required_rubygems_version: !ruby/object:Gem::Requirement
307
332
  requirements:
308
333
  - - ">="
309
334
  - !ruby/object:Gem::Version
310
335
  version: '0'
311
336
  requirements: []
312
- rubyforge_project:
313
- rubygems_version: 2.7.6
314
- signing_key:
337
+ rubygems_version: 3.1.2
338
+ signing_key:
315
339
  specification_version: 4
316
340
  summary: shared base for request_handler using dry-* gems
317
341
  test_files: []
data/.travis.yml DELETED
@@ -1,40 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- rvm:
4
- - 2.2.10
5
- - 2.3.7
6
- - 2.4.4
7
- - 2.5.1
8
- - jruby-9.1.17.0
9
- - jruby-9.2.0.0
10
- jdk:
11
- - oraclejdk8
12
- env:
13
- - "JRUBY_OPTS='--dev --debug'"
14
- - "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
15
- matrix:
16
- exclude:
17
- - rvm: 2.2.10
18
- jdk: oraclejdk8
19
- env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
20
- - rvm: 2.3.7
21
- jdk: oraclejdk8
22
- env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
23
- - rvm: 2.4.4
24
- jdk: oraclejdk8
25
- env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
26
- - rvm: 2.5.1
27
- jdk: oraclejdk8
28
- env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
29
- allow_failures:
30
- - rvm: jruby-9.1.17.0
31
- jdk: oraclejdk8
32
- env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
33
- - rvm: jruby-9.2.0.0
34
- jdk: oraclejdk8
35
- env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
36
- before_install:
37
- - gem update --system
38
- - gem install bundler -v 1.16.2
39
- before_script:
40
- - bundle exec danger