some fixes from 0.48 rubocop update

This commit is contained in:
Devin Howard 2018-01-20 13:46:54 -08:00
parent 4f94123f3e
commit 139f7efe2b
50 changed files with 101 additions and 117 deletions

View file

@ -12,7 +12,7 @@ Rails:
Enabled: true Enabled: true
Metrics/LineLength: Metrics/LineLength:
Max: 100 Max: 120
Metrics/AbcSize: Metrics/AbcSize:
Max: 16 Max: 16

0
Rakefile Normal file → Executable file
View file

View file

@ -1,12 +1,12 @@
# frozen_string_literal: true # frozen_string_literal: true
class AccessController < ApplicationController 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 approve_access approve_access_post
deny_access deny_access_post request_access) deny_access deny_access_post request_access]
before_action :set_map, only: %i(access access_request before_action :set_map, only: %i[access access_request
approve_access approve_access_post approve_access approve_access_post
deny_access deny_access_post request_access) deny_access deny_access_post request_access]
after_action :verify_authorized after_action :verify_authorized
# GET maps/:id/request_access # GET maps/:id/request_access

View file

@ -4,7 +4,7 @@ module Api
module V2 module V2
class MapsController < WithUpdatesController class MapsController < WithUpdatesController
def searchable_columns def searchable_columns
%i(name desc) %i[name desc]
end end
def apply_filters(collection) def apply_filters(collection)

View file

@ -8,7 +8,7 @@ module Api
snorlax_used_rest! 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 after_action :verify_authorized
def index def index

View file

@ -4,7 +4,7 @@ module Api
module V2 module V2
class TopicsController < WithUpdatesController class TopicsController < WithUpdatesController
def searchable_columns def searchable_columns
%i(name desc link) %i[name desc link]
end end
end end
end end

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class ExploreController < ApplicationController 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 before_action :authorize_explore
after_action :verify_authorized after_action :verify_authorized
after_action :verify_policy_scoped after_action :verify_policy_scoped

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class MappingsController < ApplicationController 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_authorized, except: :index
after_action :verify_policy_scoped, only: :index after_action :verify_policy_scoped, only: :index

View file

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
class MapsController < ApplicationController class MapsController < ApplicationController
before_action :require_user, only: %i(create update destroy events follow unfollow) 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 :set_map, only: %i[show conversation update destroy contains events export follow unfollow unfollow_from_email]
after_action :verify_authorized after_action :verify_authorized
# GET maps/:id # GET maps/:id

View file

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
class MetacodesController < ApplicationController class MetacodesController < ApplicationController
before_action :require_admin, except: %i(index show) before_action :require_admin, except: %i[index show]
before_action :set_metacode, only: %i(edit update) before_action :set_metacode, only: %i[edit update]
# GET /metacodes # GET /metacodes
# GET /metacodes.json # GET /metacodes.json

View file

