diff --git a/.rubocop.yml b/.rubocop.yml index 9fb58aba..6bdcbfc3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,9 +6,16 @@ AllCops: - 'bin/**/*' - 'vendor/**/*' - 'app/assets/javascripts/node_modules/**/*' + - 'Vagrantfile' Rails: Enabled: true Metrics/LineLength: Max: 100 + +Metrics/AbcSize: + Max: 16 + +Style/Documentation: + Enabled: false diff --git a/Gemfile b/Gemfile index 4c58772c..b4a0967b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,4 @@ +# frozen_string_literal: true source 'https://rubygems.org' ruby '2.3.0' diff --git a/Rakefile b/Rakefile index 30cf58f5..74eb42c7 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,5 @@ #!/usr/bin/env rake +# frozen_string_literal: true # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. diff --git a/Vagrantfile b/Vagrantfile index 52e040cf..6ee6cb35 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -31,7 +31,7 @@ sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '3112';" SCRIPT -VAGRANTFILE_API_VERSION = '2'.freeze +VAGRANTFILE_API_VERSION = '2' Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = 'trusty64' diff --git a/app/controllers/api/v1/deprecated_controller.rb b/app/controllers/api/v1/deprecated_controller.rb index ed68b897..b9e07214 100644 --- a/app/controllers/api/v1/deprecated_controller.rb +++ b/app/controllers/api/v1/deprecated_controller.rb @@ -1,9 +1,12 @@ +# frozen_string_literal: true module Api module V1 class DeprecatedController < ApplicationController + # rubocop:disable Style/MethodMissing def method_missing - render json: { error: "/api/v1 is deprecated! Please use /api/v2 instead." } + render json: { error: '/api/v1 is deprecated! Please use /api/v2 instead.' } end + # rubocop:enable Style/MethodMissing end end end diff --git a/app/controllers/api/v1/mappings_controller.rb b/app/controllers/api/v1/mappings_controller.rb index 35c7d6bd..8ba6e704 100644 --- a/app/controllers/api/v1/mappings_controller.rb +++ b/app/controllers/api/v1/mappings_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Api module V1 class MappingsController < DeprecatedController diff --git a/app/controllers/api/v1/maps_controller.rb b/app/controllers/api/v1/maps_controller.rb index 056810f1..0ff6f472 100644 --- a/app/controllers/api/v1/maps_controller.rb +++ b/app/controllers/api/v1/maps_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Api module V1 class MapsController < DeprecatedController diff --git a/app/controllers/api/v1/synapses_controller.rb b/app/controllers/api/v1/synapses_controller.rb index e2111e95..32522e52 100644 --- a/app/controllers/api/v1/synapses_controller.rb +++ b/app/controllers/api/v1/synapses_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Api module V1 class SynapsesController < DeprecatedController diff --git a/app/controllers/api/v1/tokens_controller.rb b/app/controllers/api/v1/tokens_controller.rb index c96b1065..9df2094a 100644 --- a/app/controllers/api/v1/tokens_controller.rb +++ b/app/controllers/api/v1/tokens_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Api module V1 class TokensController < DeprecatedController diff --git a/app/controllers/api/v1/topics_controller.rb b/app/controllers/api/v1/topics_controller.rb index e974fff3..d316bfa8 100644 --- a/app/controllers/api/v1/topics_controller.rb +++ b/app/controllers/api/v1/topics_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Api module V1 class TopicsController < DeprecatedController diff --git a/app/controllers/api/v2/mappings_controller.rb b/app/controllers/api/v2/mappings_controller.rb index 7f0d9513..86aba865 100644 --- a/app/controllers/api/v2/mappings_controller.rb +++ b/app/controllers/api/v2/mappings_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Api module V2 class MappingsController < RestfulController diff --git a/app/controllers/api/v2/maps_controller.rb b/app/controllers/api/v2/maps_controller.rb index fd54fa7b..0bcd9bee 100644 --- a/app/controllers/api/v2/maps_controller.rb +++ b/app/controllers/api/v2/maps_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Api module V2 class MapsController < RestfulController diff --git a/app/controllers/api/v2/restful_controller.rb b/app/controllers/api/v2/restful_controller.rb index de86dafd..f837957d 100644 --- a/app/controllers/api/v2/restful_controller.rb +++ b/app/controllers/api/v2/restful_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Api module V2 class RestfulController < ActionController::Base @@ -51,7 +52,8 @@ module Api "Api::V2::#{resource_name.camelize}Serializer".constantize end - def respond_with_resource(scope: default_scope, serializer: resource_serializer, root: serializer_root) + def respond_with_resource(scope: default_scope, serializer: resource_serializer, + root: serializer_root) if resource.errors.empty? render json: resource, scope: scope, serializer: serializer, root: root else @@ -59,8 +61,11 @@ module Api end end - def respond_with_collection(resources: collection, scope: default_scope, serializer: resource_serializer, root: serializer_root) - render json: resources, scope: scope, each_serializer: serializer, root: root, meta: pagination(resources), meta_key: :page + def respond_with_collection(resources: collection, scope: default_scope, + serializer: resource_serializer, root: serializer_root) + pagination_link_headers!(pagination(resources)) + render json: resources, scope: scope, each_serializer: serializer, root: root, + meta: pagination(resources), meta_key: :page end def default_scope @@ -94,33 +99,36 @@ module Api end def pagination(collection) - per = (params[:per] || 25).to_i - current_page = (params[:page] || 1).to_i - total_pages = (collection.total_count.to_f / per).ceil - prev_page = current_page > 1 ? current_page - 1 : 0 - next_page = current_page < total_pages ? current_page + 1 : 0 + return @pagination_data unless @pagination_data.nil? + current_page = (params[:page] || 1).to_i + per = (params[:per] || 25).to_i + total_pages = (collection.total_count.to_f / per).ceil + @pagination_data = { + current_page: current_page, + next_page: current_page < total_pages ? current_page + 1 : 0, + prev_page: current_page > 1 ? current_page - 1 : 0, + total_pages: total_pages, + total_count: collection.total_count, + per: per + } + end + + def pagination_link_headers!(data) base_url = request.base_url + request.path - nxt = request.query_parameters.merge(page: next_page).map{|x| x.join('=')}.join('&') - prev = request.query_parameters.merge(page: prev_page).map{|x| x.join('=')}.join('&') - last = request.query_parameters.merge(page: total_pages).map{|x| x.join('=')}.join('&') + old_query = request.query_parameters + nxt = old_query.merge(page: data[:next_page]).map { |x| x.join('=') }.join('&') + prev = old_query.merge(page: data[:prev_page]).map { |x| x.join('=') }.join('&') + last = old_query.merge(page: data[:total_pages]).map { |x| x.join('=') }.join('&') + response.headers['Link'] = [ %(<#{base_url}?#{nxt}>; rel="next"), %(<#{base_url}?#{prev}>; rel="prev"), %(<#{base_url}?#{last}>; rel="last") ].join(',') - response.headers['X-Total-Pages'] = collection.total_pages.to_s - response.headers['X-Total-Count'] = collection.total_count.to_s - response.headers['X-Per-Page'] = per.to_s - - { - current_page: current_page, - next_page: next_page, - prev_page: prev_page, - total_pages: total_pages, - total_count: collection.total_count, - per: per - } + response.headers['X-Total-Pages'] = data[:total_pages].to_s + response.headers['X-Total-Count'] = data[:total_count].to_s + response.headers['X-Per-Page'] = data[:per].to_s end def instantiate_collection @@ -163,7 +171,7 @@ module Api builder = builder.order(sort => direction) end end - return builder + builder end def visible_records diff --git a/app/controllers/api/v2/sessions_controller.rb b/app/controllers/api/v2/sessions_controller.rb index 3aefa214..2aa93669 100644 --- a/app/controllers/api/v2/sessions_controller.rb +++ b/app/controllers/api/v2/sessions_controller.rb @@ -1,9 +1,10 @@ +# frozen_string_literal: true module Api module V2 class SessionsController < ApplicationController def create @user = User.find_by(email: params[:email]) - if @user && @user.valid_password(params[:password]) + if @user&.valid_password(params[:password]) sign_in(@user) render json: @user else diff --git a/app/controllers/api/v2/synapses_controller.rb b/app/controllers/api/v2/synapses_controller.rb index 6572997d..6484699e 100644 --- a/app/controllers/api/v2/synapses_controller.rb +++ b/app/controllers/api/v2/synapses_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Api module V2 class SynapsesController < RestfulController diff --git a/app/controllers/api/v2/tokens_controller.rb b/app/controllers/api/v2/tokens_controller.rb index 6eeb102b..d1a6b255 100644 --- a/app/controllers/api/v2/tokens_controller.rb +++ b/app/controllers/api/v2/tokens_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Api module V2 class TokensController < RestfulController diff --git a/app/controllers/api/v2/topics_controller.rb b/app/controllers/api/v2/topics_controller.rb index 74fa7105..22e534ce 100644 --- a/app/controllers/api/v2/topics_controller.rb +++ b/app/controllers/api/v2/topics_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Api module V2 class TopicsController < RestfulController diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 58c996c5..83889619 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class ApplicationController < ActionController::Base include ApplicationHelper include Pundit @@ -5,7 +6,7 @@ class ApplicationController < ActionController::Base rescue_from Pundit::NotAuthorizedError, with: :handle_unauthorized protect_from_forgery(with: :exception) - before_action :get_invite_link + before_action :invite_link after_action :allow_embedding def default_serializer_options @@ -41,29 +42,26 @@ class ApplicationController < ActionController::Base private - def get_invite_link + def invite_link @invite_link = "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '') end def require_no_user - if authenticated? - redirect_to edit_user_path(user), notice: 'You must be logged out.' - return false - end + return true unless authenticated? + redirect_to edit_user_path(user), notice: 'You must be logged out.' + return false end def require_user - unless authenticated? - redirect_to new_user_session_path, notice: 'You must be logged in.' - return false - end + return true if authenticated? + redirect_to new_user_session_path, notice: 'You must be logged in.' + return false end def require_admin - unless authenticated? && admin? - redirect_to root_url, notice: 'You need to be an admin for that.' - return false - end + return true if authenticated? && admin? + redirect_to root_url, notice: 'You need to be an admin for that.' + false end def user diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 01304328..0d6af64b 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class MainController < ApplicationController include TopicsHelper include MapsHelper @@ -12,13 +13,13 @@ class MainController < ApplicationController def home @maps = policy_scope(Map).order('updated_at DESC').page(1).per(20) respond_to do |format| - format.html { - if !authenticated? - render 'main/home' - else - render 'maps/activemaps' - end - } + format.html do + if !authenticated? + render 'main/home' + else + render 'maps/activemaps' + end + end end end @@ -163,8 +164,8 @@ class MainController < ApplicationController @synapses = [] end - #limit to 5 results - @synapses = @synapses.to_a.slice(0,5) + # limit to 5 results + @synapses = @synapses.to_a.slice(0, 5) render json: autocomplete_synapse_array_json(@synapses) end diff --git a/app/controllers/mappings_controller.rb b/app/controllers/mappings_controller.rb index 3d162c0f..de2c8ea1 100644 --- a/app/controllers/mappings_controller.rb +++ b/app/controllers/mappings_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class MappingsController < ApplicationController before_action :require_user, only: [:create, :update, :destroy] after_action :verify_authorized, except: :index diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 22e75819..4a091e17 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class MapsController < ApplicationController before_action :require_user, only: [:create, :update, :access, :star, :unstar, :screenshot, :events, :destroy] after_action :verify_authorized, except: [:activemaps, :featuredmaps, :mymaps, :sharedmaps, :starredmaps, :usermaps] @@ -107,14 +108,14 @@ class MapsController < ApplicationController # GET maps/new def new - @map = Map.new(name: "Untitled Map", permission: "public", arranged: true) + @map = Map.new(name: 'Untitled Map', permission: 'public', arranged: true) authorize @map respond_to do |format| format.html do @map.user = current_user @map.save - redirect_to(map_path(@map) + '?new') + redirect_to(map_path(@map) + '?new') end end end @@ -305,9 +306,7 @@ class MapsController < ApplicationController @map = Map.find(params[:id]) authorize @map star = Star.find_by_map_id_and_user_id(@map.id, current_user.id) - if not star - star = Star.create(map_id: @map.id, user_id: current_user.id) - end + star = Star.create(map_id: @map.id, user_id: current_user.id) unless star respond_to do |format| format.json do @@ -321,9 +320,7 @@ class MapsController < ApplicationController @map = Map.find(params[:id]) authorize @map star = Star.find_by_map_id_and_user_id(@map.id, current_user.id) - if star - star.delete - end + star&.delete respond_to do |format| format.json do diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index ec59a2a4..dd3544e9 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class MessagesController < ApplicationController before_action :require_user, except: [:show] after_action :verify_authorized diff --git a/app/controllers/metacode_sets_controller.rb b/app/controllers/metacode_sets_controller.rb index a57c557f..8fec58cc 100644 --- a/app/controllers/metacode_sets_controller.rb +++ b/app/controllers/metacode_sets_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class MetacodeSetsController < ApplicationController before_action :require_admin diff --git a/app/controllers/metacodes_controller.rb b/app/controllers/metacodes_controller.rb index 313d9764..00f92878 100644 --- a/app/controllers/metacodes_controller.rb +++ b/app/controllers/metacodes_controller.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true class MetacodesController < ApplicationController before_action :require_admin, except: [:index, :show] + before_action :set_metacode, only: [:edit, :update] # GET /metacodes # GET /metacodes.json @@ -8,10 +10,7 @@ class MetacodesController < ApplicationController respond_to do |format| format.html do - unless authenticated? && user.admin - redirect_to root_url, notice: 'You need to be an admin for that.' - return false - end + return unless require_admin render :index end format.json { render json: @metacodes } @@ -23,7 +22,7 @@ class MetacodesController < ApplicationController # GET /metacodes/action.json def show @metacode = Metacode.where('DOWNCASE(name) = ?', downcase(params[:name])).first if params[:name] - @metacode = Metacode.find(params[:id]) unless @metacode + set_metacode unless @metacode respond_to do |format| format.json { render json: @metacode } @@ -36,14 +35,13 @@ class MetacodesController < ApplicationController @metacode = Metacode.new respond_to do |format| - format.html # new.html.erb + format.html format.json { render json: @metacode } end end # GET /metacodes/1/edit def edit - @metacode = Metacode.find(params[:id]) end # POST /metacodes @@ -65,8 +63,6 @@ class MetacodesController < ApplicationController # PUT /metacodes/1 # PUT /metacodes/1.json def update - @metacode = Metacode.find(params[:id]) - respond_to do |format| if @metacode.update(metacode_params) format.html { redirect_to metacodes_url, notice: 'Metacode was successfully updated.' } @@ -84,4 +80,8 @@ class MetacodesController < ApplicationController def metacode_params params.require(:metacode).permit(:id, :name, :aws_icon, :manual_icon, :color) end + + def set_metacode + @metacode = Metacode.find(params[:id]) + end end diff --git a/app/controllers/synapses_controller.rb b/app/controllers/synapses_controller.rb index ddb3e5ab..8fc31688 100644 --- a/app/controllers/synapses_controller.rb +++ b/app/controllers/synapses_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class SynapsesController < ApplicationController include TopicsHelper diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 30ac57fd..1b966ca2 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class TopicsController < ApplicationController include TopicsHelper diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb index ee7b8667..bffe3ab6 100644 --- a/app/controllers/users/passwords_controller.rb +++ b/app/controllers/users/passwords_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Users::PasswordsController < Devise::PasswordsController protected @@ -5,7 +6,7 @@ class Users::PasswordsController < Devise::PasswordsController signed_in_root_path(resource) end - def after_sending_reset_password_instructions_path_for(resource_name) + def after_sending_reset_password_instructions_path_for(_resource_name) new_user_session_path if is_navigational_format? end end diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 8895cfd2..21cd9666 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Users::RegistrationsController < Devise::RegistrationsController before_action :configure_sign_up_params, only: [:create] before_action :configure_account_update_params, only: [:update] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0ea95211..a9fff9de 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class UsersController < ApplicationController before_action :require_user, only: [:edit, :update, :updatemetacodes] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 555a32d2..1c9b4da5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,13 +1,14 @@ +# frozen_string_literal: true module ApplicationHelper - def get_metacodeset - @m = current_user.settings.metacodes - set = @m[0].include?('metacodeset') ? MetacodeSet.find(@m[0].sub('metacodeset-', '').to_i) : false - set + def metacodeset + metacodes = current_user.settings.metacodes + return false unless metacodes[0].include?('metacodeset') + MetacodeSet.find(metacodes[0].sub('metacodeset-', '').to_i) end def user_metacodes @m = current_user.settings.metacodes - set = get_metacodeset + set = metacodeset @metacodes = if set set.metacodes.to_a else @@ -16,7 +17,7 @@ module ApplicationHelper @metacodes.sort! { |m1, m2| m2.name.downcase <=> m1.name.downcase }.rotate!(-1) end - def determine_invite_link + def invite_link "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '') end end diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 4a8820f0..4fb2fe84 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ContentHelper def resource_name :user diff --git a/app/helpers/devise_helper.rb b/app/helpers/devise_helper.rb index 5081cba0..4b34effc 100644 --- a/app/helpers/devise_helper.rb +++ b/app/helpers/devise_helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module DeviseHelper def devise_error_messages! resource.errors.to_a[0] diff --git a/app/helpers/in_metacode_sets_helper.rb b/app/helpers/in_metacode_sets_helper.rb index 52a47cdc..0c45fd98 100644 --- a/app/helpers/in_metacode_sets_helper.rb +++ b/app/helpers/in_metacode_sets_helper.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true module InMetacodeSetsHelper end diff --git a/app/helpers/main_helper.rb b/app/helpers/main_helper.rb index 826effed..33378f43 100644 --- a/app/helpers/main_helper.rb +++ b/app/helpers/main_helper.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true module MainHelper end diff --git a/app/helpers/mapping_helper.rb b/app/helpers/mapping_helper.rb index 7055739f..9dd903ca 100644 --- a/app/helpers/mapping_helper.rb +++ b/app/helpers/mapping_helper.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true module MappingHelper end diff --git a/app/helpers/maps_helper.rb b/app/helpers/maps_helper.rb index 3f60fe4d..0ca99c15 100644 --- a/app/helpers/maps_helper.rb +++ b/app/helpers/maps_helper.rb @@ -1,34 +1,42 @@ +# frozen_string_literal: true module MapsHelper - ## this one is for building our custom JSON autocomplete format for typeahead + # JSON autocomplete format for typeahead def autocomplete_map_array_json(maps) - temp = [] - maps.each do |m| - map = {} - map['id'] = m.id - map['label'] = m.name - map['value'] = m.name - map['description'] = m.desc.try(:truncate, 30) - map['permission'] = m.permission - map['topicCount'] = m.topics.count - map['synapseCount'] = m.synapses.count - map['contributorCount'] = m.contributors.count - map['rtype'] = 'map' - - contributorTip = '' - firstContributorImage = 'https://s3.amazonaws.com/metamaps-assets/site/user.png' - if m.contributors.count > 0 - firstContributorImage = m.contributors[0].image.url(:thirtytwo) - m.contributors.each_with_index do |c, _index| - userImage = c.image.url(:thirtytwo) - name = c.name - contributorTip += '
  • ' + '' + name + '
  • ' - end - end - map['contributorTip'] = contributorTip - map['mapContributorImage'] = firstContributorImage - - temp.push map + maps.map do |m| + { + id: m.id, + label: m.name, + value: m.name, + description: m.desc.try(:truncate, 30), + permission: m.permission, + topicCount: m.topics.count, + synapseCount: m.synapses.count, + contributorCount: m.contributors.count, + rtype: 'map', + contributorTip: contributor_tip(map), + mapContributorImage: first_contributor_image(map) + } end - temp + end + + def first_contributor_image(map) + if map.contributors.count.positive? + return map.contributors[0].image.url(:thirtytwo) + end + 'https://s3.amazonaws.com/metamaps-assets/site/user.png' + end + + def contributor_tip(map) + output = '' + if map.contributors.count.positive? + map.contributors.each_with_index do |contributor, _index| + user_image = contributor.image.url(:thirtytwo) + output += '
  • ' + output += %() + output += "#{contributor.name}" + output += '
  • ' + end + end + output end end diff --git a/app/helpers/metacode_sets_helper.rb b/app/helpers/metacode_sets_helper.rb index 668ceb5c..9a6e09c7 100644 --- a/app/helpers/metacode_sets_helper.rb +++ b/app/helpers/metacode_sets_helper.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true module MetacodeSetsHelper end diff --git a/app/helpers/metacodes_helper.rb b/app/helpers/metacodes_helper.rb index c896d26d..d00f1ef5 100644 --- a/app/helpers/metacodes_helper.rb +++ b/app/helpers/metacodes_helper.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true module MetacodesHelper end diff --git a/app/helpers/synapses_helper.rb b/app/helpers/synapses_helper.rb index 470292e5..def3b985 100644 --- a/app/helpers/synapses_helper.rb +++ b/app/helpers/synapses_helper.rb @@ -1,33 +1,25 @@ +# frozen_string_literal: true module SynapsesHelper ## this one is for building our custom JSON autocomplete format for typeahead def autocomplete_synapse_generic_json(unique) - temp = [] - unique.each do |s| - synapse = {} - synapse['label'] = s.desc - synapse['value'] = s.desc - - temp.push synapse + unique.map do |s| + { label: s.desc, value: s.desc } end - temp end ## this one is for building our custom JSON autocomplete format for typeahead def autocomplete_synapse_array_json(synapses) - temp = [] - synapses.each do |s| - synapse = {} - synapse['id'] = s.id - synapse['label'] = s.desc.nil? || s.desc == '' ? '(no description)' : s.desc - synapse['value'] = s.desc - synapse['permission'] = s.permission - synapse['mapCount'] = s.maps.count - synapse['originator'] = s.user.name - synapse['originatorImage'] = s.user.image.url(:thirtytwo) - synapse['rtype'] = 'synapse' - - temp.push synapse + synapses.map do |s| + { + id: s.id, + label: s.desc.blank? ? '(no description)' : s.desc, + value: s.desc, + permission: s.permission, + mapCount: s.maps.count, + originator: s.user.name, + originatorImage: s.user.image.url(:thirtytwo), + rtype: 'synapse' + } end - temp end end diff --git a/app/helpers/topics_helper.rb b/app/helpers/topics_helper.rb index bb589e9a..e1a1d179 100644 --- a/app/helpers/topics_helper.rb +++ b/app/helpers/topics_helper.rb @@ -1,56 +1,39 @@ +# frozen_string_literal: true module TopicsHelper ## this one is for building our custom JSON autocomplete format for typeahead def autocomplete_array_json(topics) - temp = [] - topics.each do |t| - topic = {} - topic['id'] = t.id - topic['label'] = t.name - topic['value'] = t.name - topic['description'] = t.desc ? t.desc.truncate(70) : '' # make this return matched results - topic['type'] = t.metacode.name - topic['typeImageURL'] = t.metacode.icon - topic['permission'] = t.permission - topic['mapCount'] = t.maps.count - topic['synapseCount'] = t.synapses.count - topic['originator'] = t.user.name - topic['originatorImage'] = t.user.image.url(:thirtytwo) - topic['rtype'] = 'topic' - topic['inmaps'] = t.inmaps - topic['inmapsLinks'] = t.inmapsLinks - - temp.push topic + topics.map do |t| + { + id: t.id, + label: t.name, + value: t.name, + description: t.desc ? t.desc&.truncate(70) : '', # make this return matched results + type: t.metacode.name, + typeImageURL: t.metacode.icon, + permission: t.permission, + mapCount: t.maps.count, + synapseCount: t.synapses.count, + originator: t.user.name, + originatorImage: t.user.image.url(:thirtytwo), + rtype: :topic, + inmaps: t.inmaps, + inmapsLinks: t.inmapsLinks + } end - temp end - # find all nodes in any given nodes network + # recursively find all nodes in any given nodes network def network(node, array, count) - # recurse starting with a node to find all connected nodes and return an array of topics that constitutes the starting nodes network - - # if the array of nodes is empty initialize it array = [] if array.nil? - - # add the node to the array array.push(node) - - return array if count == 0 - - count -= 1 + return array if count.zero? # check if each relative is already in the array and if not, call the network function again - if !node.relatives.empty? - if (node.relatives - array).empty? - return array - else - (node.relatives - array).each do |relative| - array = (array | network(relative, array, count)) - end - return array - end - - elsif node.relatives.empty? - return array + remaining_relatives = node.relatives.to_a - array + remaining_relatives.each do |relative| + array = (array | network(relative, array, count - 1)) end + + array end end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 8144dfd8..379cf20a 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module UsersHelper # build custom json autocomplete for typeahead def autocomplete_user_array_json(users) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index d934e218..59a2175a 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class ApplicationMailer < ActionMailer::Base default from: 'team@metamaps.cc' layout 'mailer' diff --git a/app/mailers/map_mailer.rb b/app/mailers/map_mailer.rb index 94e8ebd5..e70d0b82 100644 --- a/app/mailers/map_mailer.rb +++ b/app/mailers/map_mailer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class MapMailer < ApplicationMailer default from: 'team@metamaps.cc' diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba8..767a072b 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end diff --git a/app/models/concerns/routing.rb b/app/models/concerns/routing.rb index 2f8467bf..ddbfad6f 100644 --- a/app/models/concerns/routing.rb +++ b/app/models/concerns/routing.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Routing extend ActiveSupport::Concern include Rails.application.routes.url_helpers diff --git a/app/models/event.rb b/app/models/event.rb index 90407314..02c6d698 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Event < ApplicationRecord KINDS = %w(user_present_on_map conversation_started_on_map topic_added_to_map synapse_added_to_map).freeze diff --git a/app/models/events/conversation_started_on_map.rb b/app/models/events/conversation_started_on_map.rb index 4ca922be..20fb89c1 100644 --- a/app/models/events/conversation_started_on_map.rb +++ b/app/models/events/conversation_started_on_map.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Events::ConversationStartedOnMap < Event # after_create :notify_users! diff --git a/app/models/events/new_mapping.rb b/app/models/events/new_mapping.rb index d7b91576..889c69bc 100644 --- a/app/models/events/new_mapping.rb +++ b/app/models/events/new_mapping.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Events::NewMapping < Event # after_create :notify_users! diff --git a/app/models/events/user_present_on_map.rb b/app/models/events/user_present_on_map.rb index 45726002..38d524ef 100644 --- a/app/models/events/user_present_on_map.rb +++ b/app/models/events/user_present_on_map.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Events::UserPresentOnMap < Event # after_create :notify_users! diff --git a/app/models/in_metacode_set.rb b/app/models/in_metacode_set.rb index de1f2514..78dc1c29 100644 --- a/app/models/in_metacode_set.rb +++ b/app/models/in_metacode_set.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class InMetacodeSet < ApplicationRecord belongs_to :metacode, class_name: 'Metacode', foreign_key: 'metacode_id' belongs_to :metacode_set, class_name: 'MetacodeSet', foreign_key: 'metacode_set_id' diff --git a/app/models/map.rb b/app/models/map.rb index f59eb790..9c30479f 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Map < ApplicationRecord belongs_to :user @@ -19,7 +20,7 @@ class Map < ApplicationRecord thumb: ['188x126#', :png] #:full => ['940x630#', :png] }, - default_url: 'https://s3.amazonaws.com/metamaps-assets/site/missing-map-white.png' + default_url: 'https://s3.amazonaws.com/metamaps-assets/site/missing-map-white.png' validates :name, presence: true validates :arranged, inclusion: { in: [true, false] } diff --git a/app/models/mapping.rb b/app/models/mapping.rb index eba7a6d2..f7219008 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Mapping < ApplicationRecord scope :topicmapping, -> { where(mappable_type: :Topic) } scope :synapsemapping, -> { where(mappable_type: :Synapse) } diff --git a/app/models/message.rb b/app/models/message.rb index 348c5d4e..682b7e51 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Message < ApplicationRecord belongs_to :user belongs_to :resource, polymorphic: true diff --git a/app/models/metacode.rb b/app/models/metacode.rb index 9b05bee5..c97c4fb5 100644 --- a/app/models/metacode.rb +++ b/app/models/metacode.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Metacode < ApplicationRecord has_many :in_metacode_sets has_many :metacode_sets, through: :in_metacode_sets diff --git a/app/models/metacode_set.rb b/app/models/metacode_set.rb index c52811fd..72bcc719 100644 --- a/app/models/metacode_set.rb +++ b/app/models/metacode_set.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class MetacodeSet < ApplicationRecord belongs_to :user has_many :in_metacode_sets diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb index 0ccea1c8..d0696985 100644 --- a/app/models/permitted_params.rb +++ b/app/models/permitted_params.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class PermittedParams < Struct.new(:params) %w(map synapse topic mapping token).each do |kind| define_method(kind) do diff --git a/app/models/star.rb b/app/models/star.rb index 52a77044..dcaaa559 100644 --- a/app/models/star.rb +++ b/app/models/star.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Star < ActiveRecord::Base belongs_to :user belongs_to :map diff --git a/app/models/synapse.rb b/app/models/synapse.rb index afd40a25..798f6a54 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Synapse < ApplicationRecord belongs_to :user belongs_to :defer_to_map, class_name: 'Map', foreign_key: 'defer_to_map_id' @@ -21,17 +22,12 @@ class Synapse < ApplicationRecord where('node1_id = ? OR node2_id = ?', topic_id, topic_id) } - # :nocov: delegate :name, to: :user, prefix: true - # :nocov: - # :nocov: def user_image user.image.url end - # :nocov: - # :nocov: def collaborator_ids if defer_to_map defer_to_map.editors.select { |mapper| mapper != user }.map(&:id) @@ -39,21 +35,12 @@ class Synapse < ApplicationRecord [] end end - # :nocov: - # :nocov: def calculated_permission - if defer_to_map - defer_to_map.permission - else - permission - end + defer_to_map&.permission || permission end - # :nocov: - # :nocov: def as_json(_options = {}) super(methods: [:user_name, :user_image, :calculated_permission, :collaborator_ids]) end - # :nocov: end diff --git a/app/models/token.rb b/app/models/token.rb index 9103aebc..9cd93043 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Token < ApplicationRecord belongs_to :user diff --git a/app/models/topic.rb b/app/models/topic.rb index c250338b..fb635da3 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Topic < ApplicationRecord include TopicsHelper @@ -73,11 +74,7 @@ class Topic < ApplicationRecord end def calculated_permission - if defer_to_map - defer_to_map.permission - else - permission - end + defer_to_map&.permission || permission end def as_json(_options = {}) diff --git a/app/models/user.rb b/app/models/user.rb index 876e10cd..4da66e57 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'open-uri' class User < ApplicationRecord @@ -41,7 +42,7 @@ class User < ApplicationRecord default_url: 'https://s3.amazonaws.com/metamaps-assets/site/user.png' # Validate the attached image is image/jpg, image/png, etc - validates_attachment_content_type :image, content_type: %r(\Aimage/.*\Z) + validates_attachment_content_type :image, content_type: %r{\Aimage/.*\Z} # override default as_json def as_json(_options = {}) @@ -79,8 +80,8 @@ class User < ApplicationRecord end end - def starred_map?(map) - return self.stars.where(map_id: map.id).exists? + def starred_map?(map) + stars.where(map_id: map.id).exists? end def settings diff --git a/app/models/user_map.rb b/app/models/user_map.rb index c48cfb96..dc268047 100644 --- a/app/models/user_map.rb +++ b/app/models/user_map.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class UserMap < ApplicationRecord belongs_to :map belongs_to :user diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 3aadbdb3..29ca3948 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class UserPreference attr_accessor :metacodes @@ -9,7 +10,7 @@ class UserPreference array.push(metacode.id.to_s) if metacode rescue ActiveRecord::StatementInvalid if m == 'Action' - Rails.logger.warn("TODO: remove this travis workaround in user_preference.rb") + Rails.logger.warn('TODO: remove this travis workaround in user_preference.rb') end end end diff --git a/app/models/webhook.rb b/app/models/webhook.rb index 6389398e..65057411 100644 --- a/app/models/webhook.rb +++ b/app/models/webhook.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Webhook < ApplicationRecord belongs_to :hookable, polymorphic: true diff --git a/app/models/webhooks/slack/base.rb b/app/models/webhooks/slack/base.rb index 97cf1f04..960775dd 100644 --- a/app/models/webhooks/slack/base.rb +++ b/app/models/webhooks/slack/base.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Webhooks::Slack::Base = Struct.new(:event) do include Routing diff --git a/app/models/webhooks/slack/conversation_started_on_map.rb b/app/models/webhooks/slack/conversation_started_on_map.rb index 5fa325d0..daf2270e 100644 --- a/app/models/webhooks/slack/conversation_started_on_map.rb +++ b/app/models/webhooks/slack/conversation_started_on_map.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Webhooks::Slack::ConversationStartedOnMap < Webhooks::Slack::Base def text "There is a live conversation starting on map *#{event.map.name}*. #{view_map_on_metamaps('Join in!')}" diff --git a/app/models/webhooks/slack/synapse_added_to_map.rb b/app/models/webhooks/slack/synapse_added_to_map.rb index 5dc636e1..5157afa7 100644 --- a/app/models/webhooks/slack/synapse_added_to_map.rb +++ b/app/models/webhooks/slack/synapse_added_to_map.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Webhooks::Slack::SynapseAddedToMap < Webhooks::Slack::Base def text "\"*#{eventable.mappable.topic1.name}* #{eventable.mappable.desc || '->'} *#{eventable.mappable.topic2.name}*\" was added as a connection to the map *#{view_map_on_metamaps}*" diff --git a/app/models/webhooks/slack/topic_added_to_map.rb b/app/models/webhooks/slack/topic_added_to_map.rb index 07a20759..d3a19760 100644 --- a/app/models/webhooks/slack/topic_added_to_map.rb +++ b/app/models/webhooks/slack/topic_added_to_map.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Webhooks::Slack::TopicAddedToMap < Webhooks::Slack::Base def text "New #{eventable.mappable.metacode.name} topic *#{eventable.mappable.name}* was added to the map *#{view_map_on_metamaps}*" diff --git a/app/models/webhooks/slack/user_present_on_map.rb b/app/models/webhooks/slack/user_present_on_map.rb index 666d5121..c3185e48 100644 --- a/app/models/webhooks/slack/user_present_on_map.rb +++ b/app/models/webhooks/slack/user_present_on_map.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Webhooks::Slack::UserPresentOnMap < Webhooks::Slack::Base def text "Mapper *#{event.user.name}* has joined the map *#{event.map.name}*. #{view_map_on_metamaps('Map with them')}" diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index a9835c98..348ef5f2 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class ApplicationPolicy attr_reader :user, :record @@ -39,7 +40,7 @@ class ApplicationPolicy # explicitly say they want to (E.g. seeing/editing/deleting private # maps - they should be able to, but not by accident) def admin_override - user && user.admin + user&.admin end def scope diff --git a/app/policies/main_policy.rb b/app/policies/main_policy.rb index 77ab373c..e0ffc30b 100644 --- a/app/policies/main_policy.rb +++ b/app/policies/main_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class MainPolicy < ApplicationPolicy def initialize(user, _record) @user = user diff --git a/app/policies/map_policy.rb b/app/policies/map_policy.rb index 0a2b33ce..4cb2db38 100644 --- a/app/policies/map_policy.rb +++ b/app/policies/map_policy.rb @@ -1,14 +1,13 @@ +# frozen_string_literal: true class MapPolicy < ApplicationPolicy class Scope < Scope def resolve visible = %w(public commons) - permission = 'maps.permission IN (?)' - if user - shared_maps = user.shared_maps.map(&:id) - scope.where(permission + ' OR maps.id IN (?) OR maps.user_id = ?', visible, shared_maps, user.id) - else - scope.where(permission, visible) - end + return scope.where(permission: visible) unless user + + scope.where(permission: visible) + .or(scope.where(id: user.shared_maps.map(&:id))) + .or(scope.where(user_id: user.id)) end end @@ -17,7 +16,9 @@ class MapPolicy < ApplicationPolicy end def show? - record.permission == 'commons' || record.permission == 'public' || record.collaborators.include?(user) || record.user == user + record.permission.in?(['commons', 'public']) || + record.collaborators.include?(user) || + record.user == user end def create? @@ -25,7 +26,10 @@ class MapPolicy < ApplicationPolicy end def update? - user.present? && (record.permission == 'commons' || record.collaborators.include?(user) || record.user == user) + return false unless user.present? + record.permission == 'commons' || + record.collaborators.include?(user) || + record.user == user end def destroy? @@ -33,7 +37,7 @@ class MapPolicy < ApplicationPolicy end def access? - # note that this is to edit access + # note that this is to edit who can access the map user.present? && record.user == user end diff --git a/app/policies/mapping_policy.rb b/app/policies/mapping_policy.rb index 1cd99783..efcb798b 100644 --- a/app/policies/mapping_policy.rb +++ b/app/policies/mapping_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class MappingPolicy < ApplicationPolicy class Scope < Scope def resolve diff --git a/app/policies/message_policy.rb b/app/policies/message_policy.rb index 8df6e916..f35a2895 100644 --- a/app/policies/message_policy.rb +++ b/app/policies/message_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class MessagePolicy < ApplicationPolicy class Scope < Scope def resolve diff --git a/app/policies/synapse_policy.rb b/app/policies/synapse_policy.rb index 310b3947..eae820b3 100644 --- a/app/policies/synapse_policy.rb +++ b/app/policies/synapse_policy.rb @@ -1,13 +1,14 @@ +# frozen_string_literal: true class SynapsePolicy < ApplicationPolicy class Scope < Scope def resolve visible = %w(public commons) - permission = 'synapses.permission IN (?)' - if user - scope.where(permission + ' OR synapses.defer_to_map_id IN (?) OR synapses.user_id = ?', visible, user.shared_maps.map(&:id), user.id) - else - scope.where(permission, visible) - end + + return scope.where(permission: visible) unless user + + scope.where(permission: visible) + .or(scope.where(defer_to_map_id: user.shared_maps.map(&:id))) + .or(scope.where(user_id: user.id)) end end diff --git a/app/policies/token_policy.rb b/app/policies/token_policy.rb index e150fec9..cd9a5ab7 100644 --- a/app/policies/token_policy.rb +++ b/app/policies/token_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class TokenPolicy < ApplicationPolicy class Scope < Scope def resolve diff --git a/app/policies/topic_policy.rb b/app/policies/topic_policy.rb index 7bca6770..7bcf585c 100644 --- a/app/policies/topic_policy.rb +++ b/app/policies/topic_policy.rb @@ -1,13 +1,13 @@ +# frozen_string_literal: true class TopicPolicy < ApplicationPolicy class Scope < Scope def resolve visible = %w(public commons) - permission = 'topics.permission IN (?)' - if user - scope.where(permission + ' OR topics.defer_to_map_id IN (?) OR topics.user_id = ?', visible, user.shared_maps.map(&:id), user.id) - else - scope.where(permission, visible) - end + return scope.where(permission: visible) unless user + + scope.where(permission: visible) + .or(scope.where(defer_to_map_id: user.shared_maps.map(&:id))) + .or(scope.where(user_id: user.id)) end end @@ -23,14 +23,13 @@ class TopicPolicy < ApplicationPolicy if record.defer_to_map.present? map_policy.show? else - record.permission == 'commons' || record.permission == 'public' || record.user == user + record.permission.in?(['commons', 'public']) || record.user == user end end def update? - if !user.present? - false - elsif record.defer_to_map.present? + return false unless user.present? + if record.defer_to_map.present? map_policy.update? else record.permission == 'commons' || record.user == user diff --git a/app/serializers/api/v2/application_serializer.rb b/app/serializers/api/v2/application_serializer.rb index f943646c..a5da830a 100644 --- a/app/serializers/api/v2/application_serializer.rb +++ b/app/serializers/api/v2/application_serializer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Api module V2 class ApplicationSerializer < ActiveModel::Serializer @@ -6,21 +7,40 @@ module Api end def embeds + # subclasses can override self.embeddable, and then it will whitelist + # scope[:embeds] based on the contents. That way scope[:embeds] can just pull + # from params and the whitelisting happens here @embeds ||= (scope[:embeds] || []).select { |e| self.class.embeddable.keys.include?(e) } end + # self.embeddable might look like this: + # topic1: { attr: :node1, serializer: TopicSerializer } + # topic2: { attr: :node2, serializer: TopicSerializer } + # contributors: { serializer: UserSerializer} + # This method will remove the :attr key if the underlying attribute name + # is different than the name provided in the final json output. All other keys + # in the hash will be passed to the ActiveModel::Serializer `attribute` method + # directly (e.g. serializer in the examples will be passed). + # + # This setup means if you passed this self.embeddable config and sent no + # ?embed= query param with your API request, you would get the regular attributes + # plus topic1_id, topic2_id, and contributor_ids. If you pass + # ?embed=topic1,topic2,contributors, then instead of two ids and an array of ids, + # you would get two serialized topics and an array of serialized users def self.embed_dat embeddable.each_pair do |key, opts| attr = opts.delete(:attr) || key if attr.to_s.pluralize == attr.to_s - attribute "#{attr.to_s.singularize}_ids".to_sym, opts.merge(unless: -> { embeds.include?(key) }) do + attribute("#{attr.to_s.singularize}_ids".to_sym, + opts.merge(unless: -> { embeds.include?(key) })) do object.send(attr).map(&:id) end - has_many attr, opts.merge(if: -> { embeds.include?(key) }) + has_many(attr, opts.merge(if: -> { embeds.include?(key) })) else id_opts = opts.merge(key: "#{key}_id") - attribute "#{attr}_id".to_sym, id_opts.merge(unless: -> { embeds.include?(key) }) - attribute key, opts.merge(if: -> { embeds.include?(key) }) + attribute("#{attr}_id".to_sym, + id_opts.merge(unless: -> { embeds.include?(key) })) + attribute(key, opts.merge(if: -> { embeds.include?(key) })) end end end diff --git a/app/serializers/api/v2/event_serializer.rb b/app/serializers/api/v2/event_serializer.rb index 644598cf..c875056a 100644 --- a/app/serializers/api/v2/event_serializer.rb +++ b/app/serializers/api/v2/event_serializer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Api module V2 class EventSerializer < ApplicationSerializer diff --git a/app/serializers/api/v2/map_serializer.rb b/app/serializers/api/v2/map_serializer.rb index 438f97ee..0a0be2c0 100644 --- a/app/serializers/api/v2/map_serializer.rb +++ b/app/serializers/api/v2/map_serializer.rb @@ -1,13 +1,14 @@ +# frozen_string_literal: true module Api module V2 class MapSerializer < ApplicationSerializer attributes :id, - :name, - :desc, - :permission, - :screenshot, - :created_at, - :updated_at + :name, + :desc, + :permission, + :screenshot, + :created_at, + :updated_at def self.embeddable { @@ -20,7 +21,7 @@ module Api } end - self.class_eval do + class_eval do embed_dat end end diff --git a/app/serializers/api/v2/mapping_serializer.rb b/app/serializers/api/v2/mapping_serializer.rb index dc36421e..19e7318e 100644 --- a/app/serializers/api/v2/mapping_serializer.rb +++ b/app/serializers/api/v2/mapping_serializer.rb @@ -1,11 +1,12 @@ +# frozen_string_literal: true module Api module V2 class MappingSerializer < ApplicationSerializer attributes :id, - :created_at, - :updated_at, - :mappable_id, - :mappable_type + :created_at, + :updated_at, + :mappable_id, + :mappable_type attribute :xloc, if: -> { object.mappable_type == 'Topic' } attribute :yloc, if: -> { object.mappable_type == 'Topic' } @@ -17,7 +18,7 @@ module Api } end - self.class_eval do + class_eval do embed_dat end end diff --git a/app/serializers/api/v2/metacode_serializer.rb b/app/serializers/api/v2/metacode_serializer.rb index 4f4daa35..16013e33 100644 --- a/app/serializers/api/v2/metacode_serializer.rb +++ b/app/serializers/api/v2/metacode_serializer.rb @@ -1,11 +1,12 @@ +# frozen_string_literal: true module Api module V2 class MetacodeSerializer < ApplicationSerializer attributes :id, - :name, - :manual_icon, - :color, - :aws_icon + :name, + :manual_icon, + :color, + :aws_icon end end end diff --git a/app/serializers/api/v2/synapse_serializer.rb b/app/serializers/api/v2/synapse_serializer.rb index 9ef86660..f647022c 100644 --- a/app/serializers/api/v2/synapse_serializer.rb +++ b/app/serializers/api/v2/synapse_serializer.rb @@ -1,12 +1,13 @@ +# frozen_string_literal: true module Api module V2 class SynapseSerializer < ApplicationSerializer attributes :id, - :desc, - :category, - :permission, - :created_at, - :updated_at + :desc, + :category, + :permission, + :created_at, + :updated_at def self.embeddable { @@ -16,7 +17,7 @@ module Api } end - self.class_eval do + class_eval do embed_dat end end diff --git a/app/serializers/api/v2/token_serializer.rb b/app/serializers/api/v2/token_serializer.rb index 18d15d15..8f86757b 100644 --- a/app/serializers/api/v2/token_serializer.rb +++ b/app/serializers/api/v2/token_serializer.rb @@ -1,10 +1,11 @@ +# frozen_string_literal: true module Api module V2 class TokenSerializer < ApplicationSerializer attributes :id, - :token, - :description, - :created_at + :token, + :description, + :created_at end end end diff --git a/app/serializers/api/v2/topic_serializer.rb b/app/serializers/api/v2/topic_serializer.rb index 48d1d6de..8da46a2a 100644 --- a/app/serializers/api/v2/topic_serializer.rb +++ b/app/serializers/api/v2/topic_serializer.rb @@ -1,13 +1,14 @@ +# frozen_string_literal: true module Api module V2 class TopicSerializer < ApplicationSerializer attributes :id, - :name, - :desc, - :link, - :permission, - :created_at, - :updated_at + :name, + :desc, + :link, + :permission, + :created_at, + :updated_at def self.embeddable { @@ -16,7 +17,7 @@ module Api } end - self.class_eval do + class_eval do embed_dat end end diff --git a/app/serializers/api/v2/user_serializer.rb b/app/serializers/api/v2/user_serializer.rb index fdfffae0..ec58775d 100644 --- a/app/serializers/api/v2/user_serializer.rb +++ b/app/serializers/api/v2/user_serializer.rb @@ -1,19 +1,22 @@ +# frozen_string_literal: true module Api module V2 class UserSerializer < ApplicationSerializer attributes :id, - :name, - :avatar, - :is_admin, - :generation + :name, + :avatar, + :is_admin, + :generation def avatar object.image.url(:sixtyfour) end + # rubocop:disable Style/PredicateName def is_admin object.admin end + # rubocop:enable Style/PredicateName end end end diff --git a/app/serializers/api/v2/webhook_serializer.rb b/app/serializers/api/v2/webhook_serializer.rb index 59d60283..3221e450 100644 --- a/app/serializers/api/v2/webhook_serializer.rb +++ b/app/serializers/api/v2/webhook_serializer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Api module V2 class WebhookSerializer < ApplicationSerializer diff --git a/app/services/map_export_service.rb b/app/services/map_export_service.rb index c52b0802..2ded756c 100644 --- a/app/services/map_export_service.rb +++ b/app/services/map_export_service.rb @@ -1,4 +1,11 @@ -class MapExportService < Struct.new(:user, :map) +# frozen_string_literal: true +class MapExportService + attr_reader :user, :map + def initialize(user, map) + @user = user + @map = map + end + def json # marshal_dump turns OpenStruct into a Hash { diff --git a/app/services/perm.rb b/app/services/perm.rb index 99897028..57e0816f 100644 --- a/app/services/perm.rb +++ b/app/services/perm.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Perm # e.g. Perm::ISSIONS ISSIONS = [:commons, :public, :private].freeze diff --git a/app/services/webhook_service.rb b/app/services/webhook_service.rb index 965f2c91..0efe9392 100644 --- a/app/services/webhook_service.rb +++ b/app/services/webhook_service.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class WebhookService def self.publish!(webhook:, event:) return false unless webhook.event_types.include? event.kind diff --git a/app/views/layouts/_lightboxes.html.erb b/app/views/layouts/_lightboxes.html.erb index 68fa9e27..89b5a6b4 100644 --- a/app/views/layouts/_lightboxes.html.erb +++ b/app/views/layouts/_lightboxes.html.erb @@ -94,7 +94,7 @@

    As a valued beta tester, you have the ability to invite your peers, colleagues and collaborators onto the platform.

    Below is a personal invite link containing your unique access code, which can be used multiple times.

    -

    <%= determine_invite_link %> +

    <%= invite_link() %>

    diff --git a/app/views/maps/_newtopic.html.erb b/app/views/maps/_newtopic.html.erb index ba3d1797..8e10c7a7 100644 --- a/app/views/maps/_newtopic.html.erb +++ b/app/views/maps/_newtopic.html.erb @@ -1,29 +1,34 @@ +<% @metacodes = user_metacodes() %> + <%= form_for Topic.new, url: topics_url, remote: true do |form| %>
    Switch Metacodes
    +
    Pin Open
    Unpin
    +
    - <% @metacodes = user_metacodes() %> - <% set = get_metacodeset() %> <% @metacodes.each do |metacode| %> <%= metacode.name %> <% end %>
    + <%= form.text_field :name, :maxlength => 140, :placeholder => "title..." %> +
    - + + <% end %> diff --git a/config.ru b/config.ru index 8a0f42cc..ab79c07d 100644 --- a/config.ru +++ b/config.ru @@ -1,3 +1,4 @@ +# frozen_string_literal: true # This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) diff --git a/config/application.rb b/config/application.rb index b80306c5..b629682a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative 'boot' require 'csv' diff --git a/config/boot.rb b/config/boot.rb index e49b6649..f17b883c 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rubygems' require 'rails/commands/server' diff --git a/config/environment.rb b/config/environment.rb index 426333bb..12ea62f8 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Load the Rails application. require_relative 'application' diff --git a/config/environments/development.rb b/config/environments/development.rb index 407a30f3..b1654921 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Metamaps::Application.configure do # Settings specified here will take precedence over those in config/application.rb diff --git a/config/environments/production.rb b/config/environments/production.rb index 24ceed21..f9c94af6 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb diff --git a/config/environments/test.rb b/config/environments/test.rb index dac060f1..5f0b1ee2 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Metamaps::Application.configure do # Settings specified here will take precedence over those in config/application.rb diff --git a/config/initializers/access_codes.rb b/config/initializers/access_codes.rb index 4a220c97..fdf4e4b3 100644 --- a/config/initializers/access_codes.rb +++ b/config/initializers/access_codes.rb @@ -1,4 +1,7 @@ +# frozen_string_literal: true $codes = [] if ActiveRecord::Base.connection.data_source_exists? 'users' - $codes = ActiveRecord::Base.connection.execute('SELECT code FROM users').map { |user| user['code'] } + $codes = ActiveRecord::Base.connection + .execute('SELECT code FROM users') + .map { |user| user['code'] } end diff --git a/config/initializers/active_model_serializers.rb b/config/initializers/active_model_serializers.rb index aba3586b..929be340 100644 --- a/config/initializers/active_model_serializers.rb +++ b/config/initializers/active_model_serializers.rb @@ -1 +1,2 @@ +# frozen_string_literal: true ActiveModelSerializers.config.adapter = :json diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 51639b67..315ac48a 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # ApplicationController.renderer.defaults.merge!( diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 31897cf4..4edab3b6 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. @@ -9,4 +10,4 @@ Rails.application.config.assets.quiet = true # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. -Rails.application.config.assets.precompile += %w( webpacked/metamaps.bundle.js ) +Rails.application.config.assets.precompile += %w(webpacked/metamaps.bundle.js) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 59385cdf..5b98aef4 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,7 +1,10 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. -# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# You can add backtrace silencers for libraries that you're using but don't +# wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } -# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# You can also remove all the silencers if you're trying to debug a problem +# that might stem from framework code. # Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index f51a497e..74ea9274 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Specify a serializer for the signed and encrypted cookie jars. diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb index a9a8dcff..cb46d3ef 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Rails.application.config.middleware.insert_before 0, Rack::Cors do allow do origins '*' diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 8a87b3b9..6740cdc9 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| @@ -6,7 +7,8 @@ Devise.setup do |config| # confirmation, reset password and unlock tokens in the database. # Devise will use the `secret_key_base` on Rails 4+ applications as its `secret_key` # by default. You can change it below and use your own secret key. - # config.secret_key = '4d38a819bcea6314ffccb156a8e84b1b52c51ed446d11877c973791b3cd88449e9dbd7990cbc6e7f37d84702168ec36391467000c842ed5bed4f0b05df2b9507' + # config.secret_key = '4d38a819bcea6314ffccb156a8e84b1b52c51ed446d11877c973791b3cd88' + + # '449e9dbd7990cbc6e7f37d84702168ec36391467000c842ed5bed4f0b05df2b9507' # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, @@ -91,7 +93,8 @@ Devise.setup do |config| config.stretches = Rails.env.test? ? 1 : 10 # Setup a pepper to generate the encrypted password. - # config.pepper = "640ad415cb5292ac9ddbfa6ad7d9653d1537f1184e4037c2453db3eccb98e1c82facc6d3de7bf9d4c41d9967d41194c6e120f36f430e195ba840cd00e02dea59" + # config.pepper = "640ad415cb5292ac9ddbfa6ad7d9653d1537f1184e4037c2453db3eccb98e1c82" + + # "facc6d3de7bf9d4c41d9967d41194c6e120f36f430e195ba840cd00e02dea59" # ==> Configuration for :confirmable # A period that the user is allowed to access the website even without diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb index 843fe831..40de1df8 100644 --- a/config/initializers/doorkeeper.rb +++ b/config/initializers/doorkeeper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Doorkeeper.configure do # Change the ORM that doorkeeper will use (needs plugins) orm :active_record @@ -7,7 +8,8 @@ Doorkeeper.configure do current_user || redirect_to(new_user_session_url) end - # If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below. + # If you want to restrict access to the web interface for adding oauth authorized applications, + # you need to declare the block below. admin_authenticator do current_user || redirect_to(new_user_session_url) end @@ -38,7 +40,9 @@ Doorkeeper.configure do # Provide support for an owner to be assigned to each registered application (disabled by default) # Optional parameter :confirmation => true (default false) if you want to enforce ownership of # a registered application - # Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support + # Note: you must also run the rails g doorkeeper:application_owner generator to provide the + # necessary support + # # enable_application_owner :confirmation => false # Define access token scopes for your provider @@ -60,9 +64,11 @@ Doorkeeper.configure do # access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param # Change the native redirect uri for client apps - # When clients register with the following redirect uri, they won't be redirected to any server and the authorization code will be displayed within the provider - # The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL - # (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi) + # When clients register with the following redirect uri, they won't be redirected to any server + # and the authorization code will be displayed within the provider + # The value can be any string. Use nil to disable this feature. When disabled, clients + # must provide a valid URL (Similar behaviour: + # https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi) # # native_redirect_uri 'urn:ietf:wg:oauth:2.0:oob' diff --git a/config/initializers/exception_notification.rb b/config/initializers/exception_notification.rb index 5423334e..db508b3c 100644 --- a/config/initializers/exception_notification.rb +++ b/config/initializers/exception_notification.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'exception_notification/rails' ExceptionNotification.configure do |config| diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 4a994e1e..b7fe1231 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ac033bf9..aa7435fb 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/config/initializers/kaminari_config.rb b/config/initializers/kaminari_config.rb index b1d87b01..5b9883ab 100644 --- a/config/initializers/kaminari_config.rb +++ b/config/initializers/kaminari_config.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Kaminari.configure do |config| # config.default_per_page = 25 # config.max_per_page = nil diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index c7b0c86d..5e8d015a 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb index 0706cafd..d3c12d7b 100644 --- a/config/initializers/new_framework_defaults.rb +++ b/config/initializers/new_framework_defaults.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # # This file contains migration options to ease your Rails 5.0 upgrade. diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index 4a65d495..6f094b7c 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true Paperclip::Attachment.default_options[:url] = ':s3_domain_url' Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename' diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index e7f18911..4da6fb50 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index d2dc13b6..57d69156 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. Rails.application.config.session_store :cookie_store, key: '_Metamaps_session' diff --git a/config/initializers/uservoice.rb b/config/initializers/uservoice.rb index df04eeaa..9375e3a1 100644 --- a/config/initializers/uservoice.rb +++ b/config/initializers/uservoice.rb @@ -1,7 +1,11 @@ +# frozen_string_literal: true require 'uservoice-ruby' def current_sso_token - @current_sso_token ||= UserVoice.generate_sso_token('metamapscc', ENV['SSO_KEY'], { - email: current_user.email - }, 300) # Default expiry time is 5 minutes = 300 seconds + @current_sso_token ||= UserVoice.generate_sso_token( + 'metamapscc', + ENV['SSO_KEY'], + { email: current_user.email }, + 300 # Default expiry time is 5 minutes = 300 seconds + ) end diff --git a/config/initializers/version.rb b/config/initializers/version.rb index c378cb6f..ff08c330 100644 --- a/config/initializers/version.rb +++ b/config/initializers/version.rb @@ -1,2 +1,3 @@ -METAMAPS_VERSION = "2 build `git log -1 --pretty=%H`".freeze -METAMAPS_LAST_UPDATED = `git log -1 --pretty='%ad'`.split(' ').values_at(1,2,4).join(' ').freeze +# frozen_string_literal: true +METAMAPS_VERSION = '2 build `git log -1 --pretty=%H`' +METAMAPS_LAST_UPDATED = `git log -1 --pretty='%ad'`.split(' ').values_at(1, 2, 4).join(' ').freeze diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 36bb3e27..d65576db 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # # This file contains settings for ActionController::ParamsWrapper which diff --git a/config/puma.rb b/config/puma.rb index c7f311f8..da41eff9 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,19 +1,20 @@ +# frozen_string_literal: true # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum, this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i +threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }.to_i threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests, default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT') { 3000 } # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV') { 'development' } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together diff --git a/config/routes.rb b/config/routes.rb index 38fe274e..fe48b6ba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Metamaps::Application.routes.draw do use_doorkeeper root to: 'main#home', via: :get @@ -63,7 +64,11 @@ Metamaps::Application.routes.draw do get 'explore/starred', to: 'maps#starredmaps' get 'explore/mapper/:id', to: 'maps#usermaps' - devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, skip: :sessions + devise_for :users, skip: :sessions, controllers: { + registrations: 'users/registrations', + passwords: 'users/passwords', + sessions: 'devise/sessions' + } devise_scope :user do get 'login' => 'devise/sessions#new', :as => :new_user_session diff --git a/config/spring.rb b/config/spring.rb index be72de67..b0ca9589 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true %w( .ruby-version .ruby-gemset diff --git a/lib/tasks/extensions.rake b/lib/tasks/extensions.rake index bf07cec2..776c81e3 100644 --- a/lib/tasks/extensions.rake +++ b/lib/tasks/extensions.rake @@ -1,7 +1,8 @@ +# frozen_string_literal: true namespace :assets do task :js_compile do - system "npm install" - system "npm run build" + system 'npm install' + system 'npm run build' end end diff --git a/lib/tasks/heroku.rake b/lib/tasks/heroku.rake index a523a778..d7ce308f 100644 --- a/lib/tasks/heroku.rake +++ b/lib/tasks/heroku.rake @@ -1,9 +1,10 @@ +# frozen_string_literal: true require 'dotenv/tasks' namespace :heroku do desc 'Generate the Heroku gems manifest from gem dependencies' task gems: :dotenv do - RAILS_ENV = 'production'.freeze + RAILS_ENV = 'production' Rake::Task[:environment].invoke list = Rails.configuration.gems.collect do |g| _command, *options = g.send(:install_command) diff --git a/lib/tasks/perms.rake b/lib/tasks/perms.rake index 39cb9b27..bf087bd0 100644 --- a/lib/tasks/perms.rake +++ b/lib/tasks/perms.rake @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'dotenv/tasks' namespace :perms do diff --git a/script/rails b/script/rails index a861c543..6f9d9941 100644 --- a/script/rails +++ b/script/rails @@ -1,5 +1,5 @@ #!/usr/bin/env ruby.exe -# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. +# frozen_string_literal: true APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) diff --git a/spec/api/v2/mappings_api_spec.rb b/spec/api/v2/mappings_api_spec.rb index 4a1e3298..4d802865 100644 --- a/spec/api/v2/mappings_api_spec.rb +++ b/spec/api/v2/mappings_api_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe 'mappings API', type: :request do @@ -23,7 +24,9 @@ RSpec.describe 'mappings API', type: :request do end it 'POST /api/v2/mappings' do - post '/api/v2/mappings', params: { mapping: mapping.attributes, access_token: token } + post '/api/v2/mappings', params: { + mapping: mapping.attributes, access_token: token + } expect(response).to have_http_status(:success) expect(response).to match_json_schema(:mapping) @@ -31,7 +34,9 @@ RSpec.describe 'mappings API', type: :request do end it 'PATCH /api/v2/mappings/:id' do - patch "/api/v2/mappings/#{mapping.id}", params: { mapping: mapping.attributes, access_token: token } + patch "/api/v2/mappings/#{mapping.id}", params: { + mapping: mapping.attributes, access_token: token + } expect(response).to have_http_status(:success) expect(response).to match_json_schema(:mapping) diff --git a/spec/api/v2/maps_api_spec.rb b/spec/api/v2/maps_api_spec.rb index 7356ca72..77cbc24b 100644 --- a/spec/api/v2/maps_api_spec.rb +++ b/spec/api/v2/maps_api_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe 'maps API', type: :request do diff --git a/spec/api/v2/synapses_api_spec.rb b/spec/api/v2/synapses_api_spec.rb index f232b879..093bc41e 100644 --- a/spec/api/v2/synapses_api_spec.rb +++ b/spec/api/v2/synapses_api_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe 'synapses API', type: :request do @@ -23,7 +24,9 @@ RSpec.describe 'synapses API', type: :request do end it 'POST /api/v2/synapses' do - post '/api/v2/synapses', params: { synapse: synapse.attributes, access_token: token } + post '/api/v2/synapses', params: { + synapse: synapse.attributes, access_token: token + } expect(response).to have_http_status(:success) expect(response).to match_json_schema(:synapse) @@ -31,7 +34,9 @@ RSpec.describe 'synapses API', type: :request do end it 'PATCH /api/v2/synapses/:id' do - patch "/api/v2/synapses/#{synapse.id}", params: { synapse: synapse.attributes, access_token: token } + patch "/api/v2/synapses/#{synapse.id}", params: { + synapse: synapse.attributes, access_token: token + } expect(response).to have_http_status(:success) expect(response).to match_json_schema(:synapse) diff --git a/spec/api/v2/tokens_api_spec.rb b/spec/api/v2/tokens_api_spec.rb index c2e480a5..cd424ba0 100644 --- a/spec/api/v2/tokens_api_spec.rb +++ b/spec/api/v2/tokens_api_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe 'tokens API', type: :request do diff --git a/spec/api/v2/topics_api_spec.rb b/spec/api/v2/topics_api_spec.rb index 4781348a..9811071d 100644 --- a/spec/api/v2/topics_api_spec.rb +++ b/spec/api/v2/topics_api_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe 'topics API', type: :request do diff --git a/spec/controllers/mappings_controller_spec.rb b/spec/controllers/mappings_controller_spec.rb index bcd2b97f..8d1c424d 100644 --- a/spec/controllers/mappings_controller_spec.rb +++ b/spec/controllers/mappings_controller_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe MappingsController, type: :controller do diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb index a10c20d1..b877dc88 100644 --- a/spec/controllers/maps_controller_spec.rb +++ b/spec/controllers/maps_controller_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe MapsController, type: :controller do diff --git a/spec/controllers/metacodes_controller_spec.rb b/spec/controllers/metacodes_controller_spec.rb index cb4116d4..b25017b9 100644 --- a/spec/controllers/metacodes_controller_spec.rb +++ b/spec/controllers/metacodes_controller_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe MetacodesController, type: :controller do diff --git a/spec/controllers/synapses_controller_spec.rb b/spec/controllers/synapses_controller_spec.rb index 15d91250..3a5310e4 100644 --- a/spec/controllers/synapses_controller_spec.rb +++ b/spec/controllers/synapses_controller_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe SynapsesController, type: :controller do diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index 315b931f..0d7e3010 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe TopicsController, type: :controller do diff --git a/spec/factories/mappings.rb b/spec/factories/mappings.rb index bed0b754..1bcdf891 100644 --- a/spec/factories/mappings.rb +++ b/spec/factories/mappings.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true FactoryGirl.define do factory :mapping do xloc 0 diff --git a/spec/factories/maps.rb b/spec/factories/maps.rb index 14450c00..a95590e4 100644 --- a/spec/factories/maps.rb +++ b/spec/factories/maps.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true FactoryGirl.define do factory :map do sequence(:name) { |n| "Cool Map ##{n}" } diff --git a/spec/factories/metacodes.rb b/spec/factories/metacodes.rb index 543e4955..2ed71beb 100644 --- a/spec/factories/metacodes.rb +++ b/spec/factories/metacodes.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true FactoryGirl.define do factory :metacode do sequence(:name) { |n| "Cool Metacode ##{n}" } diff --git a/spec/factories/synapses.rb b/spec/factories/synapses.rb index db82fc39..6af8ca9e 100644 --- a/spec/factories/synapses.rb +++ b/spec/factories/synapses.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true FactoryGirl.define do factory :synapse do sequence(:desc) { |n| "Cool synapse ##{n}" } @@ -6,6 +7,6 @@ FactoryGirl.define do association :topic1, factory: :topic association :topic2, factory: :topic user - weight 1 # todo drop this column + weight 1 # TODO: drop this column end end diff --git a/spec/factories/tokens.rb b/spec/factories/tokens.rb index 3970d76f..6d5f110b 100644 --- a/spec/factories/tokens.rb +++ b/spec/factories/tokens.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true FactoryGirl.define do factory :token do user diff --git a/spec/factories/topics.rb b/spec/factories/topics.rb index f4c73f4c..a6048d7c 100644 --- a/spec/factories/topics.rb +++ b/spec/factories/topics.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true FactoryGirl.define do factory :topic do user diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 746f52b1..b5b20b9a 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # # This file supports three factories, because code and joinedwithcode # make things complicated! diff --git a/spec/mailers/previews/map_mailer_preview.rb b/spec/mailers/previews/map_mailer_preview.rb index 60310bf4..96d07c07 100644 --- a/spec/mailers/previews/map_mailer_preview.rb +++ b/spec/mailers/previews/map_mailer_preview.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Preview all emails at http://localhost:3000/rails/mailers/map_mailer class MapMailerPreview < ActionMailer::Preview def invite_to_edit_email diff --git a/spec/models/map_spec.rb b/spec/models/map_spec.rb index e70429be..3f3089cf 100644 --- a/spec/models/map_spec.rb +++ b/spec/models/map_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe Map, type: :model do diff --git a/spec/models/mapping_spec.rb b/spec/models/mapping_spec.rb index 54c72b88..343c19ee 100644 --- a/spec/models/mapping_spec.rb +++ b/spec/models/mapping_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe Mapping, type: :model do diff --git a/spec/models/metacode_spec.rb b/spec/models/metacode_spec.rb index c9b34527..49354898 100644 --- a/spec/models/metacode_spec.rb +++ b/spec/models/metacode_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe Metacode, type: :model do diff --git a/spec/models/synapse_spec.rb b/spec/models/synapse_spec.rb index 3bdb1ac4..c5b63a41 100644 --- a/spec/models/synapse_spec.rb +++ b/spec/models/synapse_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe Synapse, type: :model do diff --git a/spec/models/token_spec.rb b/spec/models/token_spec.rb index 50e89c02..82582218 100644 --- a/spec/models/token_spec.rb +++ b/spec/models/token_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe Token, type: :model do diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index dbaac86d..50e6d74b 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe Topic, type: :model do diff --git a/spec/policies/map_policy_spec.rb b/spec/policies/map_policy_spec.rb index 7dd33707..c08432dd 100644 --- a/spec/policies/map_policy_spec.rb +++ b/spec/policies/map_policy_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe MapPolicy, type: :policy do diff --git a/spec/policies/mapping_policy_spec.rb b/spec/policies/mapping_policy_spec.rb index 46b9c117..4010e589 100644 --- a/spec/policies/mapping_policy_spec.rb +++ b/spec/policies/mapping_policy_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe MappingPolicy, type: :policy do diff --git a/spec/policies/synapse_policy.rb b/spec/policies/synapse_policy.rb index 4c725e37..4d9d422c 100644 --- a/spec/policies/synapse_policy.rb +++ b/spec/policies/synapse_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe SynapsePolicy, type: :policy do diff --git a/spec/policies/topic_policy_spec.rb b/spec/policies/topic_policy_spec.rb index 7078496c..ef80e8dc 100644 --- a/spec/policies/topic_policy_spec.rb +++ b/spec/policies/topic_policy_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe TopicPolicy, type: :policy do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index d14d6dbe..ddf0781c 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true ENV['RAILS_ENV'] ||= 'test' require 'spec_helper' require File.expand_path('../../config/environment', __FILE__) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a2b164b2..a3477eb7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.configure do |config| config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true diff --git a/spec/support/controller_helpers.rb b/spec/support/controller_helpers.rb index 1672479f..1d24b7ca 100644 --- a/spec/support/controller_helpers.rb +++ b/spec/support/controller_helpers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # https://github.com/plataformatec/devise/wiki/How-To:-Stub-authentication-in-controller-specs require 'devise' diff --git a/spec/support/factory_girl.rb b/spec/support/factory_girl.rb index afae617a..0d10fa34 100644 --- a/spec/support/factory_girl.rb +++ b/spec/support/factory_girl.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # lets you type create(:user) instead of FactoryGirl.create(:user) RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods diff --git a/spec/support/pundit.rb b/spec/support/pundit.rb index 1fd8e296..6e8dc0ce 100644 --- a/spec/support/pundit.rb +++ b/spec/support/pundit.rb @@ -1 +1,2 @@ +# frozen_string_literal: true require 'pundit/rspec' diff --git a/spec/support/schema_matcher.rb b/spec/support/schema_matcher.rb index 207c5fa6..998771d9 100644 --- a/spec/support/schema_matcher.rb +++ b/spec/support/schema_matcher.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec::Matchers.define :match_json_schema do |schema_name| match do |response| schema_directory = Rails.root.join('doc', 'api', 'schemas').to_s diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb index 8017e897..1d48d7c8 100644 --- a/spec/support/simplecov.rb +++ b/spec/support/simplecov.rb @@ -1,2 +1,2 @@ +# frozen_string_literal: true require 'simplecov' -