Skip to content

Commit fd19287

Browse files
authored
Merge pull request #496 from ssuttner/rubocop_fixes
Rubocop fixes
2 parents 0ef2092 + 19dc256 commit fd19287

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+416
-1413
lines changed

.rubocop.yml

Lines changed: 19 additions & 1279 deletions
Large diffs are not rendered by default.

.rubocop_todo.yml

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2018-05-16 14:33:11 -0300 using RuboCop version 0.54.0.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 2
10+
# Configuration parameters: Include.
11+
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
12+
Bundler/DuplicatedGem:
13+
Exclude:
14+
- 'Gemfile'
15+
16+
# Offense count: 1
17+
Lint/IneffectiveAccessModifier:
18+
Exclude:
19+
- 'lib/her/api.rb'
20+
21+
# Offense count: 6
22+
# Cop supports --auto-correct.
23+
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
24+
Lint/UnusedMethodArgument:
25+
Exclude:
26+
- 'lib/her/api.rb'
27+
- 'lib/her/model/associations/association.rb'
28+
- 'lib/her/model/attributes.rb'
29+
- 'lib/her/model/orm.rb'
30+
- 'spec/model/attributes_spec.rb'
31+
32+
# Offense count: 1
33+
# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
34+
Lint/UselessAccessModifier:
35+
Exclude:
36+
- 'lib/her/api.rb'
37+
38+
# Offense count: 10
39+
Metrics/AbcSize:
40+
Max: 38
41+
42+
# Offense count: 91
43+
# Configuration parameters: CountComments, ExcludedMethods.
44+
Metrics/BlockLength:
45+
Max: 694
46+
47+
# Offense count: 4
48+
Metrics/CyclomaticComplexity:
49+
Max: 12
50+
51+
# Offense count: 10
52+
# Configuration parameters: CountComments.
53+
Metrics/MethodLength:
54+
Max: 28
55+
56+
# Offense count: 1
57+
# Configuration parameters: CountComments.
58+
Metrics/ModuleLength:
59+
Max: 106
60+
61+
# Offense count: 4
62+
Metrics/PerceivedComplexity:
63+
Max: 12
64+
65+
# Offense count: 4
66+
Naming/MemoizedInstanceVariableName:
67+
Exclude:
68+
- 'lib/her/model/associations.rb'
69+
- 'lib/her/model/attributes.rb'
70+
- 'lib/her/model/relation.rb'
71+
72+
# Offense count: 7
73+
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros.
74+
# NamePrefix: is_, has_, have_
75+
# NamePrefixBlacklist: is_, has_, have_
76+
# NameWhitelist: is_a?
77+
# MethodDefinitionMacros: define_method, define_singleton_method
78+
Naming/PredicateName:
79+
Exclude:
80+
- 'spec/**/*'
81+
- 'lib/her/model/associations.rb'
82+
- 'lib/her/model/attributes.rb'
83+
- 'lib/her/model/base.rb'
84+
- 'lib/her/model/deprecated_methods.rb'
85+
86+
# Offense count: 1
87+
# Cop supports --auto-correct.
88+
Performance/RegexpMatch:
89+
Exclude:
90+
- 'spec/support/macros/model_macros.rb'
91+
92+
# Offense count: 23
93+
Style/Documentation:
94+
Enabled: false
95+
96+
# Offense count: 21
97+
# Cop supports --auto-correct.
98+
Style/Encoding:
99+
Enabled: false
100+
101+
# Offense count: 2
102+
# Cop supports --auto-correct.
103+
Style/ExpandPathArguments:
104+
Exclude:
105+
- 'her.gemspec'
106+
- 'spec/spec_helper.rb'
107+
108+
# Offense count: 59
109+
# Cop supports --auto-correct.
110+
# Configuration parameters: EnforcedStyle.
111+
# SupportedStyles: when_needed, always, never
112+
Style/FrozenStringLiteralComment:
113+
Enabled: false
114+
115+
# Offense count: 89
116+
# Cop supports --auto-correct.
117+
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
118+
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
119+
Style/HashSyntax:
120+
Enabled: false
121+
122+
# Offense count: 6
123+
# Cop supports --auto-correct.
124+
Style/IfUnlessModifier:
125+
Exclude:
126+
- 'lib/her/json_api/model.rb'
127+
- 'lib/her/model/associations/association_proxy.rb'
128+
- 'lib/her/model/nested_attributes.rb'
129+
- 'lib/her/model/orm.rb'
130+
- 'lib/her/model/parse.rb'
131+
132+
# Offense count: 2
133+
Style/MethodMissing:
134+
Exclude:
135+
- 'lib/her/model/associations/association_proxy.rb'
136+
- 'lib/her/model/relation.rb'
137+
138+
# Offense count: 2
139+
# Cop supports --auto-correct.
140+
Style/MutableConstant:
141+
Exclude:
142+
- 'lib/her/model/http.rb'
143+
- 'lib/her/version.rb'
144+
145+
# Offense count: 3
146+
# Cop supports --auto-correct.
147+
Style/PerlBackrefs:
148+
Exclude:
149+
- 'lib/her/model/paths.rb'
150+
151+
# Offense count: 1
152+
# Cop supports --auto-correct.
153+
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
154+
# SupportedStyles: slashes, percent_r, mixed
155+
Style/RegexpLiteral:
156+
Exclude:
157+
- 'lib/her/model/paths.rb'
158+
159+
# Offense count: 1
160+
# Cop supports --auto-correct.
161+
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, Whitelist.
162+
# Whitelist: present?, blank?, presence, try
163+
Style/SafeNavigation:
164+
Exclude:
165+
- 'spec/model/orm_spec.rb'
166+
167+
# Offense count: 1
168+
# Cop supports --auto-correct.
169+
# Configuration parameters: EnforcedStyle.
170+
# SupportedStyles: use_perl_names, use_english_names
171+
Style/SpecialGlobalVars:
172+
Exclude:
173+
- 'her.gemspec'
174+
175+
# Offense count: 1613
176+
# Cop supports --auto-correct.
177+
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
178+
# SupportedStyles: single_quotes, double_quotes
179+
Style/StringLiterals:
180+
Enabled: false
181+
182+
# Offense count: 1
183+
# Cop supports --auto-correct.
184+
# Configuration parameters: EnforcedStyle.
185+
# SupportedStyles: single_quotes, double_quotes
186+
Style/StringLiteralsInInterpolation:
187+
Exclude:
188+
- 'lib/her/model/introspection.rb'
189+
190+
# Offense count: 1
191+
# Cop supports --auto-correct.
192+
# Configuration parameters: IgnoredMethods.
193+
# IgnoredMethods: respond_to, define_method
194+
Style/SymbolProc:
195+
Exclude:
196+
- 'lib/her/model/parse.rb'
197+
198+
# Offense count: 2
199+
# Cop supports --auto-correct.
200+
# Configuration parameters: EnforcedStyle, AllowSafeAssignment.
201+
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
202+
Style/TernaryParentheses:
203+
Exclude:
204+
- 'lib/her/model/http.rb'
205+
- 'lib/her/model/orm.rb'
206+
207+
# Offense count: 1
208+
# Cop supports --auto-correct.
209+
# Configuration parameters: EnforcedStyleForMultiline.
210+
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
211+
Style/TrailingCommaInHashLiteral:
212+
Exclude:
213+
- 'lib/her/middleware/json_api_parser.rb'
214+
215+
# Offense count: 6
216+
# Cop supports --auto-correct.
217+
# Configuration parameters: EnforcedStyle, MinSize, WordRegex.
218+
# SupportedStyles: percent, brackets
219+
Style/WordArray:
220+
Exclude:
221+
- 'spec/model/orm_spec.rb'
222+
223+
# Offense count: 409
224+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
225+
# URISchemes: http, https
226+
Metrics/LineLength:
227+
Max: 377