@ -1,9 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
class NotificationsController < ApplicationController class NotificationsController < ApplicationController
before_action :set_receipts, only: %i(index 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_notification, only: %i[show mark_read mark_unread]
before_action :set_receipt, only: %i(show mark_read mark_unread) before_action :set_receipt, only: %i[show mark_read mark_unread]
def index def index
@notifications = current_user.mailbox.notifications.page(params[:page]).per(25) @notifications = current_user.mailbox.notifications.page(params[:page]).per(25)

View file

@ -8,7 +8,7 @@ class SearchController < ApplicationController
before_action :authorize_search before_action :authorize_search
after_action :verify_authorized 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 # get /search/topics?term=SOMETERM
def topics def topics

View file

@ -3,7 +3,7 @@
class SynapsesController < ApplicationController class SynapsesController < ApplicationController
include TopicsHelper 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_authorized, except: :index
after_action :verify_policy_scoped, only: :index after_action :verify_policy_scoped, only: :index

View file

@ -3,10 +3,10 @@
class TopicsController < ApplicationController class TopicsController < ApplicationController
include TopicsHelper include TopicsHelper
before_action :require_user, only: %i(create update destroy follow unfollow) before_action :require_user, only: %i[create update destroy follow unfollow]
before_action :set_topic, only: %i(show update relative_numbers before_action :set_topic, only: %i[show update relative_numbers
relatives network destroy relatives network destroy
follow unfollow unfollow_from_email) follow unfollow unfollow_from_email]
after_action :verify_authorized, except: :autocomplete_topic after_action :verify_authorized, except: :autocomplete_topic
respond_to :html, :js, :json respond_to :html, :js, :json

View file

@ -30,7 +30,7 @@ module Users
end end
def configure_sign_up_params 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 end
def configure_account_update_params def configure_account_update_params

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class UsersController < ApplicationController 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 respond_to :html, :json

View file

@ -21,9 +21,7 @@ module MapsHelper
end end
def first_contributor_image(map) def first_contributor_image(map)
if map.contributors.count.positive? return map.contributors[0].image.url(:thirtytwo) if map.contributors.count.positive?
return map.contributors[0].image.url(:thirtytwo)
end
'https://s3.amazonaws.com/metamaps-assets/site/user.png' 'https://s3.amazonaws.com/metamaps-assets/site/user.png'
end end

View file

@ -13,7 +13,7 @@ module SynapsesHelper
synapses.map do |s| synapses.map do |s|
{ {
id: s.id, id: s.id,
label: s.desc.blank? ? '(no description)' : s.desc, label: s.desc.presence || '(no description)',
value: s.desc, value: s.desc,
permission: s.permission, permission: s.permission,
mapCount: s.maps.count, mapCount: s.maps.count,

View file

@ -1,11 +1,11 @@
# frozen_string_literal: true # frozen_string_literal: true
class Event < ApplicationRecord 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 conversation_started_on_map
topic_added_to_map topic_moved_on_map topic_removed_from_map topic_added_to_map topic_moved_on_map topic_removed_from_map
synapse_added_to_map synapse_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 :eventable, polymorphic: true
belongs_to :map belongs_to :map

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class FollowReason < ApplicationRecord 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 belongs_to :follow

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class Map < ApplicationRecord class Map < ApplicationRecord
ATTRS_TO_WATCH = %w(name desc permission).freeze ATTRS_TO_WATCH = %w[name desc permission].freeze
belongs_to :user belongs_to :user
belongs_to :source, class_name: :Map belongs_to :source, class_name: :Map
@ -90,10 +90,10 @@ class Map < ApplicationRecord
def as_json(_options = {}) def as_json(_options = {})
json = super( json = super(
methods: %i(user_name user_image star_count topic_count synapse_count methods: %i[user_name user_image star_count topic_count synapse_count
contributor_count collaborator_ids screenshot_url), contributor_count collaborator_ids screenshot_url],
except: %i(screenshot_content_type screenshot_file_size screenshot_file_name except: %i[screenshot_content_type screenshot_file_size screenshot_file_name
screenshot_updated_at) screenshot_updated_at]
) )
json[:created_at_clean] = created_at_str json[:created_at_clean] = created_at_str
json[:updated_at_clean] = updated_at_str json[:updated_at_clean] = updated_at_str

View file

@ -25,7 +25,7 @@ class Mapping < ApplicationRecord
end end
def as_json(_options = {}) def as_json(_options = {})
super(methods: %i(user_name user_image)) super(methods: %i[user_name user_image])
end end
def after_created def after_created

View file

@ -14,7 +14,7 @@ class Message < ApplicationRecord
end end
def as_json(_options = {}) def as_json(_options = {})
json = super(methods: %i(user_name user_image)) json = super(methods: %i[user_name user_image])
json json
end end

View file

@ -21,11 +21,7 @@ class Metacode < ApplicationRecord
end end
def icon(*args) def icon(*args)
if manual_icon.present? manual_icon.presence || aws_icon(*args)
manual_icon
else
aws_icon(*args)
end
end end
def as_json(options = {}) def as_json(options = {})
@ -57,9 +53,7 @@ class Metacode < ApplicationRecord
def manual_icon_https def manual_icon_https
if manual_icon.present? if manual_icon.present?
unless manual_icon.starts_with? 'https' errors.add(:base, 'Manual icon must begin with https') unless manual_icon.starts_with? 'https'
errors.add(:base, 'Manual icon must begin with https')
end
end end
end end
end end

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class PermittedParams < Struct.new(:params) 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 define_method(kind) do
permitted_attributes = send("#{kind}_attributes") permitted_attributes = send("#{kind}_attributes")
params.require(kind).permit(*permitted_attributes) params.require(kind).permit(*permitted_attributes)
@ -16,18 +16,18 @@ class PermittedParams < Struct.new(:params)
end end
def map_attributes def map_attributes
%i(name desc permission arranged) %i[name desc permission arranged]
end end
def synapse_attributes def synapse_attributes
%i(desc category weight permission topic1_id topic2_id) %i[desc category weight permission topic1_id topic2_id]
end end
def topic_attributes def topic_attributes
%i(name desc link permission metacode_id) %i[name desc link permission metacode_id]
end end
def mapping_attributes def mapping_attributes
%i(xloc yloc map_id mappable_type mappable_id) %i[xloc yloc map_id mappable_type mappable_id]
end end
end end

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class Synapse < ApplicationRecord 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 :user
belongs_to :defer_to_map, class_name: 'Map', foreign_key: 'defer_to_map_id' belongs_to :defer_to_map, class_name: 'Map', foreign_key: 'defer_to_map_id'
@ -55,7 +55,7 @@ class Synapse < ApplicationRecord
end end
def as_json(_options = {}) def as_json(_options = {})
super(methods: %i(user_name user_image collaborator_ids)) super(methods: %i[user_name user_image collaborator_ids])
end end
def as_rdf def as_rdf

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class Topic < ApplicationRecord 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 TopicsHelper
include Attachable include Attachable
@ -70,7 +70,7 @@ class Topic < ApplicationRecord
end end
def as_json(options = {}) 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]), .merge(inmaps: inmaps(options[:user]), inmapsLinks: inmapsLinks(options[:user]),
map_count: map_count(options[:user]), synapse_count: synapse_count(options[:user])) map_count: map_count(options[:user]), synapse_count: synapse_count(options[:user]))
end end

