Skip to content

Commit

Permalink
Fix rubocop errors in app/api & app/channels (#6425)
Browse files Browse the repository at this point in the history
* Fix rubocop errors in app/api & app/channels

* Fix rubocop guardclause offenses
  • Loading branch information
yamiacat authored and cesswairimu committed Nov 8, 2019
1 parent defce80 commit 431b557
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/api/srch/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Search < Grape::API
if results.present?
docs = results.map do |model|
DocResult.new(
doc_type: 'USERS',
doc_type: 'USERS',
doc_url: '/profile/' + model.name,
doc_title: model.username,
latitude: model.lat,
Expand Down Expand Up @@ -181,7 +181,7 @@ class Search < Grape::API
DocList.new('', search_request)
end
end

# Request URL should be /api/srch/nodes?query=QRY
desc 'Perform a search of nodes', hidden: false,
is_array: false,
Expand Down
17 changes: 6 additions & 11 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@ class Connection < ActionCable::Connection::Base
def connect
self.current_user = find_verified_user
end

def find_verified_user
if cookies.signed['user_token'] != nil
user = User.where(persistence_token: cookies.signed['user_token'])
if user.any?
return user.first
else
return nil
end
else
return nil
end
return if cookies.signed['user_token'].nil?

user = User.where(persistence_token: cookies.signed['user_token'])

return user.first if user.any?
end
end
end
7 changes: 3 additions & 4 deletions app/channels/room_channel.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# This is a general channel connected to all active session
class RoomChannel < ApplicationCable::Channel

def subscribed
stream_from "room_channel"
end
Expand All @@ -10,8 +9,8 @@ def unsubscribed
end

def speak(message)
if current_user && current_user.role == "admin"
ActionCable.server.broadcast 'room_channel', message: message["message"]
end
return unless current_user && current_user.role == "admin"

ActionCable.server.broadcast 'room_channel', message: message["message"]
end
end
2 changes: 1 addition & 1 deletion app/channels/user_channel.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UserChannel < ApplicationCable::Channel
def subscribed
if current_user != nil
if !current_user.nil?
stream_from "users:#{current_user.id}"
else
reject
Expand Down
2 changes: 1 addition & 1 deletion app/channels/user_notification_channel.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UserNotificationChannel < ApplicationCable::Channel
def subscribed
if current_user != nil
if !current_user.nil?
stream_from "users:notification:#{current_user.id}"
else
reject
Expand Down

0 comments on commit 431b557

Please sign in to comment.