Skip to content

Commit 1f8809f

Browse files
committed
updates gem dependencies
- adds changelog entry
1 parent dc5e4b0 commit 1f8809f

24 files changed

+119
-93
lines changed

.rubocop_todo.yml

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2016-09-28 13:52:41 +0200 using RuboCop version 0.39.0.
3+
# on 2016-12-01 19:41:18 +0100 using RuboCop version 0.46.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 41
9+
# Offense count: 3
10+
# this must be removed for preparation of ruby 2.4
11+
Lint/UnifiedInteger:
12+
Exclude:
13+
- 'lib/grape/dsl/inside_route.rb'
14+
- 'spec/grape/validations/validators/allow_blank_spec.rb'
15+
16+
# Offense count: 44
1017
Metrics/AbcSize:
1118
Max: 44
1219

@@ -19,27 +26,27 @@ Metrics/BlockNesting:
1926
Metrics/ClassLength:
2027
Max: 279
2128

22-
# Offense count: 28
29+
# Offense count: 26
2330
Metrics/CyclomaticComplexity:
2431
Max: 14
2532

26-
# Offense count: 955
27-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
33+
# Offense count: 964
34+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
2835
# URISchemes: http, https
2936
Metrics/LineLength:
3037
Max: 215
3138

32-
# Offense count: 52
39+
# Offense count: 55
3340
# Configuration parameters: CountComments.
3441
Metrics/MethodLength:
3542
Max: 33
3643

37-
# Offense count: 8
44+
# Offense count: 9
3845
# Configuration parameters: CountComments.
3946
Metrics/ModuleLength:
4047
Max: 212
4148

42-
# Offense count: 18
49+
# Offense count: 17
4350
Metrics/PerceivedComplexity:
4451
Max: 14
4552

@@ -48,6 +55,7 @@ Style/Documentation:
4855
Enabled: false
4956