View file

@ -52,24 +52,24 @@ class User < ApplicationRecord
validates_attachment_content_type :image, content_type: %r{\Aimage/.*\Z} validates_attachment_content_type :image, content_type: %r{\Aimage/.*\Z}
# override default as_json # override default as_json
def as_json(_options = {}) def as_json(options = {})
json = { id: id, json = { id: id,
name: name, name: name,
image: image.url(:sixtyfour), image: image.url(:sixtyfour),
admin: admin } admin: admin }
if _options[:follows] if options[:follows]
json['follows'] = { json['follows'] = {
topics: following.active.where(followed_type: 'Topic').to_a.map(&:followed_id), topics: following.active.where(followed_type: 'Topic').to_a.map(&:followed_id),
maps: following.active.where(followed_type: 'Map').to_a.map(&:followed_id) maps: following.active.where(followed_type: 'Map').to_a.map(&:followed_id)
} }
end end
if _options[:follow_settings] if options[:follow_settings]
json['follow_topic_on_created'] = settings.follow_topic_on_created == '1' json['follow_topic_on_created'] = settings.follow_topic_on_created == '1'
json['follow_topic_on_contributed'] = settings.follow_topic_on_contributed == '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_created'] = settings.follow_map_on_created == '1'
json['follow_map_on_contributed'] = settings.follow_map_on_contributed == '1' json['follow_map_on_contributed'] = settings.follow_map_on_contributed == '1'
end end
json['email'] = email if _options[:email] json['email'] = email if options[:email]
json json
end end
@ -133,7 +133,7 @@ class User < ApplicationRecord
def has_map_open(map) def has_map_open(map)
latestEvent = Event.where(map: map, user: self) 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) .order(:created_at)
.last .last
latestEvent && latestEvent.kind == 'user_present_on_map' latestEvent && latestEvent.kind == 'user_present_on_map'

View file

@ -6,7 +6,7 @@ class UserPreference
def initialize def initialize
array = [] array = []
%w(Action Aim Idea Question Note Wildcard Subject).each do |m| %w[Action Aim Idea Question Note Wildcard Subject].each do |m|
begin begin
metacode = Metacode.find_by(name: m) metacode = Metacode.find_by(name: m)
array.push(metacode.id.to_s) if metacode array.push(metacode.id.to_s) if metacode