her.gemspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- encoding: utf-8 -*-
2+
23
$:.push File.expand_path("../lib", __FILE__)
34
require "her/version"
45

@@ -14,12 +15,12 @@ Gem::Specification.new do |s|
1415

1516
s.files = `git ls-files`.split("\n")
1617
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
1819
s.require_paths = ["lib"]
1920

21+
s.add_development_dependency "json", "~> 1.8"
2022
s.add_development_dependency "rake", "~> 10.0"
2123
s.add_development_dependency "rspec", "~> 3.5"
22-
s.add_development_dependency "json", "~> 1.8"
2324

2425
s.add_runtime_dependency "activemodel", ">= 4.2.1"
2526
s.add_runtime_dependency "faraday", ">= 0.8", "< 1.0"

lib/her/api.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ module Her
22
# This class is where all HTTP requests are made. Before using Her, you must configure it
33
# so it knows where to make those requests. In Rails, this is usually done in `config/initializers/her.rb`:
44
class API
5+
56
# @private
67
attr_reader :connection, :options
78

89
# Constants
910
FARADAY_OPTIONS = [:request, :proxy, :ssl, :builder, :url, :parallel_manager, :params, :headers, :builder_class].freeze
1011

1112
# Setup a default API connection. Accepted arguments and options are the same as {API#setup}.
12-
def self.setup(opts={}, &block)
13+
def self.setup(opts = {}, &block)
1314
@default_api = new(opts, &block)
1415
end
1516