5057
# Offense count: 16
58+
# Cop supports --auto-correct.
5159
# Configuration parameters: EnforcedStyle, SupportedStyles.
5260
# SupportedStyles: compact, exploded
5361
Style/RaiseArgs:

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Next Release
1414
* [#1512](https://github.com/ruby-grape/grape/pull/1512): Fix: deeply nested parameters are included within `#declared(params)` - [@krbs](https://github.com/krbs).
1515
* [#1510](https://github.com/ruby-grape/grape/pull/1510): Fix: inconsistent validation for multiple parameters - [@dgasper](https://github.com/dgasper).
1616
* [#1526](https://github.com/ruby-grape/grape/pull/1526): Reduce warnings caused by instance variables not initialized - [@cpetschnig](https://github.com/cpetschnig).
17+
* [#1531](https://github.com/ruby-grape/grape/pull/1531): Updates gem dependencies - [@LeFnord](https://github.com/LeFnord).
18+
1719

1820
0.18.0 (10/7/2016)
1921
==================

Gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ gemspec
77
group :development, :test do
88
gem 'bundler'
99
gem 'rake'
10-
gem 'rubocop', '0.39.0'
10+
gem 'rubocop', '~> 0.40'
1111
end
1212

1313
group :development do
@@ -21,7 +21,7 @@ group :development do
2121
end
2222

2323
group :test do
24-
gem 'grape-entity', '0.5.0'
24+
gem 'grape-entity', '~> 0.6'
2525
gem 'maruku'
2626
gem 'rack-test'
2727
gem 'rspec', '~> 3.0'

lib/grape/dsl/helpers.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ def helpers(new_mod = nil, &block)
3131
mod = new_mod || Module.new
3232
define_boolean_in_mod(mod)
3333
inject_api_helpers_to_mod(mod) if new_mod
34-
inject_api_helpers_to_mod(mod) do
35-
mod.class_eval(&block)
36-
end if block_given?
34+
if block_given?
35+
inject_api_helpers_to_mod(mod) do
36+
mod.class_eval(&block)
37+
end
38+
end
3739

3840
namespace_stackable(:helpers, mod)
3941
else

lib/grape/dsl/parameters.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ def all_or_none_of(*attrs)
176176
# @yield a parameter definition DSL
177177
def given(*attrs, &block)
178178
attrs.each do |attr|
179-
attr_ = attr.is_a?(Hash) ? attr.keys[0] : attr
180-
raise Grape::Exceptions::UnknownParameter.new(attr_) unless declared_param?(attr_)
179+
proxy_attr = attr.is_a?(Hash) ? attr.keys[0] : attr
180+
raise Grape::Exceptions::UnknownParameter.new(proxy_attr) unless declared_param?(proxy_attr)
181181
end
182182
new_lateral_scope(dependent_on: attrs, &block)
183183
end

lib/grape/dsl/request_response.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,10 @@ def rescue_from(*args, &block)
110110
end
111111
handler ||= extract_with(options)
112112

113-
case
114-
when args.include?(:all)
113+
if args.include?(:all)
115114
namespace_inheritable(:rescue_all, true)
116115
namespace_inheritable :all_rescue_handler, handler
117-
when args.include?(:grape_exceptions)
116+
elsif args.include?(:grape_exceptions)
118117
namespace_inheritable(:rescue_all, true)
119118
namespace_inheritable(:rescue_grape_exceptions, true)
120119
else

lib/grape/dsl/routing.rb

+10-6
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,17 @@ def reset_endpoints!
200200
# @option options [Regexp] You may supply a regular expression that the declared parameter must meet.
201201
def route_param(param, options = {}, &block)
202202
options = options.dup
203-
options[:requirements] = {
204-
param.to_sym => options[:requirements]
205-
} if options[:requirements].is_a?(Regexp)
203+
if options[:requirements].is_a?(Regexp)
204+
options[:requirements] = {
205+
param.to_sym => options[:requirements]
206+
}
207+
end
206208

207-
Grape::Validations::ParamsScope.new(api: self) do
208-
requires param, type: options[:type]
209-
end if options.key?(:type)
209+
if options.key?(:type)
210+
Grape::Validations::ParamsScope.new(api: self) do
211+
requires param, type: options[:type]
212+
end
213+
end
210214
namespace(":#{param}", options, &block)
211215
end
212216

lib/grape/error_formatter/base.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ def present(message, env)
1515
# env['api.endpoint'].route does not work when the error occurs within a middleware
1616
# the Endpoint does not have a valid env at this moment
1717
http_codes = env[Grape::Env::GRAPE_ROUTING_ARGS][:route_info].http_codes || []
18-
found_code = http_codes.find do |http_code|
19-
(http_code[0].to_i == env[Grape::Env::API_ENDPOINT].status) && http_code[2].respond_to?(:represent)
20-
end if env[Grape::Env::API_ENDPOINT].request
18+
if env[Grape::Env::API_ENDPOINT].request
19+
found_code = http_codes.find do |http_code|
20+
(http_code[0].to_i == env[Grape::Env::API_ENDPOINT].status) && http_code[2].respond_to?(:represent)
21+
end
22+
end
2123

2224
presenter = found_code[2] if found_code
2325
end

lib/grape/middleware/base.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ def call!(env)
4545

4646
# @abstract
4747
# Called before the application is called in the middleware lifecycle.
48-
def before
49-
end
48+
def before; end
5049

5150
# @abstract
5251
# Called after the application is called in the middleware lifecycle.
5352
# @return [Response, nil] a Rack SPEC response or nil to call the application afterwards.
54-
def after
55-
end
53+
def after; end
5654

5755
def response
5856
return @app_response if @app_response.is_a?(Rack::Response)

lib/grape/middleware/error.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def rescuable_by_grape?(klass)
7070
end
7171

7272
def exec_handler(e, &handler)
73-
if handler.lambda? && handler.arity == 0
73+
if handler.lambda? && handler.arity.zero?
7474
instance_exec(&handler)
7575
else
7676
instance_exec(e, &handler)

lib/grape/middleware/versioner/path.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def default_options
2626
def before
2727
path = env[Grape::Http::Headers::PATH_INFO].dup
2828

29-
if prefix && path.index(prefix) == 0
29+
if prefix && path.index(prefix).zero?
3030
path.sub!(prefix, '')
3131
path = Grape::Router.normalize_path(path)
3232
end

lib/grape/router.rb

+8-6
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,21 @@ def transaction(env)
9797

9898
# If neighbor exists and request method is OPTIONS,
9999
# return response by using #call_with_allow_headers.
100-
return call_with_allow_headers(
101-
env,
102-
neighbor.allow_header,
103-
neighbor.endpoint
104-
) if neighbor && method == 'OPTIONS' && !cascade
100+
if neighbor && method == 'OPTIONS' && !cascade
101+
return call_with_allow_headers(
102+
env,
103+
neighbor.allow_header,
104+
neighbor.endpoint
105+
)
106+
end
105107

106108
route = match?(input, '*')
107109
if route
108110
response = process_route(route, env)
109111
return response if response && !(cascade = cascade?(response))
110112
end
111113

112-
(!cascade && neighbor) ? call_with_allow_headers(env, neighbor.allow_header, neighbor.endpoint) : nil
114+
!cascade && neighbor ? call_with_allow_headers(env, neighbor.allow_header, neighbor.endpoint) : nil
113115
end
114116

115117
def process_route(route, env)

lib/grape/router/attribute_translator.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ def to_h
1313
def method_missing(m, *args)
1414
if m[-1] == '='
1515
@attributes[m[0..-1]] = *args
16-
else
16+
elsif m[-1] != '='
1717
@attributes[m]
18+
else
19+
super
1820
end
1921
end
2022

lib/grape/router/pattern.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ def build_path(pattern, anchor: false, suffix: nil, **_options)
3939
pattern << '/' unless pattern.end_with?('/')
4040
pattern << '*path'
4141
end
42-
pattern = pattern.split('/').tap do |parts|
43-
parts[parts.length - 1] = '?' + parts.last
44-
end.join('/') if pattern.end_with?('*path')
42+
if pattern.end_with?('*path')
43+
pattern = pattern.split('/').tap do |parts|
44+
parts[parts.length - 1] = '?' + parts.last
45+
end.join('/')
46+
end
4547
pattern + suffix.to_s
4648
end
4749

lib/grape/router/route.rb

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def method_missing(method_id, *arguments)
2828
end
2929
end
3030

31+
def respond_to_missing?(method_id, _)
32+
ROUTE_ATTRIBUTE_REGEXP.match(method_id.to_s)
33+
end
34+
3135
[
3236
:prefix,
3337
:version,

lib/grape/validations/params_scope.rb

+19-15
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,28 @@ def should_validate?(parameters)
4242
return false if @optional && (params(parameters).blank? ||
4343
any_element_blank?(parameters))
4444

45-
@dependent_on.each do |dependency|
46-
if dependency.is_a?(Hash)
47-
dependency_key = dependency.keys[0]
48-
proc = dependency.values[0]
49-
return false unless proc.call(params(parameters).try(:[], dependency_key))
50-
elsif params(parameters).try(:[], dependency).blank?
51-
return false
45+
if @dependent_on
46+
@dependent_on.each do |dependency|
47+
if dependency.is_a?(Hash)
48+
dependency_key = dependency.keys[0]
49+
proc = dependency.values[0]
50+
return false unless proc.call(params(parameters).try(:[], dependency_key))
51+
elsif params(parameters).try(:[], dependency).blank?
52+
return false
53+
end
5254
end
53-
end if @dependent_on
55+
end
5456

5557
return true if parent.nil?
5658
parent.should_validate?(parameters)
5759
end
5860

5961
# @return [String] the proper attribute name, with nesting considered.
6062
def full_name(name)
61-
case
62-
when nested?
63+
if nested?
6364
# Find our containing element's name, and append ours.
6465
"#{@parent.full_name(@element)}#{array_index}[#{name}]"
65-
when lateral?
66+
elsif lateral?
6667
# Find the name of the element as if it was at the
6768
# same nesting level as our parent.
6869
@parent.full_name(name)
@@ -171,7 +172,8 @@ def new_scope(attrs, optional = false, &block)
171172
parent: self,
172173
optional: optional,
173174
type: opts[:type],
174-
&block)
175+
&block
176+
)
175177
end
176178

177179
# Returns a new parameter scope, not nested under any current-level param
@@ -189,7 +191,8 @@ def new_lateral_scope(options, &block)
189191
options: @optional,
190192
type: Hash,
191193
dependent_on: options[:dependent_on],
192-
&block)
194+
&block
195+
)
193196
end
194197

195198
# Returns a new parameter scope, subordinate to the current one and nested
@@ -202,7 +205,8 @@ def new_group_scope(attrs, &block)
202205
api: @api,
203206
parent: self,
204207
group: attrs.first,
205-
&block)
208+
&block
209+
)
206210
end
207211

