request_handler 0.9.1 → 0.10.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: 14b3530f39b336a119b6c37b07c9e4a4cfef1033
4
- data.tar.gz: b54120aaaf4c7934d4726b052405e7129a5cb68d
3
+ metadata.gz: 252b6dd26a2f9989d6bb8782a7cfec3c745db91d
4
+ data.tar.gz: 95efc2b338c327105d3bd1e6836c92848d1d51c8
5
5
  SHA512:
6
- metadata.gz: 0da96498795ecef95acfa1b4136b580e77155755ed9db531fa5e172ee6a464698a7a9c7c5d496ad361b60d5473cbbdb0a148d4056c4c2ba236baa177a5ad95cc
7
- data.tar.gz: 5226d3a8ba5d4dbb3dfff3cc354b644f03d176f3ba7f0084180072fde33a7f912e65ab713c74e8942292f48e1f2d9a8bd653ec53d15abd52b02e7ad7686f3706
6
+ metadata.gz: 348b442311e1f02780bb6e6207534dd00d23a614d443a384240fb1814853df6f996f59cad3eecd463a88763c732a16f4a1621e95a061068b6d058cebfbc56f65
7
+ data.tar.gz: 941fd8a4714ff60b793475125b0e74fe2187f669ca603cd2821f8bcbf59fa41191e41a32f3eb9189acbff46ed6bb3f0a4b4c2e6aaa882c50279b189208bd589a
data/.rubocop.yml CHANGED
@@ -1,11 +1,14 @@
1
1
  # minitest specifics
2
2
  AllCops:
3
- TargetRubyVersion: 2.3
3
+ TargetRubyVersion: 2.1
4
4
  Metrics/LineLength:
5
5
  Max: 119
6
6
  Metrics/MethodLength:
7
7
  Exclude:
8
8
  - test/**/*
9
+ Metrics/ClassLength:
10
+ Exclude:
11
+ - lib/request_handler/base.rb
9
12
  Style/ClassAndModuleChildren:
10
13
  Exclude:
11
14
  - test/**/*
data/.travis.yml CHANGED
@@ -1,10 +1,36 @@
1
- sudo: false
2
1
  language: ruby
3
2
  cache: bundler
4
- jdk:
5
- - oraclejdk8
6
3
  rvm:
4
+ - 2.1.10
5
+ - 2.2.6
7
6
  - 2.3.3
8
7
  - 2.4.0
9
- - jruby-9.1.6.0
10
- before_install: gem install bundler -v 1.13.6
8
+ - jruby-9.1.7.0
9
+ jdk:
10
+ - oraclejdk8
11
+ env:
12
+ - "JRUBY_OPTS='--dev --debug'"
13
+ - "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
14
+ matrix:
15
+ exclude:
16
+ - rvm: 2.1.10
17
+ jdk: oraclejdk8
18
+ env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
19
+ - rvm: 2.2.6
20
+ jdk: oraclejdk8
21
+ env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
22
+ - rvm: 2.3.3
23
+ jdk: oraclejdk8
24
+ env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
25
+ - rvm: 2.4.0
26
+ jdk: oraclejdk8
27
+ env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
28
+ allow_failures:
29
+ - rvm: jruby-9.1.7.0
30
+ jdk: oraclejdk8
31
+ env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
32
+ before_install:
33
+ - gem update --system
34
+ - gem install bundler -v 1.13.6
35
+ before_script:
36
+ - bundle exec danger
data/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@ Changelog
3
3
 
4
4
  ## master
5
5
 
6
+ ## 0.10.0
7
+
8
+ - raise an error if mandatory options are missing in the handler configuration
9
+ - Transform param keys to string before substitution
10
+ - make gem compatible with ruby 2.1
11
+ - add danger
12
+ - raise an ExternalArgumentError if the body does not contain data
13
+
6
14
  ## 0.9.1
7
15
 
8
16
  - fix configure method
data/Dangerfile ADDED
@@ -0,0 +1,26 @@
1
+ # --------------------------------------------------------------------------------------------------------------------
2
+ # Has any changes happened inside the actual library code?
3
+ # --------------------------------------------------------------------------------------------------------------------
4
+ has_app_changes = !git.modified_files.grep(/lib/).empty?
5
+ has_test_changes = !git.modified_files.grep(/spec/).empty?
6
+ is_version_bump = git.modified_files.sort == ["CHANGELOG.md", "lib/request_handler/version.rb"].sort
7
+
8
+ if has_app_changes && !has_test_changes && !is_version_bump
9
+ warn("Tests were not updated. That's OK if you're refactoring existing code.", sticky: false)
10
+ end
11
+
12
+ if !git.modified_files.include?("CHANGELOG.md") && has_app_changes
13
+ fail("Please include a CHANGELOG entry. \nYou can find it at [CHANGELOG.md](https://github.com/request_handler/request_handler/blob/master/CHANGELOG.md).")
14
+ message "Note, we hard-wrap at 80 chars and use 2 spaces after the last line."
15
+ end
16
+
17
+ # Make it more obvious that a PR is a work in progress and shouldn't be merged yet
18
+ warn("PR is classed as Work in Progress") if github.pr_title.include? "WIP"
19
+
20
+ # Warn when there is a big PR
21
+ warn("Big PR") if git.lines_of_code > 500
22
+
23
+ commit_lint.check warn: :all, disable: [:subject_cap]
24
+
25
+ # rubocop
26
+ rubocop.lint "*"
data/Gemfile CHANGED
@@ -3,3 +3,9 @@ source 'https://rubygems.org'
3
3
 
