request_handler 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 260df33b16a2f025b11b533242b0e01c6394277a
4
- data.tar.gz: 198e45ed88918f7cd9284dfd3e6b9a38b0131b50
3
+ metadata.gz: a8e315a0edd52be9b9cb71f954b28bd167350bd9
4
+ data.tar.gz: 4890f5dbee778780b5c98165e693feeaa5de058f
5
5
  SHA512:
6
- metadata.gz: 5575e87a8d2be849138d622f596094eb09819f36a464ae36b1e7ebee096e1b1962ef78120ec900353b9d6bf22bfdd9634eace53e4e127878558b69e4c77b190e
7
- data.tar.gz: ded86848d0ffdc9b20858cb0d4268c0ccbe5542cb64692bc9c4a0e6790caa62028b9e37289238fc62c2ad3c5709bca007f394f719a3dd30ec2007c006f87520e
6
+ metadata.gz: 4b7010ce210fb7fbfee81f82c9660a86ff4ffe06b2e59c9f689674cac313a6526cf8be1a7c8691da21b2acb6b2ce1442044f22d86e87a5d3cdb21d1302d40e82
7
+ data.tar.gz: fbb91b67a25d63e1e792bddd67283384dd8b30dbfa874e9d45e31fbfebb3ec5143d202d4d798127ef300bff5da5b52711d0ed113132e18145f084e6433425011
data/.travis.yml CHANGED
@@ -1,5 +1,8 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ cache: bundler
4
+ jdk:
5
+ - oraclejdk8
3
6
  rvm:
4
7
  - 2.3.3
5
8
  - 2.4.0
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@ Changelog
2
2
  ===
3
3
 
4
4
  ## master
5
+
6
+ ## 0.9.0
7
+
8
+ - change nesting separator from `_` to `__` and use it consistently (also in sorting fields)
9
+ - make separator configurable
10
+
11
+
12
+ ## 0.8.0
5
13
  - rename gem (dry-request_handler --> request_handler)
6
14
  - remove env based config for logger
7
15
 
data/Guardfile CHANGED
@@ -17,7 +17,7 @@
17
17
  # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
18
18
 
19
19
  group :red_green_refactor, halt_on_fail: true do
20
- guard :rspec, cmd: 'bundle exec rspec' do
20
+ guard :rspec, cmd: 'bundle exec rspec', all_after_pass: true do
21
21
  require 'guard/rspec/dsl'
22
22
  dsl = Guard::RSpec::Dsl.new(self)
23
23
 
data/README.md CHANGED
@@ -1,8 +1,13 @@
1
1
  # RequestHandler
2
2
 
