From df25f84c0f7b609aa81d5f625806cc890cfcfa85 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sat, 20 Jan 2018 14:47:16 -0800 Subject: [PATCH] whittle down todo file --- .rubocop.yml | 6 ++--- .rubocop_todo.yml | 33 -------------------------- app/helpers/topics_helper.rb | 2 +- app/models/event.rb | 2 +- app/models/follow.rb | 4 +--- app/models/mapping.rb | 4 ++-- app/models/metacode.rb | 16 +++++-------- app/models/synapse.rb | 4 ++-- app/models/topic.rb | 8 +++---- app/policies/map_policy.rb | 2 +- app/views/metacode_sets/_form.html.erb | 8 +++---- app/views/metacode_sets/edit.html.erb | 2 +- app/views/metacode_sets/new.html.erb | 2 +- 13 files changed, 27 insertions(+), 66 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2670eaca..16f9992b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,9 +13,9 @@ AllCops: Rails: Enabled: true -#Metrics/LineLength: -# Max: 120 -# +Metrics/LineLength: + Max: 120 + #Metrics/AbcSize: # Max: 16 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index dfb904bf..bf1d5c1f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,12 +1,3 @@ -# Offense count: 6 -Lint/AmbiguousBlockAssociation: - Exclude: - - 'app/models/event.rb' - - 'app/models/follow.rb' - - 'app/models/mapping.rb' - - 'app/models/synapse.rb' - - 'app/models/topic.rb' - # Offense count: 50 Metrics/AbcSize: Max: 128 @@ -25,12 +16,6 @@ Metrics/ClassLength: Metrics/CyclomaticComplexity: Max: 15 -# Offense count: 2 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Metrics/LineLength: - Max: 146 - # Offense count: 45 # Configuration parameters: CountComments. Metrics/MethodLength: @@ -75,24 +60,6 @@ Style/GlobalVars: - 'app/models/user.rb' - 'config/initializers/access_codes.rb' -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: line_count_dependent, lambda, literal -Style/Lambda: - Exclude: - - 'app/models/follow.rb' - - 'app/models/synapse.rb' - - 'app/models/topic.rb' - -# Offense count: 3 -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: snake_case, camelCase -Style/MethodName: - Exclude: - - 'app/models/metacode.rb' - - 'app/models/topic.rb' - # Offense count: 6 # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. # NamePrefix: is_, has_, have_ diff --git a/app/helpers/topics_helper.rb b/app/helpers/topics_helper.rb index 2cc5e85d..9a605835 100644 --- a/app/helpers/topics_helper.rb +++ b/app/helpers/topics_helper.rb @@ -17,7 +17,7 @@ module TopicsHelper rtype: is_map ? 'map' : 'topic', inmaps: is_map ? [] : t.inmaps(current_user), - inmapsLinks: is_map ? [] : t.inmapsLinks(current_user), + inmapsLinks: is_map ? [] : t.inmaps_links(current_user), type: is_map ? metamap_metacode.name : t.metacode.name, typeImageURL: is_map ? metamap_metacode.icon : t.metacode.icon, mapCount: is_map ? 0 : t.maps.count, diff --git a/app/models/event.rb b/app/models/event.rb index e4da5c82..21e4640d 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -11,7 +11,7 @@ class Event < ApplicationRecord belongs_to :map belongs_to :user - scope :chronologically, -> { order('created_at asc') } + scope :chronologically, (-> { order('created_at asc') }) after_create :notify_webhooks!, if: :map diff --git a/app/models/follow.rb b/app/models/follow.rb index 01226a8f..dc61ae8c 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -11,9 +11,7 @@ class Follow < ApplicationRecord after_create :add_subsetting - scope :active, -> { - where(muted: false) - } + scope :active, (-> { where(muted: false) }) private diff --git a/app/models/mapping.rb b/app/models/mapping.rb index 627d93ae..5d04fe64 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true class Mapping < ApplicationRecord - scope :topicmapping, -> { where(mappable_type: :Topic) } - scope :synapsemapping, -> { where(mappable_type: :Synapse) } + scope :topicmapping, (-> { where(mappable_type: :Topic) }) + scope :synapsemapping, (-> { where(mappable_type: :Synapse) }) belongs_to :mappable, polymorphic: true belongs_to :map, class_name: 'Map', foreign_key: 'map_id', touch: true diff --git a/app/models/metacode.rb b/app/models/metacode.rb index 6a2697bd..445967c1 100644 --- a/app/models/metacode.rb +++ b/app/models/metacode.rb @@ -6,9 +6,7 @@ class Metacode < ApplicationRecord has_many :topics # This method associates the attribute ":aws_icon" with a file attachment - has_attached_file :aws_icon, styles: { - ninetysix: ['96x96#', :png] - }, + has_attached_file :aws_icon, styles: { ninetysix: ['96x96#', :png] }, default_url: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png' # Validate the attached icon is image/jpg, image/png, etc @@ -31,15 +29,13 @@ class Metacode < ApplicationRecord def as_json(options = {}) default = super(options) default[:icon] = icon - default.except('aws_icon_file_name', 'aws_icon_content_type', 'aws_icon_file_size', 'aws_icon_updated_at', 'manual_icon') + default.except( + 'aws_icon_file_name', 'aws_icon_content_type', 'aws_icon_file_size', 'aws_icon_updated_at', + 'manual_icon' + ) end - def hasSelected(user) - return true if user.settings.metacodes.include? id.to_s - false - end - - def inMetacodeSet(metacode_set) + def in_metacode_set(metacode_set) return true if metacode_sets.include? metacode_set false end diff --git a/app/models/synapse.rb b/app/models/synapse.rb index da107aee..c016a58c 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -22,9 +22,9 @@ class Synapse < ApplicationRecord validates :category, inclusion: { in: ['from-to', 'both'], allow_nil: true } - scope :for_topic, ->(topic_id = nil) { + scope :for_topic, (lambda do |topic_id = nil| where(topic1_id: topic_id).or(where(topic2_id: topic_id)) - } + end) before_create :set_perm_by_defer after_create :after_created_async diff --git a/app/models/topic.rb b/app/models/topic.rb index 582a7472..5c7e3127 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -39,13 +39,13 @@ class Topic < ApplicationRecord topics1.or(topics2) end - scope :relatives, ->(topic_id = nil, user = nil) { + scope :relatives, (lambda do |topic_id = nil, user = nil| # should only see topics through *visible* synapses # e.g. Topic A (commons) -> synapse (private) -> Topic B (commons) must be filtered out topic_ids = Pundit.policy_scope(user, Synapse.where(topic1_id: topic_id)).pluck(:topic2_id) topic_ids += Pundit.policy_scope(user, Synapse.where(topic2_id: topic_id)).pluck(:topic1_id) where(id: topic_ids.uniq) - } + end) delegate :name, to: :user, prefix: true @@ -65,13 +65,13 @@ class Topic < ApplicationRecord Pundit.policy_scope(user, maps).map(&:name) end - def inmapsLinks(user) + def inmaps_links(user) Pundit.policy_scope(user, maps).map(&:id) end def as_json(options = {}) super(methods: %i[user_name user_image collaborator_ids]) - .merge(inmaps: inmaps(options[:user]), inmapsLinks: inmapsLinks(options[:user]), + .merge(inmaps: inmaps(options[:user]), inmapsLinks: inmaps_links(options[:user]), map_count: map_count(options[:user]), synapse_count: synapse_count(options[:user])) end diff --git a/app/policies/map_policy.rb b/app/policies/map_policy.rb index 308d1ce9..07829b9f 100644 --- a/app/policies/map_policy.rb +++ b/app/policies/map_policy.rb @@ -23,7 +23,7 @@ class MapPolicy < ApplicationPolicy end def conversation? - show? && %w[connorturland@gmail.com devin@callysto.com chessscholar@gmail.com solaureum@gmail.com ishanshapiro@gmail.com].include?(user.email) + show? && is_tester(user) end def create? diff --git a/app/views/metacode_sets/_form.html.erb b/app/views/metacode_sets/_form.html.erb index b3d3f018..f209eece 100644 --- a/app/views/metacode_sets/_form.html.erb +++ b/app/views/metacode_sets/_form.html.erb @@ -35,7 +35,7 @@ <% $i = 0 %> <% @m = Metacode.order("name").all %> <% while $i < (Metacode.all.length / 4) do %> -
  • class="toggledOff"<% end %> +
  • class="toggledOff"<% end %> onclick="Metamaps.Admin.liClickHandler.call(this);"> <%= @m[$i].name %>

    <%= @m[$i].name.downcase %>

    @@ -46,7 +46,7 @@