View file

@ -5,7 +5,7 @@ class Webhook < ApplicationRecord
validates :uri, presence: true validates :uri, presence: true
validates :hookable, presence: true validates :hookable, presence: true
validates :kind, inclusion: { in: %w(slack) } validates :kind, inclusion: { in: %w[slack] }
validates :event_types, length: { minimum: 1 } validates :event_types, length: { minimum: 1 }
def headers def headers

View file

@ -3,7 +3,7 @@
class MapPolicy < ApplicationPolicy class MapPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
visible = %w(public commons) visible = %w[public commons]
return scope.where(permission: visible) unless user return scope.where(permission: visible) unless user
scope.where(permission: visible) scope.where(permission: visible)
@ -17,13 +17,13 @@ class MapPolicy < ApplicationPolicy
end end
def show? def show?
record.permission.in?(%w(commons public)) || record.permission.in?(%w[commons public]) ||
record.collaborators.include?(user) || record.collaborators.include?(user) ||
record.user == user record.user == user
end end
def conversation? 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 end
def create? def create?

View file

@ -7,7 +7,7 @@ class MappingPolicy < ApplicationPolicy
# it would be nice if we could also base this on the mappable, but that # 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 # 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 # a private topic, since you can't see the private topic anyways
visible = %w(public commons) visible = %w[public commons]
permission = 'maps.permission IN (?)' permission = 'maps.permission IN (?)'
return scope.joins(:map).where(permission, visible) unless user return scope.joins(:map).where(permission, visible) unless user

View file

@ -3,7 +3,7 @@
class MessagePolicy < ApplicationPolicy class MessagePolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
visible = %w(public commons) visible = %w[public commons]
permission = 'maps.permission IN (?)' permission = 'maps.permission IN (?)'
return scope.joins(:map).where(permission, visible) unless user return scope.joins(:map).where(permission, visible) unless user

View file

@ -3,9 +3,9 @@
class SynapsePolicy < ApplicationPolicy class SynapsePolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve 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(defer_to_map_id: user.all_accessible_maps.map(&:id)))
.or(scope.where(user_id: user.id)) .or(scope.where(user_id: user.id))
end end

View file

@ -3,9 +3,9 @@
class TopicPolicy < ApplicationPolicy class TopicPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve 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(defer_to_map_id: user.all_accessible_maps.map(&:id)))
.or(scope.where(user_id: user.id)) .or(scope.where(user_id: user.id))
end end
@ -23,7 +23,7 @@ class TopicPolicy < ApplicationPolicy
if record.defer_to_map.present? if record.defer_to_map.present?
map_policy.show? map_policy.show?
else else
record.permission.in?(%w(commons public)) || record.user == user record.permission.in?(%w[commons public]) || record.user == user
end end
end end

View file

@ -8,9 +8,7 @@ class FollowService
return if (reason == 'created' || reason == 'contributed') && !should_auto_follow(entity, user, reason) return if (reason == 'created' || reason == 'contributed') && !should_auto_follow(entity, user, reason)
follow = Follow.where(followed: entity, user: user).first_or_create follow = Follow.where(followed: entity, user: user).first_or_create
unless follow.update(muted: false) raise follow.errors.full_messages.join("\n") unless follow.update(muted: false)
raise follow.errors.full_messages.join("\n")
end
if FollowReason::REASONS.include?(reason) && !follow.follow_reason.read_attribute(reason) if FollowReason::REASONS.include?(reason) && !follow.follow_reason.read_attribute(reason)
follow.follow_reason.update_attribute(reason, true) follow.follow_reason.update_attribute(reason, true)
end end
@ -19,9 +17,7 @@ class FollowService
def unfollow(entity, user) def unfollow(entity, user)
follow = Follow.where(followed: entity, user: user).first follow = Follow.where(followed: entity, user: user).first
if follow if follow
unless follow.update(muted: true) raise follow.errors.full_messages.join("\n") unless follow.update(muted: true)
raise follow.errors.full_messages.join("\n")
end
end end
end end
@ -38,7 +34,7 @@ class FollowService
def should_auto_follow(entity, user, reason) def should_auto_follow(entity, user, reason)
follow = Follow.where(followed: entity, user: user).first follow = Follow.where(followed: entity, user: user).first
return false if follow && follow.muted return false if follow&.muted
if entity.class == Topic if entity.class == Topic
if reason == 'created' if reason == 'created'
return user.settings.follow_topic_on_created == '1' return user.settings.follow_topic_on_created == '1'

