Skip to content

Commit a4364f2

Browse files
committed
addresses comments, adds rakc ~> 2 gemfile
1 parent 7857ed2 commit a4364f2

File tree

12 files changed

+83
-55
lines changed

12 files changed

+83
-55
lines changed

.rubocop.yml

+9
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ AllCops:
99
- bin/**/*
1010

1111
inherit_from: .rubocop_todo.yml
12+
13+
Style/Documentation:
14+
Enabled: false
15+
16+
Style/MultilineIfModifier:
17+
Enabled: false
18+
19+
Style/RaiseArgs:
20+
Enabled: false

.rubocop_todo.yml

+3-10
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ Metrics/ModuleLength:
5050
Metrics/PerceivedComplexity:
5151
Max: 14
5252

53-
# Offense count: 114
54-
Style/Documentation:
55-
Enabled: false
56-
57-
# Offense count: 16
58-
# Cop supports --auto-correct.
59-
# Configuration parameters: EnforcedStyle, SupportedStyles.
60-
# SupportedStyles: compact, exploded
61-
Style/RaiseArgs:
62-
Enabled: false
53+
Style/MethodMissing:
54+
Exclude:
55+
- 'lib/grape/router/attribute_translator.rb'

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ matrix:
99
- bundle exec danger
1010
- rvm: 2.3.3
1111
gemfile: Gemfile
12+
- rvm: 2.3.3
13+
gemfile: gemfiles/rack_edge.gemfile
1214
- rvm: 2.3.3
1315
gemfile: gemfiles/rack_1.5.2.gemfile
1416
- rvm: 2.3.3

gemfiles/rack_edge.gemfile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This file was generated by Appraisal
2+
3+
source 'https://rubygems.org'
4+
5+
gem 'rack', github: 'rack/rack'
6+
7+
group :development, :test do
8+
gem 'bundler'
9+
gem 'rake'
10+
gem 'rubocop', '~> 0.45.0'
11+
end
12+
13+
group :development do
14+
gem 'guard'
15+
gem 'guard-rspec'
16+
gem 'guard-rubocop'
17+
gem 'yard'
18+
gem 'appraisal'
19+
gem 'benchmark-ips'
20+
gem 'redcarpet'
21+
end
22+
23+
group :test do
24+
gem 'grape-entity', '~> 0.6'
25+
gem 'maruku'
26+
gem 'rack-test'
27+
gem 'rspec', '~> 3.0'
28+
gem 'cookiejar'
29+
gem 'rack-jsonp', require: 'rack/jsonp'
30+
gem 'mime-types', '~> 3.0'
31+
gem 'ruby-grape-danger', '~> 0.1.0', require: false
32+
end
33+
34+
gemspec path: '../'

gemfiles/rails_edge.gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source 'https://rubygems.org'
44

5-
gem 'rails', '~> 5.0.0'
5+
gem 'rails', github: 'rails/rails'
66

77
group :development, :test do
88
gem 'bundler'

lib/grape/dsl/helpers.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ 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-
if block_given?
35-
inject_api_helpers_to_mod(mod) do
36-
mod.class_eval(&block)
37-
end
38-
end
34+
35+
inject_api_helpers_to_mod(mod) do
36+
mod.class_eval(&block)
37+
end if block_given?
3938

4039
namespace_stackable(:helpers, mod)
4140
else

lib/grape/dsl/routing.rb

+8-10
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,15 @@ 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-
if options[:requirements].is_a?(Regexp)
204-
options[:requirements] = {
205-
param.to_sym => options[:requirements]
206-
}
207-
end
208203

209-
if options.key?(:type)
210-
Grape::Validations::ParamsScope.new(api: self) do
211-
requires param, type: options[:type]
212-
end
213-
end
204+
options[:requirements] = {
205+
param.to_sym => options[:requirements]
206+
} if options[:requirements].is_a?(Regexp)
207+
208+
Grape::Validations::ParamsScope.new(api: self) do
209+
requires param, type: options[:type]
210+
end if options.key?(:type)
211+
214212
namespace(":#{param}", options, &block)
215213
end
216214

lib/grape/error_formatter/base.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ 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-
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
18+
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 if env[Grape::Env::API_ENDPOINT].request
2322

2423
presenter = found_code[2] if found_code
2524
end

lib/grape/router.rb

+5-7
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,11 @@ def transaction(env)
9797

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

108106
route = match?(input, '*')
109107
if route

lib/grape/router/attribute_translator.rb

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ def method_missing(m, *args)
1515
@attributes[m[0..-1]] = *args
1616
elsif m[-1] != '='
1717
@attributes[m]
18-
else
19-
super
2018
end
2119
end
2220

lib/grape/router/pattern.rb

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

lib/grape/validations/params_scope.rb

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

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
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
5452
end
55-
end
53+
end if @dependent_on
5654

5755
return true if parent.nil?
5856
parent.should_validate?(parameters)

0 commit comments

Comments
 (0)