diff --git a/.rubocop.yml b/.rubocop.yml index e7819c17..efb2fbab 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,7 +12,7 @@ Rails: Enabled: true Metrics/LineLength: - Max: 100 + Max: 120 Metrics/AbcSize: Max: 16 diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 diff --git a/app/controllers/access_controller.rb b/app/controllers/access_controller.rb index d4c56add..affb7179 100644 --- a/app/controllers/access_controller.rb +++ b/app/controllers/access_controller.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true class AccessController < ApplicationController - before_action :require_user, only: %i(access access_request + before_action :require_user, only: %i[access access_request approve_access approve_access_post - deny_access deny_access_post request_access) - before_action :set_map, only: %i(access access_request + deny_access deny_access_post request_access] + before_action :set_map, only: %i[access access_request approve_access approve_access_post - deny_access deny_access_post request_access) + deny_access deny_access_post request_access] after_action :verify_authorized # GET maps/:id/request_access diff --git a/app/controllers/api/v2/maps_controller.rb b/app/controllers/api/v2/maps_controller.rb index 9f542c47..f39c1ba4 100644 --- a/app/controllers/api/v2/maps_controller.rb +++ b/app/controllers/api/v2/maps_controller.rb @@ -4,7 +4,7 @@ module Api module V2 class MapsController < WithUpdatesController def searchable_columns - %i(name desc) + %i[name desc] end def apply_filters(collection) diff --git a/app/controllers/api/v2/restful_controller.rb b/app/controllers/api/v2/restful_controller.rb index 57f1b82d..78a67935 100644 --- a/app/controllers/api/v2/restful_controller.rb +++ b/app/controllers/api/v2/restful_controller.rb @@ -8,7 +8,7 @@ module Api snorlax_used_rest! - before_action :load_resource, only: %i(show update destroy) + before_action :load_resource, only: %i[show update destroy] after_action :verify_authorized def index diff --git a/app/controllers/api/v2/topics_controller.rb b/app/controllers/api/v2/topics_controller.rb index 99233cfe..07dffccd 100644 --- a/app/controllers/api/v2/topics_controller.rb +++ b/app/controllers/api/v2/topics_controller.rb @@ -4,7 +4,7 @@ module Api module V2 class TopicsController < WithUpdatesController def searchable_columns - %i(name desc link) + %i[name desc link] end end end diff --git a/app/controllers/explore_controller.rb b/app/controllers/explore_controller.rb index 5f828e1c..41e25009 100644 --- a/app/controllers/explore_controller.rb +++ b/app/controllers/explore_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class ExploreController < ApplicationController - before_action :require_authentication, only: %i(mine shared starred) + before_action :require_authentication, only: %i[mine shared starred] before_action :authorize_explore after_action :verify_authorized after_action :verify_policy_scoped diff --git a/app/controllers/mappings_controller.rb b/app/controllers/mappings_controller.rb index 2089379b..59df40b8 100644 --- a/app/controllers/mappings_controller.rb +++ b/app/controllers/mappings_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class MappingsController < ApplicationController - before_action :require_user, only: %i(create update destroy) + before_action :require_user, only: %i[create update destroy] after_action :verify_authorized, except: :index after_action :verify_policy_scoped, only: :index diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 573f2441..b6a6687e 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true class MapsController < ApplicationController - before_action :require_user, only: %i(create update destroy events follow unfollow) - before_action :set_map, only: %i(show conversation update destroy contains events export follow unfollow unfollow_from_email) + before_action :require_user, only: %i[create update destroy events follow unfollow] + before_action :set_map, only: %i[show conversation update destroy contains events export follow unfollow unfollow_from_email] after_action :verify_authorized # GET maps/:id diff --git a/app/controllers/metacodes_controller.rb b/app/controllers/metacodes_controller.rb index 6f73785e..faf32332 100644 --- a/app/controllers/metacodes_controller.rb +++ b/app/controllers/metacodes_controller.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true class MetacodesController < ApplicationController - before_action :require_admin, except: %i(index show) - before_action :set_metacode, only: %i(edit update) + before_action :require_admin, except: %i[index show] + before_action :set_metacode, only: %i[edit update] # GET /metacodes # GET /metacodes.json diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 3103b2aa..2dde0bc7 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class NotificationsController < ApplicationController - before_action :set_receipts, only: %i(index show mark_read mark_unread) - before_action :set_notification, only: %i(show mark_read mark_unread) - before_action :set_receipt, only: %i(show mark_read mark_unread) + before_action :set_receipts, only: %i[index show mark_read mark_unread] + before_action :set_notification, only: %i[show mark_read mark_unread] + before_action :set_receipt, only: %i[show mark_read mark_unread] def index @notifications = current_user.mailbox.notifications.page(params[:page]).per(25) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 234b3293..a1b8adea 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -8,7 +8,7 @@ class SearchController < ApplicationController before_action :authorize_search after_action :verify_authorized - after_action :verify_policy_scoped, only: %i(maps mappers synapses topics) + after_action :verify_policy_scoped, only: %i[maps mappers synapses topics] # get /search/topics?term=SOMETERM def topics diff --git a/app/controllers/synapses_controller.rb b/app/controllers/synapses_controller.rb index 5f19224b..c92e970f 100644 --- a/app/controllers/synapses_controller.rb +++ b/app/controllers/synapses_controller.rb @@ -3,7 +3,7 @@ class SynapsesController < ApplicationController include TopicsHelper - before_action :require_user, only: %i(create update destroy) + before_action :require_user, only: %i[create update destroy] after_action :verify_authorized, except: :index after_action :verify_policy_scoped, only: :index diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index b8a26593..69e46497 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -3,10 +3,10 @@ class TopicsController < ApplicationController include TopicsHelper - before_action :require_user, only: %i(create update destroy follow unfollow) - before_action :set_topic, only: %i(show update relative_numbers + before_action :require_user, only: %i[create update destroy follow unfollow] + before_action :set_topic, only: %i[show update relative_numbers relatives network destroy - follow unfollow unfollow_from_email) + follow unfollow unfollow_from_email] after_action :verify_authorized, except: :autocomplete_topic respond_to :html, :js, :json diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index f45c61c0..cac2daa3 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -30,7 +30,7 @@ module Users end def configure_sign_up_params - devise_parameter_sanitizer.permit(:sign_up, keys: %i(name joinedwithcode)) + devise_parameter_sanitizer.permit(:sign_up, keys: %i[name joinedwithcode]) end def configure_account_update_params diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index fe4d63fc..8841cea3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class UsersController < ApplicationController - before_action :require_user, only: %i(edit update updatemetacodes update_metacode_focus) + before_action :require_user, only: %i[edit update updatemetacodes update_metacode_focus] respond_to :html, :json diff --git a/app/helpers/maps_helper.rb b/app/helpers/maps_helper.rb index b1efae4d..691804ac 100644 --- a/app/helpers/maps_helper.rb +++ b/app/helpers/maps_helper.rb @@ -21,9 +21,7 @@ module MapsHelper end def first_contributor_image(map) - if map.contributors.count.positive? - return map.contributors[0].image.url(:thirtytwo) - end + return map.contributors[0].image.url(:thirtytwo) if map.contributors.count.positive? 'https://s3.amazonaws.com/metamaps-assets/site/user.png' end diff --git a/app/helpers/synapses_helper.rb b/app/helpers/synapses_helper.rb index 0fbaf925..156871d9 100644 --- a/app/helpers/synapses_helper.rb +++ b/app/helpers/synapses_helper.rb @@ -13,7 +13,7 @@ module SynapsesHelper synapses.map do |s| { id: s.id, - label: s.desc.blank? ? '(no description)' : s.desc, + label: s.desc.presence || '(no description)', value: s.desc, permission: s.permission, mapCount: s.maps.count, diff --git a/app/models/event.rb b/app/models/event.rb index a463314e..e4da5c82 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true class Event < ApplicationRecord - KINDS = %w(user_present_on_map user_not_present_on_map + KINDS = %w[user_present_on_map user_not_present_on_map conversation_started_on_map topic_added_to_map topic_moved_on_map topic_removed_from_map synapse_added_to_map synapse_removed_from_map - topic_updated synapse_updated).freeze + topic_updated synapse_updated].freeze belongs_to :eventable, polymorphic: true belongs_to :map diff --git a/app/models/follow_reason.rb b/app/models/follow_reason.rb index 732db132..91df7a2c 100644 --- a/app/models/follow_reason.rb +++ b/app/models/follow_reason.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class FollowReason < ApplicationRecord - REASONS = %w(created commented contributed followed shared_on starred).freeze + REASONS = %w[created commented contributed followed shared_on starred].freeze belongs_to :follow diff --git a/app/models/map.rb b/app/models/map.rb index 6f58af2e..321c3de1 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Map < ApplicationRecord - ATTRS_TO_WATCH = %w(name desc permission).freeze + ATTRS_TO_WATCH = %w[name desc permission].freeze belongs_to :user belongs_to :source, class_name: :Map @@ -90,10 +90,10 @@ class Map < ApplicationRecord def as_json(_options = {}) json = super( - methods: %i(user_name user_image star_count topic_count synapse_count - contributor_count collaborator_ids screenshot_url), - except: %i(screenshot_content_type screenshot_file_size screenshot_file_name - screenshot_updated_at) + methods: %i[user_name user_image star_count topic_count synapse_count + contributor_count collaborator_ids screenshot_url], + except: %i[screenshot_content_type screenshot_file_size screenshot_file_name + screenshot_updated_at] ) json[:created_at_clean] = created_at_str json[:updated_at_clean] = updated_at_str diff --git a/app/models/mapping.rb b/app/models/mapping.rb index 5139bad3..a3ea037b 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -25,7 +25,7 @@ class Mapping < ApplicationRecord end def as_json(_options = {}) - super(methods: %i(user_name user_image)) + super(methods: %i[user_name user_image]) end def after_created diff --git a/app/models/message.rb b/app/models/message.rb index f0ea0af2..1159bdb4 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -14,7 +14,7 @@ class Message < ApplicationRecord end def as_json(_options = {}) - json = super(methods: %i(user_name user_image)) + json = super(methods: %i[user_name user_image]) json end diff --git a/app/models/metacode.rb b/app/models/metacode.rb index 4a099d76..7f3edad7 100644 --- a/app/models/metacode.rb +++ b/app/models/metacode.rb @@ -21,11 +21,7 @@ class Metacode < ApplicationRecord end def icon(*args) - if manual_icon.present? - manual_icon - else - aws_icon(*args) - end + manual_icon.presence || aws_icon(*args) end def as_json(options = {}) @@ -57,9 +53,7 @@ class Metacode < ApplicationRecord def manual_icon_https if manual_icon.present? - unless manual_icon.starts_with? 'https' - errors.add(:base, 'Manual icon must begin with https') - end + errors.add(:base, 'Manual icon must begin with https') unless manual_icon.starts_with? 'https' end end end diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb index 0fb9ef21..5916c870 100644 --- a/app/models/permitted_params.rb +++ b/app/models/permitted_params.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class PermittedParams < Struct.new(:params) - %w(map synapse topic mapping token).each do |kind| + %w[map synapse topic mapping token].each do |kind| define_method(kind) do permitted_attributes = send("#{kind}_attributes") params.require(kind).permit(*permitted_attributes) @@ -16,18 +16,18 @@ class PermittedParams < Struct.new(:params) end def map_attributes - %i(name desc permission arranged) + %i[name desc permission arranged] end def synapse_attributes - %i(desc category weight permission topic1_id topic2_id) + %i[desc category weight permission topic1_id topic2_id] end def topic_attributes - %i(name desc link permission metacode_id) + %i[name desc link permission metacode_id] end def mapping_attributes - %i(xloc yloc map_id mappable_type mappable_id) + %i[xloc yloc map_id mappable_type mappable_id] end end diff --git a/app/models/synapse.rb b/app/models/synapse.rb index 7e09ad2e..9ffc5cf7 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Synapse < ApplicationRecord - ATTRS_TO_WATCH = %w(desc category permission defer_to_map_id).freeze + ATTRS_TO_WATCH = %w[desc category permission defer_to_map_id].freeze belongs_to :user belongs_to :defer_to_map, class_name: 'Map', foreign_key: 'defer_to_map_id' @@ -55,7 +55,7 @@ class Synapse < ApplicationRecord end def as_json(_options = {}) - super(methods: %i(user_name user_image collaborator_ids)) + super(methods: %i[user_name user_image collaborator_ids]) end def as_rdf diff --git a/app/models/topic.rb b/app/models/topic.rb index 9e551cc3..538f0c0e 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Topic < ApplicationRecord - ATTRS_TO_WATCH = %w(name desc link metacode_id permission defer_to_map_id).freeze + ATTRS_TO_WATCH = %w[name desc link metacode_id permission defer_to_map_id].freeze include TopicsHelper include Attachable @@ -70,7 +70,7 @@ class Topic < ApplicationRecord end def as_json(options = {}) - super(methods: %i(user_name user_image collaborator_ids)) + super(methods: %i[user_name user_image collaborator_ids]) .merge(inmaps: inmaps(options[:user]), inmapsLinks: inmapsLinks(options[:user]), map_count: map_count(options[:user]), synapse_count: synapse_count(options[:user])) end diff --git a/app/models/user.rb b/app/models/user.rb index 3b3a0045..9e5fda7a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -52,24 +52,24 @@ class User < ApplicationRecord validates_attachment_content_type :image, content_type: %r{\Aimage/.*\Z} # override default as_json - def as_json(_options = {}) + def as_json(options = {}) json = { id: id, name: name, image: image.url(:sixtyfour), admin: admin } - if _options[:follows] + if options[:follows] json['follows'] = { topics: following.active.where(followed_type: 'Topic').to_a.map(&:followed_id), maps: following.active.where(followed_type: 'Map').to_a.map(&:followed_id) } end - if _options[:follow_settings] + if options[:follow_settings] json['follow_topic_on_created'] = settings.follow_topic_on_created == '1' json['follow_topic_on_contributed'] = settings.follow_topic_on_contributed == '1' json['follow_map_on_created'] = settings.follow_map_on_created == '1' json['follow_map_on_contributed'] = settings.follow_map_on_contributed == '1' end - json['email'] = email if _options[:email] + json['email'] = email if options[:email] json end @@ -133,7 +133,7 @@ class User < ApplicationRecord def has_map_open(map) latestEvent = Event.where(map: map, user: self) - .where(kind: %w(user_present_on_map user_not_present_on_map)) + .where(kind: %w[user_present_on_map user_not_present_on_map]) .order(:created_at) .last latestEvent && latestEvent.kind == 'user_present_on_map' diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 5a746612..e227f601 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -6,7 +6,7 @@ class UserPreference def initialize array = [] - %w(Action Aim Idea Question Note Wildcard Subject).each do |m| + %w[Action Aim Idea Question Note Wildcard Subject].each do |m| begin metacode = Metacode.find_by(name: m) array.push(metacode.id.to_s) if metacode diff --git a/app/models/webhook.rb b/app/models/webhook.rb index 038c8985..30a1b8b4 100644 --- a/app/models/webhook.rb +++ b/app/models/webhook.rb @@ -5,7 +5,7 @@ class Webhook < ApplicationRecord validates :uri, presence: true validates :hookable, presence: true - validates :kind, inclusion: { in: %w(slack) } + validates :kind, inclusion: { in: %w[slack] } validates :event_types, length: { minimum: 1 } def headers diff --git a/app/policies/map_policy.rb b/app/policies/map_policy.rb index ea231ad7..308d1ce9 100644 --- a/app/policies/map_policy.rb +++ b/app/policies/map_policy.rb @@ -3,7 +3,7 @@ class MapPolicy < ApplicationPolicy class Scope < Scope def resolve - visible = %w(public commons) + visible = %w[public commons] return scope.where(permission: visible) unless user scope.where(permission: visible) @@ -17,13 +17,13 @@ class MapPolicy < ApplicationPolicy end def show? - record.permission.in?(%w(commons public)) || + record.permission.in?(%w[commons public]) || record.collaborators.include?(user) || record.user == user end def conversation? - show? && %w(connorturland@gmail.com devin@callysto.com chessscholar@gmail.com solaureum@gmail.com ishanshapiro@gmail.com).include?(user.email) + show? && %w[connorturland@gmail.com devin@callysto.com chessscholar@gmail.com solaureum@gmail.com ishanshapiro@gmail.com].include?(user.email) end def create? diff --git a/app/policies/mapping_policy.rb b/app/policies/mapping_policy.rb index 011e5f4b..2c5e0bd0 100644 --- a/app/policies/mapping_policy.rb +++ b/app/policies/mapping_policy.rb @@ -7,7 +7,7 @@ class MappingPolicy < ApplicationPolicy # it would be nice if we could also base this on the mappable, but that # gets really complicated. Devin thinks it's OK to SHOW a mapping for # a private topic, since you can't see the private topic anyways - visible = %w(public commons) + visible = %w[public commons] permission = 'maps.permission IN (?)' return scope.joins(:map).where(permission, visible) unless user diff --git a/app/policies/message_policy.rb b/app/policies/message_policy.rb index bbc03639..6bf2bd67 100644 --- a/app/policies/message_policy.rb +++ b/app/policies/message_policy.rb @@ -3,7 +3,7 @@ class MessagePolicy < ApplicationPolicy class Scope < Scope def resolve - visible = %w(public commons) + visible = %w[public commons] permission = 'maps.permission IN (?)' return scope.joins(:map).where(permission, visible) unless user diff --git a/app/policies/synapse_policy.rb b/app/policies/synapse_policy.rb index e789fdc3..0658343f 100644 --- a/app/policies/synapse_policy.rb +++ b/app/policies/synapse_policy.rb @@ -3,9 +3,9 @@ class SynapsePolicy < ApplicationPolicy class Scope < Scope def resolve - return scope.where(permission: %w(public commons)) unless user + return scope.where(permission: %w[public commons]) unless user - scope.where(permission: %w(public commons)) + scope.where(permission: %w[public commons]) .or(scope.where(defer_to_map_id: user.all_accessible_maps.map(&:id))) .or(scope.where(user_id: user.id)) end diff --git a/app/policies/topic_policy.rb b/app/policies/topic_policy.rb index 5ed050e5..fa19a4f1 100644 --- a/app/policies/topic_policy.rb +++ b/app/policies/topic_policy.rb @@ -3,9 +3,9 @@ class TopicPolicy < ApplicationPolicy class Scope < Scope def resolve - return scope.where(permission: %w(public commons)) unless user + return scope.where(permission: %w[public commons]) unless user - scope.where(permission: %w(public commons)) + scope.where(permission: %w[public commons]) .or(scope.where(defer_to_map_id: user.all_accessible_maps.map(&:id))) .or(scope.where(user_id: user.id)) end @@ -23,7 +23,7 @@ class TopicPolicy < ApplicationPolicy if record.defer_to_map.present? map_policy.show? else - record.permission.in?(%w(commons public)) || record.user == user + record.permission.in?(%w[commons public]) || record.user == user end end diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb index 173d56ba..4c59828f 100644 --- a/app/services/follow_service.rb +++ b/app/services/follow_service.rb @@ -8,9 +8,7 @@ class FollowService return if (reason == 'created' || reason == 'contributed') && !should_auto_follow(entity, user, reason) follow = Follow.where(followed: entity, user: user).first_or_create - unless follow.update(muted: false) - raise follow.errors.full_messages.join("\n") - end + raise follow.errors.full_messages.join("\n") unless follow.update(muted: false) if FollowReason::REASONS.include?(reason) && !follow.follow_reason.read_attribute(reason) follow.follow_reason.update_attribute(reason, true) end @@ -19,9 +17,7 @@ class FollowService def unfollow(entity, user) follow = Follow.where(followed: entity, user: user).first if follow - unless follow.update(muted: true) - raise follow.errors.full_messages.join("\n") - end + raise follow.errors.full_messages.join("\n") unless follow.update(muted: true) end end @@ -38,7 +34,7 @@ class FollowService def should_auto_follow(entity, user, reason) follow = Follow.where(followed: entity, user: user).first - return false if follow && follow.muted + return false if follow&.muted if entity.class == Topic if reason == 'created' return user.settings.follow_topic_on_created == '1' diff --git a/app/services/map_activity_service.rb b/app/services/map_activity_service.rb index 5bfafa24..07b65ec7 100644 --- a/app/services/map_activity_service.rb +++ b/app/services/map_activity_service.rb @@ -5,7 +5,7 @@ class MapActivityService 'Activity on map ' + map.name end - def self.summarize_data(map, user, until_moment = DateTime.now) + def self.summarize_data(map, user, until_moment = DateTime.current) results = { stats: {} } @@ -18,15 +18,13 @@ class MapActivityService message_count = Message.where(resource: map) .where('created_at > ? AND created_at < ?', since, until_moment) .where.not(user: user).count - results[:stats][:messages_sent] = message_count if message_count > 0 + results[:stats][:messages_sent] = message_count if message_count.positive? moved_count = Event.where(kind: 'topic_moved_on_map', map: map) .where('created_at > ? AND created_at < ?', since, until_moment) .where(eventable_id: scoped_topic_ids) .where.not(user: user).group(:eventable_id).count - unless moved_count.keys.empty? - results[:stats][:topics_moved] = moved_count.keys.length - end + results[:stats][:topics_moved] = moved_count.keys.length unless moved_count.keys.empty? topics_added_events = Event.where(kind: 'topic_added_to_map', map: map) .where('created_at > ? AND created_at < ?', since, until_moment) diff --git a/app/services/map_export_service.rb b/app/services/map_export_service.rb index 2defd7eb..4e180bf2 100644 --- a/app/services/map_export_service.rb +++ b/app/services/map_export_service.rb @@ -47,16 +47,16 @@ class MapExportService private def topic_headings - %i(id name metacode x y description link user permission) + %i[id name metacode x y description link user permission] end def synapse_headings - %i(topic1 topic2 category description user permission) + %i[topic1 topic2 category description user permission] end def exportable_topics visible_topics ||= Pundit.policy_scope!(user, map.topics) - topic_mappings = Mapping.includes(mappable: %i(metacode user)) + topic_mappings = Mapping.includes(mappable: %i[metacode user]) .where(mappable: visible_topics, map: map) topic_mappings.map do |mapping| topic = mapping.mappable diff --git a/app/services/perm.rb b/app/services/perm.rb index c220a306..8c453490 100644 --- a/app/services/perm.rb +++ b/app/services/perm.rb @@ -2,7 +2,7 @@ class Perm # e.g. Perm::ISSIONS - ISSIONS = %i(commons public private).freeze + ISSIONS = %i[commons public private].freeze class << self def short(permission) diff --git a/config/environments/development.rb b/config/environments/development.rb index a71a1590..bd7eaa2d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -25,7 +25,7 @@ Rails.application.configure do # Print deprecation notices to the Rails logger config.active_support.deprecation = :log - config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews" + config.action_mailer.preview_path = Rails.root.join('spec', 'mailers', 'preview') # Expands the lines which load the assets config.assets.debug = false diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index da5460e3..83195397 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -10,5 +10,5 @@ Rails.application.configure do # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. - config.assets.precompile += %w(application-secret.css application-secret.js webpacked/metamaps.bundle.js) + config.assets.precompile += %w[application-secret.css application-secret.js webpacked/metamaps.bundle.js] end diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb index a93b5b32..27f799d5 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -5,6 +5,6 @@ Rails.application.config.middleware.insert_before 0, Rack::Cors do origins '*' resource '/api/*', headers: :any, - methods: %i(get post put delete options head) + methods: %i[get post put delete options head] end end diff --git a/config/initializers/delayed_job.rb b/config/initializers/delayed_job.rb index c4725b19..c978c537 100644 --- a/config/initializers/delayed_job.rb +++ b/config/initializers/delayed_job.rb @@ -11,4 +11,4 @@ Delayed::Worker.class_eval do prepend ExceptionNotifierInDelayedJob end -Delayed::Worker.logger = Logger.new(File.join(Rails.root, 'log', 'delayed_job.log')) +Delayed::Worker.logger = Logger.new(Rails.root.join('log', 'delayed_job.log')) diff --git a/config/initializers/exception_notification.rb b/config/initializers/exception_notification.rb index 29ef9e5e..421974be 100644 --- a/config/initializers/exception_notification.rb +++ b/config/initializers/exception_notification.rb @@ -51,11 +51,11 @@ ExceptionNotification.configure do |config| # Ignore additional exception types. # ActiveRecord::RecordNotFound, AbstractController::ActionNotFound and # ActionController::RoutingError are already added. - config.ignored_exceptions += %w( + config.ignored_exceptions += %w[ ActionView::TemplateError CustomError UnauthorizedException InvalidArgumentException InvalidEntityException InvalidRequestException NotFoundException ValidationException - ) + ] # Adds a condition to decide when an exception must be ignored or not. # The ignore_if method can be invoked multiple times to add extra conditions. diff --git a/config/initializers/internal_testers.rb b/config/initializers/internal_testers.rb index a014f3a4..e4d1f93f 100644 --- a/config/initializers/internal_testers.rb +++ b/config/initializers/internal_testers.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true def is_tester(user) - user && %w(connorturland@gmail.com devin@callysto.com chessscholar@gmail.com solaureum@gmail.com ishanshapiro@gmail.com).include?(user.email) + user && %w[connorturland@gmail.com devin@callysto.com chessscholar@gmail.com solaureum@gmail.com ishanshapiro@gmail.com].include?(user.email) end diff --git a/config/routes.rb b/config/routes.rb index 667e0965..eba0d5e1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,7 +17,7 @@ Metamaps::Application.routes.draw do end get :explore, to: redirect('/') - resources :maps, except: %i(index edit) do + resources :maps, except: %i[index edit] do member do get :conversation get :export @@ -55,10 +55,10 @@ Metamaps::Application.routes.draw do end end - resources :mappings, except: %i(index new edit) + resources :mappings, except: %i[index new edit] - resources :messages, only: %i(show create update destroy) - resources :notifications, only: %i(index show) do + resources :messages, only: %i[show create update destroy] + resources :notifications, only: %i[index show] do collection do get :unsubscribe end @@ -80,9 +80,9 @@ Metamaps::Application.routes.draw do get :synapses end - resources :synapses, except: %i(index new edit) + resources :synapses, except: %i[index new edit] - resources :topics, except: %i(index new edit) do + resources :topics, except: %i[index new edit] do member do get :network get :relative_numbers @@ -111,7 +111,7 @@ Metamaps::Application.routes.draw do get 'join' => 'users/registrations#new', :as => :sign_up end - resources :users, except: %i(index destroy) do + resources :users, except: %i[index destroy] do member do get :details end @@ -121,16 +121,16 @@ Metamaps::Application.routes.draw do namespace :api, path: '/api', default: { format: :json } do namespace :v2, path: '/v2' do - resources :metacodes, only: %i(index show) - resources :mappings, only: %i(index create show update destroy) - resources :maps, only: %i(index create show update destroy) do + resources :metacodes, only: %i[index show] + resources :mappings, only: %i[index create show update destroy] + resources :maps, only: %i[index create show update destroy] do post :stars, to: 'stars#create', on: :member delete :stars, to: 'stars#destroy', on: :member end - resources :synapses, only: %i(index create show update destroy) - resources :tokens, only: %i(index create destroy) - resources :topics, only: %i(index create show update destroy) - resources :users, only: %i(index show) do + resources :synapses, only: %i[index create show update destroy] + resources :tokens, only: %i[index create destroy] + resources :topics, only: %i[index create show update destroy] + resources :users, only: %i[index show] do get :current, on: :collection end match '*path', to: 'restful#catch_404', via: :all diff --git a/config/spring.rb b/config/spring.rb index c35b7474..ed3449f1 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -%w( +%w[ .ruby-version .ruby-gemset .rbenv-vars tmp/restart.txt tmp/caching-dev.txt -).each { |path| Spring.watch(path) } +].each { |path| Spring.watch(path) } diff --git a/script/rails b/script/rails old mode 100644 new mode 100755 diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 6a9830fa..5a255365 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -6,9 +6,7 @@ require File.expand_path('../../config/environment', __FILE__) require 'rspec/rails' # Prevent database truncation if the environment is production -if Rails.env.production? - abort('The Rails environment is running in production mode!') -end +abort('The Rails environment is running in production mode!') if Rails.env.production? # require all support files Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } @@ -17,7 +15,7 @@ ActiveRecord::Migration.maintain_test_schema! RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" + config.fixture_path = ::Rails.root.join('spec', 'fixtures') config.use_transactional_fixtures = true diff --git a/spec/support/schema_matcher.rb b/spec/support/schema_matcher.rb index f0b4a206..c74ba7d8 100644 --- a/spec/support/schema_matcher.rb +++ b/spec/support/schema_matcher.rb @@ -15,7 +15,7 @@ RSpec::Matchers.define :match_json_schema do |schema_name| end def get_json_example(resource) - filepath = "#{Rails.root}/doc/api/examples/#{resource}.json" + filepath = Rails.root.join('doc', 'api', 'examples', "#{resource}.json") OpenStruct.new(body: File.read(filepath)) end @@ -25,7 +25,7 @@ def update_file_refs(schema) schema[key] = if value.is_a? Hash update_file_refs(value) elsif key == '$ref' - "#{Rails.root}/doc/api/schemas/#{value}" + Rails.root.join('doc', 'api', 'schemas', value.to_s) else value end