4
4
  # Specify your gem's dependencies in dry-request_handler.gemspec
5
5
  gemspec
6
+
7
+ group :development, :test do
8
+ gem 'danger'
9
+ gem 'danger-commit_lint'
10
+ gem 'danger-rubocop'
11
+ end
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/request_handler.svg)](https://badge.fury.io/rb/request_handler)
4
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
5
  [![codecov](https://codecov.io/gh/runtastic/request_handler/branch/master/graph/badge.svg)](https://codecov.io/gh/runtastic/request_handler)
7
6
 
8
7
  This gem allows easy and dry handling of requests based on the dry-validation
@@ -35,7 +35,7 @@ module RequestHandler
35
35
  def page_params
36
36
  @page_params ||= PageParser.new(
37
37
  params: params,
38
- page_config: config.lookup!('page')
38
+ page_config: lookup!('page')
39
39
  ).run
40
40
  end
41
41
 
@@ -71,9 +71,9 @@ module RequestHandler
71
71
  defaults = fetch_defaults('filter.defaults', {})
72
72
  defaults.merge(FilterParser.new(
73
73
  params: params,
74
- schema: config.lookup!('filter.schema'),
75
- additional_url_filter: config.lookup!('filter.additional_url_filter'),
76
- schema_options: execute_options(config.lookup!('filter.options'))
74
+ schema: lookup!('filter.schema'),
75
+ additional_url_filter: lookup('filter.additional_url_filter'),
76
+ schema_options: execute_options(lookup('filter.options'))
77
77
  ).run)
78
78
  end
79
79
 
@@ -89,7 +89,7 @@ module RequestHandler
89
89
  defaults = fetch_defaults("#{type}.defaults", [])
90
90
  result = parser.new(
91
91
  params: params,
92
- allowed_options_type: config.lookup!("#{type}.allowed")
92
+ allowed_options_type: lookup!("#{type}.allowed")
93
93
  ).run
94
94
  result.empty? ? defaults : result
95
95
  end
@@ -98,19 +98,19 @@ module RequestHandler
98
98
  defaults = fetch_defaults('body.defaults', {})
99
99
  defaults.merge(BodyParser.new(
100
100
  request: request,
101
- schema: config.lookup!('body.schema'),
102
- schema_options: execute_options(config.lookup!('body.options'))
101
+ schema: lookup!('body.schema'),
102
+ schema_options: execute_options(lookup('body.options'))
103
103
  ).run)
104
104
  end
105
105
 
106
106
  def parse_fieldsets_params
107
107
  FieldsetsParser.new(params: params,
108
- allowed: config.lookup!('fieldsets.allowed'),
109
- required: config.lookup!('fieldsets.required')).run
108
+ allowed: lookup!('fieldsets.allowed'),
109
+ required: lookup!('fieldsets.required')).run
110
110
  end
111
111
 
112
112
  def fetch_defaults(key, default)
113
- value = config.lookup!(key)
113
+ value = lookup(key)
114
114
  return default if value.nil?
115
115
  return value unless value.respond_to?(:call)
116
116
  value.call(request)
@@ -122,10 +122,22 @@ module RequestHandler
122
122
  options.call(self, request)
123
123
  end
124
124
 
125
+ def lookup!(key)
126
+ config.lookup!(key).tap do |data|
127
+ raise NoConfigAvailableError, key.to_sym => 'is not configured' if data.nil?
128
+ end
129
+ end
130
+
131
+ def lookup(key)
132
+ config.lookup!(key)
133
+ end
134
+
125
135
  def params
126
136
  raise MissingArgumentError, params: 'is missing' if request.params.nil?
127
137
  raise ExternalArgumentError, params: 'must be a Hash' unless request.params.is_a?(Hash)
128
- @params ||= Helper.deep_transform_keys_in_object(request.params) { |k| k.gsub('.', ::RequestHandler.separator) }
138
+ @params ||= Helper.deep_transform_keys_in_object(request.params) do |k|
139
+ k.to_s.gsub('.', ::RequestHandler.separator)
140
+ end
129
141
  end
130
142
 
131
143
  def config
@@ -4,7 +4,7 @@ require 'request_handler/error'
4
4
  module RequestHandler
5
5
  class BodyParser < SchemaParser
6
6
  def initialize(request:, schema:, schema_options: {})
7
- raise MissingArgumentError, "request.body": 'is missing' if request.body.nil?
7
+ raise MissingArgumentError, :"request.body" => 'is missing' if request.body.nil?
8
8
  super(schema: schema, schema_options: schema_options)
9
9
  @request = request
10
10
  end
@@ -16,7 +16,9 @@ module RequestHandler
16
16
  private
17
17
 
18
18
  def flattened_request_body
19
- body = request_body['data']
19
+ body = request_body.fetch('data') do
20
+ raise ExternalArgumentError, body: 'must contain data'
21
+ end
20
22
  body.merge!(body.delete('attributes') { {} })
21
23
  relationships = flatten_relationship_resource_linkages(body.delete('relationships') { {} })
22
24
  body.merge!(relationships)
@@ -45,12 +45,12 @@ module RequestHandler
45
45
  end
46
46
 
47
47
  def raise_invalid_field_option(type)
48
- return if allowed&.key?(type)
48
+ return if allowed.key?(type)
49
49
  raise OptionNotAllowedError, fieldsets: "fieldsets for type: #{type} not allowed"
50
50
  end
51
51
 
52
52
  def raise_missing_fields_param
53
- return if required.nil? || required.empty?
53
+ return if required.empty?
54
54
  raise ExternalArgumentError, fieldsets: 'missing required fields options'
55
55
  end
56
56
 
@@ -14,7 +14,7 @@ module RequestHandler
14
14
  options.map do |option|
15
15
  option.gsub!('.', ::RequestHandler.separator)
16
16
  begin
17
- allowed_options_type&.call(option).to_sym
17
+ allowed_options_type.call(option).to_sym
18
18
  rescue Dry::Types::ConstraintError
19
19
  raise OptionNotAllowedError, option.to_sym => 'is not an allowed include option'
20
20
  end
@@ -51,7 +51,7 @@ module RequestHandler
51
51
  def fetch_and_check_default_size(prefix)
52
52
  default_size = lookup_nested_config_key('default_size', prefix)
53
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
+ raise_not_positive(prefix, 'size') unless default_size.is_a?(Integer) && default_size > 0
55
55
  default_size
56
56
  end
57
57
 
@@ -64,7 +64,7 @@ module RequestHandler
64
64
 
65
65
  def check_int(string:, error_msg:)
66
66
  output = Integer(string)
67
- raise ExternalArgumentError, error_msg unless output.positive?
67
+ raise ExternalArgumentError, error_msg unless output > 0
68
68
  output
69
69
  rescue ArgumentError
70
70
  raise ExternalArgumentError, error_msg
@@ -6,7 +6,7 @@ module RequestHandler
6
6
  missing_arguments = []
7
7
  missing_arguments << { schema: 'is missing' } if schema.nil?
8
8
  missing_arguments << { schema_options: 'is missing' } if schema_options.nil?
9
- raise MissingArgumentError, missing_arguments if missing_arguments.length.positive?
9
+ raise MissingArgumentError, missing_arguments unless missing_arguments.empty?
10
10
  raise InternalArgumentError, schema: 'must be a Schema' unless schema.is_a?(Dry::Validation::Schema)
11
11
  @schema = schema
12
12
  @schema_options = schema_options
@@ -35,7 +35,7 @@ module RequestHandler
35
35
  end
36
36
 
37
37
  def allowed_option(name)
38
- allowed_options_type&.call(name)
38
+ allowed_options_type.call(name)
39
39
  rescue Dry::Types::ConstraintError
40
40
  raise OptionNotAllowedError, name.to_sym => 'is not an allowed sort option'
41
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RequestHandler
4
- VERSION = '0.9.1'
4
+ VERSION = '0.10.0'.freeze
5
5
  end
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.description = 'shared base for request_handler using dry-* gems'
16
16
  spec.homepage = 'https://github.com/runtastic/request_handler'
17
17
  spec.license = 'MIT'
18
- spec.required_ruby_version = '~> 2.3'
18
+ spec.required_ruby_version = '~> 2.1'
19
19
 
20
20
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
21
21
  f.match(%r{^(test|spec|features)/})
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.9.1
4
+ version: 0.10.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-31 00:00:00.000000000 Z
12
+ date: 2017-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-validation
@@ -220,6 +220,7 @@ files:
220
220
  - ".rubocop.yml"
221
221
  - ".travis.yml"
222
222
  - CHANGELOG.md
223
+ - Dangerfile
223
224
  - Gemfile
224
225
  - Guardfile
225
226
  - LICENSE.txt
@@ -256,7 +257,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
256
257
  requirements:
257
258
  - - "~>"
258
259
  - !ruby/object:Gem::Version
259
- version: '2.3'
260
+ version: '2.1'
260
261
  required_rubygems_version: !ruby/object:Gem::Requirement
261
262
  requirements:
262
263
  - - ">="