@@ -68,11 +69,11 @@ def initialize(*args, &blk)
6869
# connection.use MyCustomParser
6970
# connection.use Faraday::Adapter::NetHttp
7071
# end
71-
def setup(opts={}, &blk)
72+
def setup(opts = {}, &blk)
7273
opts[:url] = opts.delete(:base_uri) if opts.include?(:base_uri) # Support legacy :base_uri option
7374
@options = opts
7475

75-
faraday_options = @options.reject { |key, value| !FARADAY_OPTIONS.include?(key.to_sym) }
76+
faraday_options = @options.select { |key, _| FARADAY_OPTIONS.include?(key.to_sym) }
7677
@connection = Faraday.new(faraday_options) do |connection|
7778
yield connection if block_given?
7879
end
@@ -84,11 +85,11 @@ def setup(opts={}, &blk)
8485
# and a metadata Hash.
8586
#
8687
# @private
87-
def request(opts={})
88+
def request(opts = {})
8889
method = opts.delete(:_method)
8990
path = opts.delete(:_path)
9091
headers = opts.delete(:_headers)
91-
opts.delete_if { |key, value| key.to_s =~ /^_/ } # Remove all internal parameters
92+
opts.delete_if { |key, _| key.to_s =~ /^_/ } # Remove all internal parameters
9293
if method == :options
9394
# Faraday doesn't support the OPTIONS verb because of a name collision with an internal options method
9495
# so we need to call run_request directly.
@@ -108,12 +109,12 @@ def request(opts={})
108109
end
109110
end
110111
{ :parsed_data => response.env[:body], :response => response }
111-
112112
end
113113

114114
private
115+
115116
# @private
116-
def self.default_api(opts={})
117+
def self.default_api(opts = {})
117118
defined?(@default_api) ? @default_api : nil
118119
end
119120
end

lib/her/collection.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
module Her
22
class Collection < ::Array
3+
34
attr_reader :metadata, :errors
45

56
# @private
6-
def initialize(items=[], metadata={}, errors={})
7+
def initialize(items = [], metadata = {}, errors = {})
78
super(items)
89
@metadata = metadata
910
@errors = errors

lib/her/errors.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
module Her
22
module Errors
33
class PathError < StandardError
4+
45
attr_reader :missing_parameter
56

6-
def initialize(message, missing_parameter=nil)
7+
def initialize(message, missing_parameter = nil)
78
super(message)
89
@missing_parameter = missing_parameter
910
end
@@ -16,6 +17,7 @@ class ParseError < StandardError
1617
end
1718

1819
class ResourceInvalid < StandardError
20+
1921
attr_reader :resource
2022
def initialize(resource)
2123
@resource = resource

lib/her/json_api/model.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
module Her
22
module JsonApi
33
module Model
4-
54
def self.included(klass)
65
klass.class_eval do
76
include Her::Model
87

98
[:parse_root_in_json, :include_root_in_json, :root_element, :primary_key].each do |method|
10-
define_method method do |*args|
9+
define_method method do |*_|
1110
raise NoMethodError, "Her::JsonApi::Model does not support the #{method} configuration option"
1211
end
1312
end
1413

1514
method_for :update, :patch
1615

1716
@type = name.demodulize.tableize
18-
17+
1918
def self.parse(data)
2019
data.fetch(:attributes).merge(data.slice(:id))
2120
end
2221

23-
def self.to_params(attributes, changes={})
24-
request_data = { type: @type }.tap { |request_body|
25-
attrs = attributes.dup.symbolize_keys.tap { |filtered_attributes|
22+
def self.to_params(attributes, changes = {})
23+
request_data = { type: @type }.tap do |request_body|
24+
attrs = attributes.dup.symbolize_keys.tap do |filtered_attributes|
2625
if her_api.options[:send_only_modified_attributes]
2726
filtered_attributes.slice! *changes.keys.map(&:to_sym)
2827
end
29-
}
28+
end
3029
request_body[:id] = attrs.delete(:id) if attrs[:id]
3130
request_body[:attributes] = attrs
32-
}
31+
end
3332
{ data: request_data }
3433
end
3534

lib/her/middleware.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ module Her
77
module Middleware
88
DefaultParseJSON = FirstLevelParseJSON
99

10-
autoload :JsonApiParser, 'her/middleware/json_api_parser'
10+
autoload :JsonApiParser, 'her/middleware/json_api_parser'
1111
end
1212
end

lib/her/middleware/accept_json.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Her
22
module Middleware
33
# This middleware adds a "Accept: application/json" HTTP header
44
class AcceptJSON < Faraday::Middleware
5+
56
# @private
67
def add_header(headers)
78
headers.merge! "Accept" => "application/json"

0 commit comments

Comments
 (0)