View file

@ -5,7 +5,7 @@ class MapActivityService
'Activity on map ' + map.name 'Activity on map ' + map.name
end end
def self.summarize_data(map, user, until_moment = DateTime.now) def self.summarize_data(map, user, until_moment = DateTime.current)
results = { results = {
stats: {} stats: {}
} }
@ -18,15 +18,13 @@ class MapActivityService
message_count = Message.where(resource: map) message_count = Message.where(resource: map)
.where('created_at > ? AND created_at < ?', since, until_moment) .where('created_at > ? AND created_at < ?', since, until_moment)
.where.not(user: user).count .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) moved_count = Event.where(kind: 'topic_moved_on_map', map: map)
.where('created_at > ? AND created_at < ?', since, until_moment) .where('created_at > ? AND created_at < ?', since, until_moment)
.where(eventable_id: scoped_topic_ids) .where(eventable_id: scoped_topic_ids)
.where.not(user: user).group(:eventable_id).count .where.not(user: user).group(:eventable_id).count
unless moved_count.keys.empty? results[:stats][:topics_moved] = moved_count.keys.length unless moved_count.keys.empty?
results[:stats][:topics_moved] = moved_count.keys.length
end
topics_added_events = Event.where(kind: 'topic_added_to_map', map: map) topics_added_events = Event.where(kind: 'topic_added_to_map', map: map)
.where('created_at > ? AND created_at < ?', since, until_moment) .where('created_at > ? AND created_at < ?', since, until_moment)

View file

@ -47,16 +47,16 @@ class MapExportService
private private
def topic_headings def topic_headings
%i(id name metacode x y description link user permission) %i[id name metacode x y description link user permission]
end end
def synapse_headings def synapse_headings
%i(topic1 topic2 category description user permission) %i[topic1 topic2 category description user permission]
end end
def exportable_topics def exportable_topics
visible_topics ||= Pundit.policy_scope!(user, map.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) .where(mappable: visible_topics, map: map)
topic_mappings.map do |mapping| topic_mappings.map do |mapping|
topic = mapping.mappable topic = mapping.mappable

View file

@ -2,7 +2,7 @@
class Perm class Perm
# e.g. Perm::ISSIONS # e.g. Perm::ISSIONS
ISSIONS = %i(commons public private).freeze ISSIONS = %i[commons public private].freeze
class << self class << self
def short(permission) def short(permission)

View file

@ -25,7 +25,7 @@ Rails.application.configure do
# Print deprecation notices to the Rails logger # Print deprecation notices to the Rails logger
config.active_support.deprecation = :log 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 # Expands the lines which load the assets
config.assets.debug = false config.assets.debug = false

View file

@ -10,5 +10,5 @@ Rails.application.configure do
# Precompile additional assets. # Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # 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 end

View file

@ -5,6 +5,6 @@ Rails.application.config.middleware.insert_before 0, Rack::Cors do
origins '*' origins '*'
resource '/api/*', resource '/api/*',
headers: :any, headers: :any,
methods: %i(get post put delete options head) methods: %i[get post put delete options head]
end end
end end

View file

@ -11,4 +11,4 @@ Delayed::Worker.class_eval do
prepend ExceptionNotifierInDelayedJob prepend ExceptionNotifierInDelayedJob
end 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'))

View file

@ -51,11 +51,11 @@ ExceptionNotification.configure do |config|
# Ignore additional exception types. # Ignore additional exception types.
# ActiveRecord::RecordNotFound, AbstractController::ActionNotFound and # ActiveRecord::RecordNotFound, AbstractController::ActionNotFound and
# ActionController::RoutingError are already added. # ActionController::RoutingError are already added.
config.ignored_exceptions += %w( config.ignored_exceptions += %w[
ActionView::TemplateError CustomError UnauthorizedException ActionView::TemplateError CustomError UnauthorizedException
InvalidArgumentException InvalidEntityException InvalidRequestException InvalidArgumentException InvalidEntityException InvalidRequestException
NotFoundException ValidationException NotFoundException ValidationException
) ]
# Adds a condition to decide when an exception must be ignored or not. # 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. # The ignore_if method can be invoked multiple times to add extra conditions.

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
def is_tester(user) 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 end