3
- This gem allows easy and dry handling of requests based on the dry-validation gem for validation and
4
- data coersion. It allows to handle headers, filters, include_options, sorting and of course to
5
- validate the body.
3
+ [![Gem Version](https://badge.fury.io/rb/request_handler.svg)](https://badge.fury.io/rb/request_handler)
4
+ [![Build Status](https://travis-ci.org/runtastic/request_handler.svg?branch=master)](https://travis-ci.org/runtastic/request_handler)
5
+ [![Code Climate](https://codeclimate.com/github/runtastic/request_handler/badges/gpa.svg)](https://codeclimate.com/github/runtastic/request_handler)
6
+ [![codecov](https://codecov.io/gh/runtastic/request_handler/branch/master/graph/badge.svg)](https://codecov.io/gh/runtastic/request_handler)
7
+
8
+ This gem allows easy and dry handling of requests based on the dry-validation
9
+ gem for validation and data coersion. It allows to handle headers, filters,
10
+ include_options, sorting and of course to validate the body.
6
11
 
7
12
  ## ToDo
8
13
 
@@ -27,18 +32,22 @@ Or install it yourself as:
27
32
 
28
33
  ## Usage
29
34
 
30
- To set up a handler, you need to extend the `Dry::RequestHandler::Base class`, providing at least the options block and a to_dto method with the parts you want to use.
31
- To use it, create a new instance of the handler passing in the request, after that you can use the handler.dto method to process and access the data.
32
- Here is a short example, check `spec/integration/request_handler_spec.rb` for a detailed one.
35
+ To set up a handler, you need create a class which inherits from
36
+ `RequestHandler::Base`, providing at least the options block and a `to_dto`
37
+ method with the parts you want to use. To use it, create a new instance of the
38
+ handler passing in the request, after that you can use the handler.dto method to
39
+ process and access the data. Here is a short example, check
40
+ `spec/integration/request_handler_spec.rb` for a detailed one.
33
41
 
34
- Please note that pagination only considers options that are configured on the server (at least an empty configuration block int the page block), other options sent by the client are ignored and will cause a warning.
42
+ Please note that pagination only considers options that are configured on the
43
+ server (at least an empty configuration block int the page block), other options
44
+ sent by the client are ignored and will cause a warning.
35
45
 
36
46
  ```ruby
37
47
  require "dry-validation"
38
48
  require "request_handler"
39
49
  class DemoHandler < RequestHandler::Base
40
50
  options do
41
- # pagination settings
42
51
  page do
43
52
  default_size 10
44
53
  max_size 20
@@ -47,21 +56,15 @@ class DemoHandler < RequestHandler::Base
47
56
  max_size 100
48
57
  end
49
58
  end
50
- # access with handler.page_params
51
59
 
52
- # include options
53
60
  include_options do
54
61
  allowed Dry::Types["strict.string"].enum("comments", "author")
55
62
  end
56
- # access with handler.include_params
57
63
 
58
- # sort options
59
64
  sort_options do
60
65
  allowed Dry::Types["strict.string"].enum("age", "name")
61
66
  end
62
- # access with handler.sort_params
63
67
 
64
- # filters
65
68
  filter do
66
69
  schema(
67
70
  Dry::Validation.Form do
@@ -75,9 +78,7 @@ class DemoHandler < RequestHandler::Base
75
78
  options(->(_handler, _request) { { foo: "bar" } })
76
79
  # options({foo: "bar"}) # also works for hash options instead of procs
77
80
  end
78
- # access with handler.filter_params
79
81
 
80
- # body
81
82
  body do
82
83
  schema(
83
84
  Dry::Validation.JSON do
@@ -90,9 +91,6 @@ class DemoHandler < RequestHandler::Base
90
91
  options(->(_handler, _request) { { foo: "bar" } })
91
92
  # options({foo: "bar"}) # also works for hash options instead of procs
92
93
  end
93
- # access via handler.body_params
94
-
95
- # also available: handler.headers
96
94
 
97
95
  def to_dto
98
96
  OpenStruct.new(
@@ -106,13 +104,82 @@ class DemoHandler < RequestHandler::Base
106
104
  end
107
105
  end
108
106
  end
107
+
108
+ # Given a Rack::Request you can create a well defined dto through the request handler:
109
+ DemoHandler.new(request: request).to_dto
110
+ ```
111
+ ### Nested Attributes
112
+
113
+ For nested attributes all options or parameter will be flattened and nesting
114
+ will be represented by joining the nesting levels with the defined separator
115
+ string. By default this will be double underscore `__`.
116
+
117
+ This means in the request handler options one must use the attributes as flat
118
+ structure with the configured separator.
119
+
120
+ #### Example
121
+
122
+ Input query parameters like the following:
123
+
124
+ ```http
125
+ GET /users?filter[name]=John&filter[posts.tag]=health
126
+ ```
127
+
128
+ will be parsed as
129
+
130
+ ```ruby
131
+ {
132
+ name: "John",
133
+ posts__tag: "health"
134
+ }
135
+ ```
136
+
137
+ Same is applied for sort and include options.
138
+
139
+ ```http
140
+ GET /users?sort=posts.published_on&include=posts.comments
141
+ ```
142
+
143
+ becomes
144
+
145
+ ```ruby
146
+ include_options = [:posts__comments]
147
+ sort_options = SortOption.new(:posts__published_on, :asc)
148
+ ```
149
+
150
+ ### Caveats
151
+
152
+ It is currently expected that _url_ parameter are already parsed and included in
153
+ the request params. With Sinatra requests the following is needed to accomplish
154
+ this:
155
+
156
+ ```ruby
157
+ get "/users/:user_id/posts" do
158
+ request.params.merge!(params)
159
+ dto = DemoHandler.new(request: request).to_dto
160
+ # more code
161
+ end
109
162
  ```
110
163
 
111
164
  ## Development
112
165
 
113
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
166
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
167
+ `rake test` to run the tests. You can also run `bin/console` for an interactive
168
+ prompt that will allow you to experiment.
114
169
 
115
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
170
+ To install this gem onto your local machine, run `bundle exec rake install`. To
171
+ release a new version, update the version number in `version.rb`, and then run
172
+ `bundle exec rake release`, which will create a git tag for the version, push
173
+ git commits and tags, and push the `.gem` file
174
+ to [rubygems.org](https://rubygems.org).
116
175
 
117
176
  ## Contributing
118
- Bug reports and pull requests are welcome on GitHub at https://github.com/runtastic/request_handler. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
177
+ Bug reports and pull requests are welcome on GitHub at
178
+ https://github.com/runtastic/request_handler. This project is intended to be a
179
+ safe, welcoming space for collaboration, and contributors are expected to adhere
180
+ to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
181
+
182
+ ## License
183
+
184
+ The gem is available as open source under the terms of
185
+ the [MIT License](http://opensource.org/licenses/MIT).
@@ -15,7 +15,12 @@ module RequestHandler
15
15
  def configuration
16
16
  @configuration ||= ::Confstruct::Configuration.new do
17
17
  logger Logger.new(STDOUT)
18
+ separator '__'
18
19
  end
19
20
  end
21
+
22
+ def separator
23
+ configuration.separator
24
+ end
20
25
  end
21
26
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
- require 'request_handler/filter_handler'
3
- require 'request_handler/page_handler'
4
- require 'request_handler/include_option_handler'
5
- require 'request_handler/sort_option_handler'
6
- require 'request_handler/header_handler'
7
- require 'request_handler/body_handler'
8
- require 'request_handler/field_set_handler'
2
+ require 'request_handler/filter_parser'
3
+ require 'request_handler/page_parser'
4
+ require 'request_handler/include_option_parser'
5
+ require 'request_handler/sort_option_parser'
6
+ require 'request_handler/header_parser'
7
+ require 'request_handler/body_parser'
8
+ require 'request_handler/fieldsets_parser'
9
9
  require 'request_handler/helper'
10
10
  require 'confstruct'
11
11
  module RequestHandler
@@ -29,34 +29,34 @@ module RequestHandler
29
29
  end
30
30
 
31
31
  def filter_params
32
- @filter_params ||= handle_filter_params
32
+ @filter_params ||= parse_filter_params
33
33
  end
34
34
 
35
35
  def page_params
36
- @page_params ||= PageHandler.new(
36
+ @page_params ||= PageParser.new(
37
37
  params: params,
38
38
  page_config: config.lookup!('page')
39
39
  ).run
40
40
  end
41
41
 
42
42
  def include_params
43
- @include_params ||= handle_include_params
43
+ @include_params ||= parse_include_params
44
44
  end
45
45
 
46
46
  def sort_params
47
- @sort_params ||= handle_sort_params
47
+ @sort_params ||= parse_sort_params
48
48
  end
49
49
 
50
50
  def headers
51
- @headers ||= HeaderHandler.new(env: request.env).run
51
+ @headers ||= HeaderParser.new(env: request.env).run
52
52
  end
53
53
 
54
54
  def body_params
55
- @body_params ||= handle_body_params
55
+ @body_params ||= parse_body_params
56
56
  end
57
57
 
58
- def field_set_params
59
- @field_set_params ||= handle_field_set_params
58
+ def fieldsets_params
59
+ @fieldsets_params ||= parse_fieldsets_params
60
60
  end
61
61
 
62
62
  # @abstract Subclass is expected to implement #to_dto
@@ -67,9 +67,9 @@ module RequestHandler
67
67
 
68
68
  attr_reader :request
69
69
 
70
- def handle_filter_params
70
+ def parse_filter_params
71
71
  defaults = fetch_defaults('filter.defaults', {})
72
- defaults.merge(FilterHandler.new(
72
+ defaults.merge(FilterParser.new(
73
73
  params: params,
74
74
  schema: config.lookup!('filter.schema'),
75
75
  additional_url_filter: config.lookup!('filter.additional_url_filter'),
@@ -77,37 +77,36 @@ module RequestHandler
77
77
  ).run)
78
78
  end
79
79
 
80
- def handle_include_params
81
- defaults = fetch_defaults('include_options.defaults', [])
82
- result = IncludeOptionHandler.new(
83
- params: params,
84
- allowed_options_type: config.lookup!('include_options.allowed')
85
- ).run
86
- result.empty? ? defaults : result
80
+ def parse_include_params
81
+ parse_options(type: 'include_options', parser: IncludeOptionParser)
82
+ end
83
+
84
+ def parse_sort_params
85
+ parse_options(type: 'sort_options', parser: SortOptionParser)
87
86
  end
88
87
 
89
- def handle_sort_params
90
- defaults = fetch_defaults('sort_options.defaults', [])
91
- result = SortOptionHandler.new(
88
+ def parse_options(type:, parser:)
89
+ defaults = fetch_defaults("#{type}.defaults", [])
90
+ result = parser.new(
92
91
  params: params,
93
- allowed_options_type: config.lookup!('sort_options.allowed')
92
+ allowed_options_type: config.lookup!("#{type}.allowed")
94
93
  ).run
95
94
  result.empty? ? defaults : result
96
95
  end
97
96
 
98
- def handle_body_params
97
+ def parse_body_params
99
98
  defaults = fetch_defaults('body.defaults', {})
100
- defaults.merge(BodyHandler.new(
99
+ defaults.merge(BodyParser.new(
101
100
  request: request,
102
101
  schema: config.lookup!('body.schema'),
103
102
  schema_options: execute_options(config.lookup!('body.options'))
104
103
  ).run)
105
104
  end
106
105
 
107
- def handle_field_set_params
108
- FieldSetHandler.new(params: params,
109
- allowed: config.lookup!('field_set.allowed'),
110
- required: config.lookup!('field_set.required')).run
106
+ def parse_fieldsets_params
107
+ FieldsetsParser.new(params: params,
108
+ allowed: config.lookup!('fieldsets.allowed'),
109
+ required: config.lookup!('fieldsets.required')).run
111
110
  end
112
111
 
113
112
  def fetch_defaults(key, default)
@@ -126,7 +125,7 @@ module RequestHandler
126
125
  def params
127
126
  raise MissingArgumentError, params: 'is missing' if request.params.nil?
128
127
  raise ExternalArgumentError, params: 'must be a Hash' unless request.params.is_a?(Hash)
129
- @params ||= Helper.deep_transform_keys_in_object(request.params) { |k| k.tr('.', '_') }
128
+ @params ||= Helper.deep_transform_keys_in_object(request.params) { |k| k.gsub('.', ::RequestHandler.separator) }
130
129
  end
131
130
 
132
131
  def config
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
- require 'request_handler/schema_handler'
2
+ require 'request_handler/schema_parser'
3
3
  require 'request_handler/error'
4
4
  module RequestHandler
5
- class BodyHandler < SchemaHandler
5
+ class BodyParser < SchemaParser
6
6
  def initialize(request:, schema:, schema_options: {})
7
7
  raise MissingArgumentError, "request.body": 'is missing' if request.body.nil?
8
8
  super(schema: schema, schema_options: schema_options)
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
- require 'request_handler/schema_handler'
2
+ require 'request_handler/schema_parser'
3
3
  require 'request_handler/error'
4
4
  module RequestHandler
5
- class FieldSetHandler
5
+ class FieldsetsParser
6
6
  def initialize(params:, allowed: {}, required: [])
7
7
  @params = params
8
8
  allowed.each_value do |option|
@@ -17,12 +17,12 @@ module RequestHandler
17
17
  fields = params['fields']
18
18
  raise_missing_fields_param unless fields
19
19
 
20
- field_set = fields.to_h.each_with_object({}) do |(type, values), memo|
20
+ fieldsets = fields.to_h.each_with_object({}) do |(type, values), memo|
21
21
  type = type.to_sym
22
22
  raise_invalid_field_option(type)
23
23
  memo[type] = parse_options(type, values)
24
24
  end
25
- check_required_field_set_types(field_set)
25
+ check_required_fieldsets_types(fieldsets)
26
26
  end
27
27
 
28
28
  private
@@ -36,22 +36,22 @@ module RequestHandler
36
36
  def parse_option(type, option)
37
37
  allowed[type].call(option).to_sym
38
38
  rescue Dry::Types::ConstraintError
39
- raise ExternalArgumentError, field_set: "invalid field: <#{option}> for type: #{type}"
39
+ raise ExternalArgumentError, fieldsets: "invalid field: <#{option}> for type: #{type}"
40
40
  end
41
41
 
42
- def check_required_field_set_types(field_set)
43
- return field_set if (required - field_set.keys).empty?
44
- raise ExternalArgumentError, field_set: 'missing required field_set parameter'
42
+ def check_required_fieldsets_types(fieldsets)
43
+ return fieldsets if (required - fieldsets.keys).empty?
44
+ raise ExternalArgumentError, fieldsets: 'missing required fieldsets parameter'
45
45
  end
46
46
 
47
47
  def raise_invalid_field_option(type)
48
48
  return if allowed&.key?(type)
49
- raise OptionNotAllowedError, field_set: "field_set for type: #{type} not allowed"
49
+ raise OptionNotAllowedError, fieldsets: "fieldsets for type: #{type} not allowed"
50
50
  end
51
51
 
52
52
  def raise_missing_fields_param
53
53
  return if required.nil? || required.empty?
54
- raise ExternalArgumentError, field_set: 'missing required fields options'
54
+ raise ExternalArgumentError, fieldsets: 'missing required fields options'
55
55
  end
56
56
 
57
57
  attr_reader :params, :allowed, :required
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
- require 'request_handler/schema_handler'
2
+ require 'request_handler/schema_parser'
3
3
  require 'request_handler/error'
4
4
  module RequestHandler
5
- class FilterHandler < SchemaHandler
5
+ class FilterParser < SchemaParser
6
6
  def initialize(params:, schema:, additional_url_filter:, schema_options: {})
7
7
  super(schema: schema, schema_options: schema_options)
8
8
  @filter = params.fetch('filter') { {} }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'request_handler/error'
3
3
  module RequestHandler
4
- class HeaderHandler
4
+ class HeaderParser
5
5
  def initialize(env:)
6
6
  raise MissingArgumentError, env: 'is missing' if env.nil?
7
7
  @headers = Helper.deep_transform_keys_in_object(env.select { |k, _v| k.start_with?('HTTP_') }) do |k|
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
- require 'request_handler/option_handler'
2
+ require 'request_handler/option_parser'
3
3
  require 'request_handler/error'
4
4
  module RequestHandler
5
- class IncludeOptionHandler < OptionHandler
5
+ class IncludeOptionParser < OptionParser
6
6
  def run
7
7
  return [] unless params.key?('include')
8
8
  options = fetch_options
@@ -12,12 +12,12 @@ module RequestHandler
12
12
 
13
13
  def allowed_options(options)
14
14
  options.map do |option|
15
+ option.gsub!('.', ::RequestHandler.separator)
15
16
  begin
16
- allowed_options_type&.call(option)
17
+ allowed_options_type&.call(option).to_sym
17
18
  rescue Dry::Types::ConstraintError
18
19
  raise OptionNotAllowedError, option.to_sym => 'is not an allowed include option'
19
20
  end
20
- option.to_sym
21
21
  end
22
22
  end
23
23
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'request_handler/error'
3
3
  module RequestHandler
4
- class OptionHandler
4
+ class OptionParser
5
5
  def initialize(params:, allowed_options_type:)
6
6
  @params = params
7
7
  @allowed_options_type = allowed_options_type
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'request_handler/error'
3
3
  module RequestHandler
4
- class PageHandler
4
+ class PageParser
5
5
  def initialize(params:, page_config:)
6
6
  missing_arguments = []
7
7
  missing_arguments << { params: 'is missing' } if params.nil?
@@ -16,8 +16,8 @@ module RequestHandler
16
16
  base = { number: extract_number, size: extract_size }
17
17
  cfg = config.keys.reduce(base) do |memo, key|
18
18
  next memo if TOP_LEVEL_PAGE_KEYS.include?(key)
19
- memo.merge!("#{key}_number".to_sym => extract_number(prefix: key),
20
- "#{key}_size".to_sym => extract_size(prefix: key))
19
+ memo.merge!("#{key}#{::RequestHandler.separator}number".to_sym => extract_number(prefix: key),
20
+ "#{key}#{::RequestHandler.separator}size".to_sym => extract_size(prefix: key))
21
21
  end
22
22
  check_for_missing_options(cfg)
23
23
  cfg
@@ -30,12 +30,14 @@ module RequestHandler
30
30
 
31
31
  def check_for_missing_options(config)
32
32
  missing_arguments = page_options.keys - config.keys.map(&:to_s)
33
+ return if missing_arguments.empty?
34
+ missing_arguments.map! { |e| e.gsub(::RequestHandler.separator, '.') }
33
35
  warn 'client sent unknown option ' + missing_arguments.to_s unless missing_arguments.empty?
34
36
  end
35
37
 
36
38
  def extract_number(prefix: nil)
37
39
  number_string = lookup_nested_params_key('number', prefix) || 1
38
- error_msg = { :"#{prefix}_number" => 'must be a positive Integer' }
40
+ error_msg = { :"#{prefix}#{::RequestHandler.separator}number" => 'must be a positive Integer' }
39
41
  check_int(string: number_string, error_msg: error_msg)
40
42
  end
41
43
 
@@ -48,16 +50,15 @@ module RequestHandler
48
50
 
49
51
  def fetch_and_check_default_size(prefix)
50
52
  default_size = lookup_nested_config_key('default_size', prefix)
51
- raise NoConfigAvailableError, "#{prefix}_size".to_sym => 'has no default_size' if default_size.nil?
52
- error_msg = { :"#{prefix}_size" => 'must be a positive Integer' }
53
- raise InternalArgumentError, error_msg unless default_size.is_a?(Integer) && default_size.positive?
53
+ raise_no_default_size(prefix) if default_size.nil?
54
+ raise_not_positive(prefix, 'size') unless default_size.is_a?(Integer) && default_size.positive?
54
55
  default_size
55
56
  end
56
57
 
57
58
  def fetch_and_check_size(prefix)
58
59
  size_string = lookup_nested_params_key('size', prefix)
59
60
  return nil if size_string.nil?
60
- error_msg = { :"#{prefix}_size" => 'must be a positive Integer' }
61
+ error_msg = { :"#{prefix}#{::RequestHandler.separator}size" => 'must be a positive Integer' }
61
62
  check_int(string: size_string, error_msg: error_msg) unless size_string.nil?
62
63
  end
63
64
 
@@ -78,7 +79,7 @@ module RequestHandler
78
79
  warn "#{prefix} max_size config not set"
79
80
  size
80
81
  else
81
- raise InternalArgumentError, "#{prefix} max_size".to_sym => 'must be a positive Integer'
82
+ raise_not_positive(prefix, 'max_size', ' ')
82
83
  end
83
84
  end
84
85
 
@@ -88,12 +89,20 @@ module RequestHandler
88
89
  end
89
90
 
90
91
  def lookup_nested_params_key(key, prefix)
91
- key = prefix ? "#{prefix}_#{key}" : key
92
+ key = prefix ? "#{prefix}#{::RequestHandler.separator}#{key}" : key
92
93
  page_options.fetch(key, nil)
93
94
  end
94
95
 
95
96
  def warn(message)
96
97
  ::RequestHandler.configuration.logger.warn(message)
97
98
  end
99
+
100
+ def raise_no_default_size(prefix, sep = ::RequestHandler.separator)
101
+ raise NoConfigAvailableError, :"#{prefix}#{sep}size" => 'has no default_size'
102
+ end
103
+
104
+ def raise_not_positive(prefix, key, sep = ::RequestHandler.separator)
105
+ raise InternalArgumentError, :"#{prefix}#{sep}#{key}" => 'must be a positive Integer'
106
+ end
98
107
  end
99
108
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'request_handler/error'
3
3
  module RequestHandler
4
- class SchemaHandler
4
+ class SchemaParser
5
5
  def initialize(schema:, schema_options: {})
6
6
  missing_arguments = []
7
7
  missing_arguments << { schema: 'is missing' } if schema.nil?
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
- require 'request_handler/option_handler'
2
+ require 'request_handler/option_parser'
3
3
  require 'request_handler/error'
4
4
  require 'request_handler/sort_option'
5
5
  module RequestHandler
6
- class SortOptionHandler < OptionHandler
6
+ class SortOptionParser < OptionParser
7
7
  def run
8
8
  return [] unless params.key?('sort')
9
9
  sort_options = parse_options(fetch_options)
@@ -19,6 +19,7 @@ module RequestHandler
19
19
  def parse_options(options)
20
20
  options.map do |option|
21
21
  name, order = parse_option(option)
22
+ name.gsub!('.', ::RequestHandler.separator)
22
23
  allowed_option(name)
23
24
  SortOption.new(name, order)
24
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RequestHandler
4
- VERSION = '0.8.0'
4
+ VERSION = '0.9.0'
5
5
  end
@@ -32,6 +32,8 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'rake', '~> 10.0'
33
33
  spec.add_development_dependency 'rspec', '~> 3.5'
34
34
  spec.add_development_dependency 'fuubar', '~> 2.2'
35
+ spec.add_development_dependency 'simplecov'
36
+ spec.add_development_dependency 'codecov'
35
37
 
36
38
  spec.add_development_dependency 'rubocop_runner', '~> 2.0'
37
39
  spec.add_development_dependency 'rubocop', '~> 0.46.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Eger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-01-10 00:00:00.000000000 Z
12
+ date: 2017-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-validation
@@ -109,6 +109,34 @@ dependencies:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: '2.2'
112
+ - !ruby/object:Gem::Dependency
113
+ name: simplecov
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: codecov
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
112
140
  - !ruby/object:Gem::Dependency
113
141
  name: rubocop_runner
114
142
  requirement: !ruby/object:Gem::Requirement
@@ -202,18 +230,18 @@ files:
202
230
  - bin/setup
203
231
  - lib/request_handler.rb
204
232
  - lib/request_handler/base.rb
205
- - lib/request_handler/body_handler.rb
233
+ - lib/request_handler/body_parser.rb
206
234
  - lib/request_handler/error.rb
207
- - lib/request_handler/field_set_handler.rb
208
- - lib/request_handler/filter_handler.rb
209
- - lib/request_handler/header_handler.rb
235
+ - lib/request_handler/fieldsets_parser.rb
236
+ - lib/request_handler/filter_parser.rb
237
+ - lib/request_handler/header_parser.rb
210
238
  - lib/request_handler/helper.rb
211
- - lib/request_handler/include_option_handler.rb
212
- - lib/request_handler/option_handler.rb
213
- - lib/request_handler/page_handler.rb
214
- - lib/request_handler/schema_handler.rb
239
+ - lib/request_handler/include_option_parser.rb
240
+ - lib/request_handler/option_parser.rb
241
+ - lib/request_handler/page_parser.rb
242
+ - lib/request_handler/schema_parser.rb
215
243
  - lib/request_handler/sort_option.rb
216
- - lib/request_handler/sort_option_handler.rb
244
+ - lib/request_handler/sort_option_parser.rb
217
245
  - lib/request_handler/version.rb
218
246
  - request_handler.gemspec
219
247
  homepage: https://github.com/runtastic/request_handler