Skip to content

Commit 8d6503d

Browse files
committed
Merge pull request #1378 from ochagata/fix_double_negation_violations
Fix double negation violations
2 parents 41afcfd + dd3ee60 commit 8d6503d

File tree

6 files changed

+26
-31
lines changed

6 files changed

+26
-31
lines changed

.rubocop_todo.yml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2016-04-26 16:12:14 -0400 using RuboCop version 0.39.0.
3+
# on 2016-04-27 13:48:11 -0500 using RuboCop version 0.39.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: 1
10-
Lint/IneffectiveAccessModifier:
11-
Exclude:
12-
- 'lib/grape/router.rb'
13-
149
# Offense count: 39
1510
Metrics/AbcSize:
1611
Max: 44
@@ -22,19 +17,19 @@ Metrics/BlockNesting:
2217
# Offense count: 7
2318
# Configuration parameters: CountComments.
2419
Metrics/ClassLength:
25-
Max: 267
20+
Max: 264
2621

2722
# Offense count: 24
2823
Metrics/CyclomaticComplexity:
2924
Max: 14
3025

31-
# Offense count: 871
26+
# Offense count: 874
3227
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
3328
# URISchemes: http, https
3429
Metrics/LineLength:
3530
Max: 215
3631

37-
# Offense count: 49
32+
# Offense count: 48
3833
# Configuration parameters: CountComments.
3934
Metrics/MethodLength:
4035
Max: 34
@@ -66,14 +61,6 @@ Style/BlockDelimiters:
6661
Style/Documentation:
6762
Enabled: false
6863

69-
# Offense count: 6
70-
Style/DoubleNegation:
71-
Exclude:
72-
- 'lib/grape/api.rb'
73-
- 'lib/grape/middleware/versioner/accept_version_header.rb'
74-
- 'lib/grape/middleware/versioner/header.rb'
75-
- 'lib/grape/path.rb'
76-
7764
# Offense count: 14
7865
# Configuration parameters: EnforcedStyle, SupportedStyles.
7966
# SupportedStyles: compact, exploded

lib/grape/api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def call(env)
123123
# errors from reaching upstream. This is effectivelly done by unsetting
124124
# X-Cascade. Default :cascade is true.
125125
def cascade?
126-
return !!self.class.namespace_inheritable(:cascade) if self.class.inheritable_setting.namespace_inheritable.keys.include?(:cascade)
127-
return !!self.class.namespace_inheritable(:version_options)[:cascade] if self.class.namespace_inheritable(:version_options) && self.class.namespace_inheritable(:version_options).key?(:cascade)
126+
return self.class.namespace_inheritable(:cascade) if self.class.inheritable_setting.namespace_inheritable.keys.include?(:cascade)
127+
return self.class.namespace_inheritable(:version_options)[:cascade] if self.class.namespace_inheritable(:version_options) && self.class.namespace_inheritable(:version_options).key?(:cascade)
128128
true
129129
end
130130

lib/grape/middleware/versioner/accept_version_header.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def strict?
5050
# this behavior, and not add the `X-Cascade` header, one can set the `:cascade` option to `false`.
5151
def cascade?
5252
if options[:version_options] && options[:version_options].key?(:cascade)
53-
!!options[:version_options][:cascade]
53+
options[:version_options][:cascade]
5454
else
5555
true
5656
end

lib/grape/middleware/versioner/header.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def version_options
159159
# header, one can set the `:cascade` option to `false`.
160160
def cascade?
161161
if version_options && version_options.key?(:cascade)
162-
!!version_options[:cascade]
162+
version_options[:cascade]
163163
else
164164
true
165165
end

lib/grape/path.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@ def root_prefix
2222
end
2323

2424
def uses_specific_format?
25-
!!(settings[:format] && Array(settings[:content_types]).size == 1)
25+
if settings.key?(:format) && settings.key?(:content_types)
26+
(settings[:format] && Array(settings[:content_types]).size == 1)
27+
else
28+
false
29+
end
2630
end
2731

2832
def uses_path_versioning?
29-
!!(settings[:version] && settings[:version_options][:using] == :path)
33+
if settings.key?(:version) && settings[:version_options] && settings[:version_options].key?(:using)
34+
(settings[:version] && settings[:version_options][:using] == :path)
35+
else
36+
false
37+
end
3038
end
3139

3240
def namespace?

lib/grape/router.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ def initialize(pattern, attributes = {})
1111
end
1212
end
1313

14+
def self.normalize_path(path)
15+
path = "/#{path}"
16+
path.squeeze!('/')
17+
path.sub!(%r{/+\Z}, '')
18+
path = '/' if path == ''
19+
path
20+
end
21+
1422
def initialize
1523
@neutral_map = []
1624
@map = Hash.new { |hash, key| hash[key] = [] }
@@ -149,13 +157,5 @@ def routes_for(method)
149157
def string_for(input)
150158
self.class.normalize_path(input)
151159
end
152-
153-
def self.normalize_path(path)
154-
path = "/#{path}"
155-
path.squeeze!('/')
156-
path.sub!(%r{/+\Z}, '')
157-
path = '/' if path == ''
158-
path
159-
end
160160
end
161161
end

0 commit comments

Comments
 (0)