Skip to content

Commit 9ea69d1

Browse files
toyhammeredNuckChorris
authored andcommittedOct 23, 2017
Fix more rubocop errors (#258)
1 parent c826c2f commit 9ea69d1

15 files changed

+26
-48
lines changed
 

‎.pryrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ if defined?(PryByebug)
66
end
77

88
# Hit Enter to repeat last command
9-
Pry::Commands.command /^$/, 'repeat last command' do
9+
Pry::Commands.command(/^$/, 'repeat last command') do
1010
_pry_.run_command Pry.history.to_a.last
1111
end

‎app/chewy/characters_index.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def self.query_for(query)
2424
max_expansions: 15,
2525
prefix_length: 2,
2626
boost: 2
27-
},
27+
}
2828
},
2929
{
3030
multi_match: {

‎app/chewy/users_index.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def self.blocking(*user_ids)
55
end
66

77
def self.active
8-
filter { deleted_at == nil }
8+
filter { deleted_at.nil? }
99
end
1010

1111
field :name

‎app/controllers/concerns/custom_controller_helpers.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ def user
3939
end
4040

4141
def authenticate_user!
42-
unless user
43-
render_jsonapi serialize_error(403, 'Must be logged in'), status: 403
44-
end
42+
render_jsonapi serialize_error(403, 'Must be logged in'), status: 403 unless user
4543
end
4644
end

‎app/controllers/concerns/doorkeeper_helpers.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def validate_token!
1616
if doorkeeper_token && !doorkeeper_token.accessible?
1717
render json: {
1818
errors: [
19-
{ title: 'Invalid token', status: "403"}
19+
{ title: 'Invalid token', status: '403' }
2020
]
2121
}, status: 403
2222
end

‎app/controllers/group_invites_controller.rb

+4-9
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,14 @@ def revoke
2222
private
2323

2424
def authenticate!
25-
unless invite
26-
return render_jsonapi serialize_error(404, 'Not Found'), status: 404
27-
end
25+
return render_jsonapi serialize_error(404, 'Not Found'), status: 404 unless invite
26+
2827
user = current_user&.resource_owner
29-
unless user == invite.user
30-
render_jsonapi serialize_error(403, 'Not Authorized'), status: 403
31-
end
28+
render_jsonapi serialize_error(403, 'Not Authorized'), status: 403 unless user == invite.user
3229
end
3330

3431
def acceptable?
35-
if invite.unacceptable?
36-
render_jsonapi serialize_error(403, 'Already Responded'), status: 403
37-
end
32+
render_jsonapi serialize_error(403, 'Already Responded'), status: 403 if invite.unacceptable?
3833
end
3934

4035
def invite

‎app/controllers/sessions_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def new
66
def create
77
return render status: 403, text: 'Token missing' if params[:token].blank?
88
token = Doorkeeper::AccessToken.by_token(params[:token])
9-
is_admin = token.resource_owner.roles.where(name: 'admin').count > 0
9+
is_admin = token.resource_owner.roles.where(name: 'admin').exists?
1010
return render status: 403, text: 'Not allowed' unless is_admin
1111
session[:token] = params[:token]
1212
render status: 200, text: 'Success'

‎app/controllers/sso_controller.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ def canny
1111
private
1212

1313
def authenticate!
14-
unless signed_in?
15-
render status: 403, json: serialize_error(403, 'Not authenticated')
16-
end
14+
render status: 403, json: serialize_error(403, 'Not authenticated') unless signed_in?
1715
end
1816
end

‎app/mailers/user_mailer.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ def client_url_for(path)
2323
# TODO: stop hardcoding this and fix root_url
2424
# Also, this gsub collapses runs of more than one forward-slash (except in
2525
# the protocol)
26-
"https://kitsu.io/#{path}".gsub(%r{([^:])/+}, '\1/') end
26+
"https://kitsu.io/#{path}".gsub(%r{([^:])/+}, '\1/')
27+
end
2728
end

‎app/models/block.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ class Block < ApplicationRecord
2929

3030
validate :not_blocking_admin
3131
def not_blocking_admin
32-
errors.add(:blocked, "cannot be an admin") if blocked.has_role?(:admin)
33-
errors.add(:blocked, "cannot be a moderator") if blocked.title == 'Mod'
32+
errors.add(:blocked, 'cannot be an admin') if blocked.has_role?(:admin)
33+
errors.add(:blocked, 'cannot be a moderator') if blocked.title == 'Mod'
3434
end
3535

3636
def self.hidden_for(user)
3737
return [] if user.nil?
3838
user = user.id if user.respond_to?(:id)
39-
Block.where('user_id = ? or blocked_id = ?', *[user]*2).
40-
pluck(:blocked_id, :user_id).flatten.uniq - [user]
39+
Block.where('user_id = ? or blocked_id = ?', user, user)
40+
.pluck(:blocked_id, :user_id).flatten.uniq - [user]
4141
end
4242

4343
after_create do

‎app/models/group_invite.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,11 @@ def not_inviting_self
107107
end
108108

109109
def not_banned
110-
if GroupBan.where(group: group, user: user).exists?
111-
errors.add(:user, 'is banned')
112-
end
110+
errors.add(:user, 'is banned') if GroupBan.where(group: group, user: user).exists?
113111
end
114112

115113
def not_already_member
116-
if GroupMember.where(group: group, user: user).exists?
117-
errors.add(:user, 'is already a member')
118-
end
114+
errors.add(:user, 'is already a member') if GroupMember.where(group: group, user: user).exists?
119115
end
120116

121117
def invitee_following_sender

‎app/models/linked_account.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ def type_is_subclass
4343

4444
in_namespace = type.start_with?('LinkedAccount')
4545
is_descendant = type.safe_constantize <= LinkedAccount
46-
unless in_namespace && is_descendant
47-
errors.add(:type, 'must be a LinkedAccount class')
48-
end
46+
errors.add(:type, 'must be a LinkedAccount class') unless in_namespace && is_descendant
4947
end
5048

5149
def self.without_syncing(reason = nil)

‎app/models/list_import.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ class ListImport < ApplicationRecord
4343
def type_is_subclass
4444
in_namespace = type.start_with?('ListImport')
4545
is_descendant = type.safe_constantize <= ListImport
46-
unless in_namespace && is_descendant
47-
errors.add(:type, 'must be a ListImport class')
48-
end
46+
errors.add(:type, 'must be a ListImport class') unless in_namespace && is_descendant
4947
end
5048

5149
# Apply the ListImport

‎app/models/media_attribute_vote.rb

+3-9
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,15 @@ class MediaAttributeVote < ApplicationRecord
3636

3737
counter_culture :anime_media_attributes,
3838
column_name: proc { |mav|
39-
if mav.vote != 'unvoted' && mav.anime_media_attributes
40-
"#{mav.vote}_vote_count"
41-
end
39+
"#{mav.vote}_vote_count" if mav.vote != 'unvoted' && mav.anime_media_attributes
4240
}
4341
counter_culture :manga_media_attributes,
4442
column_name: proc { |mav|
45-
if mav.vote != 'unvoted' && mav.manga_media_attributes
46-
"#{mav.vote}_vote_count"
47-
end
43+
"#{mav.vote}_vote_count" if mav.vote != 'unvoted' && mav.manga_media_attributes
4844
}
4945
counter_culture :dramas_media_attributes,
5046
column_name: proc { |mav|
51-
if mav.vote != 'unvoted' && mav.dramas_media_attributes
52-
"#{mav.vote}_vote_count"
53-
end
47+
"#{mav.vote}_vote_count" if mav.vote != 'unvoted' && mav.dramas_media_attributes
5448
}
5549

5650
before_validation do

‎app/models/streaming_link.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ class StreamingLink < ApplicationRecord
3131
validates :media, :streamer, :url, :subs, :dubs, presence: true
3232
validates :media, polymorphism: { type: Media }
3333

34-
scope :dubbed, -> (langs) { where('dubs @> ARRAY[?]::varchar[]', langs) }
35-
scope :subbed, -> (langs) { where('subs @> ARRAY[?]::varchar[]', langs) }
34+
scope :dubbed, ->(langs) { where('dubs @> ARRAY[?]::varchar[]', langs) }
35+
scope :subbed, ->(langs) { where('subs @> ARRAY[?]::varchar[]', langs) }
3636
end

0 commit comments

Comments
 (0)
Please sign in to comment.