View file

@ -17,7 +17,7 @@ Metamaps::Application.routes.draw do
end end
get :explore, to: redirect('/') get :explore, to: redirect('/')
resources :maps, except: %i(index edit) do resources :maps, except: %i[index edit] do
member do member do
get :conversation get :conversation
get :export get :export
@ -55,10 +55,10 @@ Metamaps::Application.routes.draw do
end end
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 :messages, only: %i[show create update destroy]
resources :notifications, only: %i(index show) do resources :notifications, only: %i[index show] do
collection do collection do
get :unsubscribe get :unsubscribe
end end
@ -80,9 +80,9 @@ Metamaps::Application.routes.draw do
get :synapses get :synapses
end 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 member do
get :network get :network
get :relative_numbers get :relative_numbers
@ -111,7 +111,7 @@ Metamaps::Application.routes.draw do
get 'join' => 'users/registrations#new', :as => :sign_up get 'join' => 'users/registrations#new', :as => :sign_up
end end
resources :users, except: %i(index destroy) do resources :users, except: %i[index destroy] do
member do member do
get :details get :details
end end
@ -121,16 +121,16 @@ Metamaps::Application.routes.draw do
namespace :api, path: '/api', default: { format: :json } do namespace :api, path: '/api', default: { format: :json } do
namespace :v2, path: '/v2' do namespace :v2, path: '/v2' do
resources :metacodes, only: %i(index show) resources :metacodes, only: %i[index show]
resources :mappings, only: %i(index create show update destroy) resources :mappings, only: %i[index create show update destroy]
resources :maps, only: %i(index create show update destroy) do resources :maps, only: %i[index create show update destroy] do
post :stars, to: 'stars#create', on: :member post :stars, to: 'stars#create', on: :member
delete :stars, to: 'stars#destroy', on: :member delete :stars, to: 'stars#destroy', on: :member
end end
resources :synapses, only: %i(index create show update destroy) resources :synapses, only: %i[index create show update destroy]
resources :tokens, only: %i(index create destroy) resources :tokens, only: %i[index create destroy]
resources :topics, only: %i(index create show update destroy) resources :topics, only: %i[index create show update destroy]
resources :users, only: %i(index show) do resources :users, only: %i[index show] do
get :current, on: :collection get :current, on: :collection
end end
match '*path', to: 'restful#catch_404', via: :all match '*path', to: 'restful#catch_404', via: :all

View file

@ -1,9 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
%w( %w[
.ruby-version .ruby-version
.ruby-gemset .ruby-gemset
.rbenv-vars .rbenv-vars
tmp/restart.txt tmp/restart.txt
tmp/caching-dev.txt tmp/caching-dev.txt
).each { |path| Spring.watch(path) } ].each { |path| Spring.watch(path) }

0
script/rails Normal file → Executable file
View file

View file

@ -6,9 +6,7 @@ require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails' require 'rspec/rails'
# Prevent database truncation if the environment is production # Prevent database truncation if the environment is production
if Rails.env.production? abort('The Rails environment is running in production mode!') if Rails.env.production?
abort('The Rails environment is running in production mode!')
end
# require all support files # require all support files
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
@ -17,7 +15,7 @@ ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config| RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures # 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 config.use_transactional_fixtures = true

View file

@ -15,7 +15,7 @@ RSpec::Matchers.define :match_json_schema do |schema_name|
end end
def get_json_example(resource) 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)) OpenStruct.new(body: File.read(filepath))
end end
@ -25,7 +25,7 @@ def update_file_refs(schema)
schema[key] = if value.is_a? Hash schema[key] = if value.is_a? Hash
update_file_refs(value) update_file_refs(value)
elsif key == '$ref' elsif key == '$ref'
"#{Rails.root}/doc/api/schemas/#{value}" Rails.root.join('doc', 'api', 'schemas', value.to_s)
else else
value value
end end