208212
# Pushes declared params to parent or settings
@@ -385,7 +389,7 @@ def validate_value_coercion(coerce_type, values)
385389
def extract_message_option(attrs)
386390
return nil unless attrs.is_a?(Array)
387391
opts = attrs.last.is_a?(Hash) ? attrs.pop : {}
388-
(opts.key?(:message) && !opts[:message].nil?) ? opts.delete(:message) : nil
392+
opts.key?(:message) && !opts[:message].nil? ? opts.delete(:message) : nil
389393
end
390394

391395
def options_key?(type, key, validations)

spec/grape/api/patch_method_helpers_spec.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ class PatchPublic < Grape::API
1212
end
1313

1414
module AuthMethods
15-
def authenticate!
16-
end
15+
def authenticate!; end
1716
end
1817

1918
class PatchPrivate < Grape::API

spec/grape/dsl/desc_spec.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class Dummy
3434
XOptionalHeader: {
3535
description: 'Not really needed',
3636
required: false
37-
}
38-
]
37+
}]
3938
}
4039

4140
subject.desc 'The description' do
@@ -51,8 +50,7 @@ class Dummy
5150
XOptionalHeader: {
5251
description: 'Not really needed',
5352
required: false
54-
}
55-
]
53+
}]
5654
end
5755

5856
expect(subject.namespace_setting(:description)).to eq(expected_options)

0 commit comments

Comments
 (0)