From f9c139c19e740889a3e46e3a2b42ea8552c2c074 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Fri, 13 Oct 2017 12:22:05 -0400 Subject: [PATCH] ruby codeclimate fixes --- app/controllers/notifications_controller.rb | 2 +- app/decorators/notification_decorator.rb | 57 +++++++++++---------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index cdbfb2ab..22a34452 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -13,7 +13,7 @@ class NotificationsController < ApplicationController receipt = @receipts.find_by(notification_id: notification.id) NotificationDecorator.decorate(notification, receipt) end - if notifications.length > 0 + if !notifications.empty? render json: notifications else render json: [].to_json diff --git a/app/decorators/notification_decorator.rb b/app/decorators/notification_decorator.rb index a2f7584b..cc503821 100644 --- a/app/decorators/notification_decorator.rb +++ b/app/decorators/notification_decorator.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class NotificationDecorator class << self def decorate(notification, receipt) @@ -14,34 +15,34 @@ class NotificationDecorator } case notification.notification_code - when MAP_ACCESS_APPROVED, MAP_ACCESS_REQUEST, MAP_INVITE_TO_EDIT - map = notification.notified_object&.map - result[:data][:map] = { - id: map&.id, - name: map&.name - } - when TOPIC_ADDED_TO_MAP - topic = notification.notified_object&.eventable - map = notification.notified_object&.map - result[:data][:topic] = { - id: topic&.id, - name: topic&.name - } - result[:data][:map] = { - id: map&.id, - name: map&.name - } - when TOPIC_CONNECTED_1, TOPIC_CONNECTED_2 - topic1 = notification.notified_object&.topic1 - topic2 = notification.notified_object&.topic2 - result[:data][:topic1] = { - id: topic1&.id, - name: topic1&.name - } - result[:data][:topic2] = { - id: topic2&.id, - name: topic2&.name - } + when MAP_ACCESS_APPROVED, MAP_ACCESS_REQUEST, MAP_INVITE_TO_EDIT + map = notification.notified_object&.map + result[:data][:map] = { + id: map&.id, + name: map&.name + } + when TOPIC_ADDED_TO_MAP + topic = notification.notified_object&.eventable + map = notification.notified_object&.map + result[:data][:topic] = { + id: topic&.id, + name: topic&.name + } + result[:data][:map] = { + id: map&.id, + name: map&.name + } + when TOPIC_CONNECTED_1, TOPIC_CONNECTED_2 + topic1 = notification.notified_object&.topic1 + topic2 = notification.notified_object&.topic2 + result[:data][:topic1] = { + id: topic1&.id, + name: topic1&.name + } + result[:data][:topic2] = { + id: topic2&.id, + name: topic2&.name + } end result end