Rubocop: activate Layout/ClassStructure (#9304)
This commit is contained in:
parent
3ab9b91575
commit
1166370818
17 changed files with 84 additions and 83 deletions
|
|
@ -29,10 +29,10 @@ Bundler/OrderedGems:
|
|||
|
||||
#################### Layout ###########################
|
||||
|
||||
# Layout/ClassStructure:
|
||||
# Description: 'Enforces a configured order of definitions within a class body.'
|
||||
# StyleGuide: '#consistent-classes'
|
||||
# Enabled: false
|
||||
Layout/ClassStructure:
|
||||
Description: 'Enforces a configured order of definitions within a class body.'
|
||||
StyleGuide: '#consistent-classes'
|
||||
Enabled: true
|
||||
|
||||
Layout/DotPosition:
|
||||
Description: 'Checks the position of the dot in multi-line method calls.'
|
||||
|
|
|
|||
|
|
@ -11,6 +11,28 @@ module Api
|
|||
|
||||
skip_before_action :verify_authenticity_token, only: %i[create update]
|
||||
|
||||
INDEX_ATTRIBUTES_FOR_SERIALIZATION = %i[
|
||||
id user_id organization_id collection_id
|
||||
title description main_image published_at crossposted_at social_image
|
||||
cached_tag_list slug path canonical_url comments_count
|
||||
public_reactions_count created_at edited_at last_comment_at published
|
||||
updated_at video_thumbnail_url
|
||||
].freeze
|
||||
private_constant :INDEX_ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
SHOW_ATTRIBUTES_FOR_SERIALIZATION = [
|
||||
*INDEX_ATTRIBUTES_FOR_SERIALIZATION, :body_markdown, :processed_html
|
||||
].freeze
|
||||
private_constant :SHOW_ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
ME_ATTRIBUTES_FOR_SERIALIZATION = %i[
|
||||
id user_id organization_id
|
||||
title description main_image published published_at cached_tag_list
|
||||
slug path canonical_url comments_count public_reactions_count
|
||||
page_views_count crossposted_at body_markdown updated_at
|
||||
].freeze
|
||||
private_constant :ME_ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
def index
|
||||
@articles = ArticleApiIndexService.new(params).get
|
||||
@articles = @articles.select(INDEX_ATTRIBUTES_FOR_SERIALIZATION).decorate
|
||||
|
|
@ -82,28 +104,6 @@ module Api
|
|||
decorate
|
||||
end
|
||||
|
||||
INDEX_ATTRIBUTES_FOR_SERIALIZATION = %i[
|
||||
id user_id organization_id collection_id
|
||||
title description main_image published_at crossposted_at social_image
|
||||
cached_tag_list slug path canonical_url comments_count
|
||||
public_reactions_count created_at edited_at last_comment_at published
|
||||
updated_at video_thumbnail_url
|
||||
].freeze
|
||||
private_constant :INDEX_ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
SHOW_ATTRIBUTES_FOR_SERIALIZATION = [
|
||||
*INDEX_ATTRIBUTES_FOR_SERIALIZATION, :body_markdown, :processed_html
|
||||
].freeze
|
||||
private_constant :SHOW_ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
ME_ATTRIBUTES_FOR_SERIALIZATION = %i[
|
||||
id user_id organization_id
|
||||
title description main_image published published_at cached_tag_list
|
||||
slug path canonical_url comments_count public_reactions_count
|
||||
page_views_count crossposted_at body_markdown updated_at
|
||||
].freeze
|
||||
private_constant :ME_ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
private
|
||||
|
||||
def article_params
|
||||
|
|
|
|||
|
|
@ -3,6 +3,11 @@ module Api
|
|||
class CommentsController < ApiController
|
||||
before_action :set_cache_control_headers, only: %i[index show]
|
||||
|
||||
ATTRIBUTES_FOR_SERIALIZATION = %i[
|
||||
id processed_html user_id ancestry deleted hidden_by_commentable_user
|
||||
].freeze
|
||||
private_constant :ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
def index
|
||||
article = Article.find(params[:a_id])
|
||||
|
||||
|
|
@ -27,11 +32,6 @@ module Api
|
|||
set_surrogate_key_header Comment.table_key, edge_cache_keys(tree_with_root_comment)
|
||||
end
|
||||
|
||||
ATTRIBUTES_FOR_SERIALIZATION = %i[
|
||||
id processed_html user_id ancestry deleted hidden_by_commentable_user
|
||||
].freeze
|
||||
private_constant :ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
private
|
||||
|
||||
# ancestry wraps a single or multiple trees of comments into a single hash,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,11 @@ module Api
|
|||
before_action :authenticate_with_api_key_or_current_user!
|
||||
before_action -> { limit_per_page(default: 80, max: 1000) }
|
||||
|
||||
USERS_ATTRIBUTES_FOR_SERIALIZATION = %i[
|
||||
id follower_id follower_type
|
||||
].freeze
|
||||
private_constant :USERS_ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
def users
|
||||
@follows = Follow.followable_user(@user.id).
|
||||
includes(:follower).
|
||||
|
|
@ -13,11 +18,6 @@ module Api
|
|||
per(@follows_limit)
|
||||
end
|
||||
|
||||
USERS_ATTRIBUTES_FOR_SERIALIZATION = %i[
|
||||
id follower_id follower_type
|
||||
].freeze
|
||||
private_constant :USERS_ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
private
|
||||
|
||||
def limit_per_page(default:, max:)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,14 @@ module Api
|
|||
|
||||
skip_before_action :verify_authenticity_token, only: %i[create update]
|
||||
|
||||
# Note: since this is used for selecting from the DB, we need to use the
|
||||
# actual column name for the listing category, prefixed with classified_.
|
||||
ATTRIBUTES_FOR_SERIALIZATION = %i[
|
||||
id user_id organization_id title slug body_markdown cached_tag_list
|
||||
classified_listing_category_id processed_html published
|
||||
].freeze
|
||||
private_constant :ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
def index
|
||||
@listings = Listing.published.
|
||||
select(ATTRIBUTES_FOR_SERIALIZATION).
|
||||
|
|
@ -51,14 +59,6 @@ module Api
|
|||
super
|
||||
end
|
||||
|
||||
# Note: since this is used for selecting from the DB, we need to use the
|
||||
# actual column name for the listing category, prefixed with classified_.
|
||||
ATTRIBUTES_FOR_SERIALIZATION = %i[
|
||||
id user_id organization_id title slug body_markdown cached_tag_list
|
||||
classified_listing_category_id processed_html published
|
||||
].freeze
|
||||
private_constant :ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
private
|
||||
|
||||
attr_accessor :user
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ module Api
|
|||
class TagsController < ApiController
|
||||
before_action :set_cache_control_headers, only: %i[index]
|
||||
|
||||
ATTRIBUTES_FOR_SERIALIZATION = %i[id name bg_color_hex text_color_hex].freeze
|
||||
private_constant :ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
def index
|
||||
page = params[:page]
|
||||
per_page = (params[:per_page] || 10).to_i
|
||||
|
|
@ -14,9 +17,6 @@ module Api
|
|||
|
||||
set_surrogate_key_header Tag.table_key, @tags.map(&:record_key)
|
||||
end
|
||||
|
||||
ATTRIBUTES_FOR_SERIALIZATION = %i[id name bg_color_hex text_color_hex].freeze
|
||||
private_constant :ATTRIBUTES_FOR_SERIALIZATION
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,6 +4,12 @@ module Api
|
|||
before_action :authenticate!, only: %i[me]
|
||||
before_action -> { doorkeeper_authorize! :public }, only: :me, if: -> { doorkeeper_token }
|
||||
|
||||
SHOW_ATTRIBUTES_FOR_SERIALIZATION = %i[
|
||||
id username name summary twitter_username github_username website_url
|
||||
location created_at profile_image
|
||||
].freeze
|
||||
private_constant :SHOW_ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
def show
|
||||
relation = User.select(SHOW_ATTRIBUTES_FOR_SERIALIZATION)
|
||||
|
||||
|
|
@ -17,12 +23,6 @@ module Api
|
|||
def me
|
||||
render :show
|
||||
end
|
||||
|
||||
SHOW_ATTRIBUTES_FOR_SERIALIZATION = %i[
|
||||
id username name summary twitter_username github_username website_url
|
||||
location created_at profile_image
|
||||
].freeze
|
||||
private_constant :SHOW_ATTRIBUTES_FOR_SERIALIZATION
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,6 +3,11 @@ module Api
|
|||
class VideosController < ApiController
|
||||
before_action :set_cache_control_headers, only: %i[index]
|
||||
|
||||
INDEX_ATTRIBUTES_FOR_SERIALIZATION = %i[
|
||||
id video path title video_thumbnail_url user_id video_duration_in_seconds
|
||||
].freeze
|
||||
private_constant :INDEX_ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
def index
|
||||
page = params[:page]
|
||||
per_page = (params[:per_page] || 24).to_i
|
||||
|
|
@ -16,11 +21,6 @@ module Api
|
|||
|
||||
set_surrogate_key_header "videos", Article.table_key, @video_articles.map(&:record_key)
|
||||
end
|
||||
|
||||
INDEX_ATTRIBUTES_FOR_SERIALIZATION = %i[
|
||||
id video path title video_thumbnail_url user_id video_duration_in_seconds
|
||||
].freeze
|
||||
private_constant :INDEX_ATTRIBUTES_FOR_SERIALIZATION
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ module Api
|
|||
|
||||
skip_before_action :verify_authenticity_token, only: %w[create destroy]
|
||||
|
||||
ATTRIBUTES_FOR_SERIALIZATION = %i[id user_id source target_url events created_at].freeze
|
||||
private_constant :ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
def index
|
||||
@webhooks = webhooks_scope.order(:id)
|
||||
end
|
||||
|
|
@ -29,9 +32,6 @@ module Api
|
|||
head :no_content
|
||||
end
|
||||
|
||||
ATTRIBUTES_FOR_SERIALIZATION = %i[id user_id source target_url events created_at].freeze
|
||||
private_constant :ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
private
|
||||
|
||||
def webhooks_scope
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ class ChatChannelsController < ApplicationController
|
|||
before_action :set_channel, only: %i[show update update_channel open moderate]
|
||||
after_action :verify_authorized
|
||||
|
||||
CHANNEL_ATTRIBUTES_FOR_SERIALIZATION = %i[id description channel_name].freeze
|
||||
private_constant :CHANNEL_ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
def index
|
||||
if params[:state] == "unopened"
|
||||
authorize ChatChannel
|
||||
|
|
@ -153,9 +156,6 @@ class ChatChannelsController < ApplicationController
|
|||
render json: { error: "not found", status: 404 }, status: :not_found
|
||||
end
|
||||
|
||||
CHANNEL_ATTRIBUTES_FOR_SERIALIZATION = %i[id description channel_name].freeze
|
||||
private_constant :CHANNEL_ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
private
|
||||
|
||||
def set_channel
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ class FollowingsController < ApplicationController
|
|||
before_action :authenticate_user!
|
||||
before_action -> { limit_per_page(default: 80, max: 1000) }
|
||||
|
||||
ATTRIBUTES_FOR_SERIALIZATION = %i[id followable_id followable_type].freeze
|
||||
TAGS_ATTRIBUTES_FOR_SERIALIZATION = [*ATTRIBUTES_FOR_SERIALIZATION, :points].freeze
|
||||
|
||||
def users
|
||||
relation = current_user.follows_by_type("User").
|
||||
select(ATTRIBUTES_FOR_SERIALIZATION).
|
||||
|
|
@ -30,10 +33,8 @@ class FollowingsController < ApplicationController
|
|||
@followed_podcasts = load_follows_and_paginate(relation)
|
||||
end
|
||||
|
||||
ATTRIBUTES_FOR_SERIALIZATION = %i[id followable_id followable_type].freeze
|
||||
private_constant :ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
TAGS_ATTRIBUTES_FOR_SERIALIZATION = [*ATTRIBUTES_FOR_SERIALIZATION, :points].freeze
|
||||
private_constant :TAGS_ATTRIBUTES_FOR_SERIALIZATION
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
module Internal
|
||||
class ListingsController < Internal::ApplicationController
|
||||
include ListingsToolkit
|
||||
ALLOWED_PARAMS = %i[
|
||||
published body_markdown title category listing_category_id tag_list action
|
||||
].freeze
|
||||
layout "internal"
|
||||
|
||||
def index
|
||||
|
|
@ -35,9 +38,6 @@ module Internal
|
|||
|
||||
private
|
||||
|
||||
ALLOWED_PARAMS = %i[
|
||||
published body_markdown title category listing_category_id tag_list action
|
||||
].freeze
|
||||
private_constant :ALLOWED_PARAMS
|
||||
|
||||
def listing_params
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ class TagsController < ApplicationController
|
|||
before_action :authenticate_user!, only: %i[edit update]
|
||||
after_action :verify_authorized
|
||||
|
||||
ATTRIBUTES_FOR_SERIALIZATION = %i[id name bg_color_hex text_color_hex].freeze
|
||||
|
||||
def index
|
||||
skip_authorization
|
||||
@tags_index = true
|
||||
|
|
@ -62,6 +64,5 @@ class TagsController < ApplicationController
|
|||
params.require(:tag).permit(accessible)
|
||||
end
|
||||
|
||||
ATTRIBUTES_FOR_SERIALIZATION = %i[id name bg_color_hex text_color_hex].freeze
|
||||
private_constant :ATTRIBUTES_FOR_SERIALIZATION
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
# To go through a markdown document. Mainly used to decide if we are in
|
||||
# code blocks to decide if we should escape underscored usernames.
|
||||
class MarkdownTraverser
|
||||
CODEBLOCK_MARKER = "```".freeze
|
||||
|
||||
def initialize(markdown)
|
||||
@lines = markdown.dup.lines
|
||||
init_position
|
||||
|
|
@ -19,7 +21,6 @@ class MarkdownTraverser
|
|||
|
||||
private
|
||||
|
||||
CODEBLOCK_MARKER = "```".freeze
|
||||
private_constant :CODEBLOCK_MARKER
|
||||
|
||||
attr_reader :lines
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
class Reaction < ApplicationRecord
|
||||
include Searchable
|
||||
BASE_POINTS = {
|
||||
"vomit" => -50.0,
|
||||
"thumbsup" => 5.0,
|
||||
"thumbsdown" => -10.0
|
||||
}.freeze
|
||||
|
||||
SEARCH_SERIALIZER = Search::ReactionSerializer
|
||||
SEARCH_CLASS = Search::Reaction
|
||||
|
|
@ -160,12 +165,6 @@ class Reaction < ApplicationRecord
|
|||
user_id
|
||||
end
|
||||
|
||||
BASE_POINTS = {
|
||||
"vomit" => -50.0,
|
||||
"thumbsup" => 5.0,
|
||||
"thumbsdown" => -10.0
|
||||
}.freeze
|
||||
|
||||
def assign_points
|
||||
base_points = BASE_POINTS.fetch(category, 1.0)
|
||||
base_points = 0 if status == "invalid"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ class Tag < ActsAsTaggableOn::Tag
|
|||
acts_as_followable
|
||||
resourcify
|
||||
|
||||
# This model doesn't inherit from ApplicationRecord so this has to be included
|
||||
include Purgeable
|
||||
include Searchable
|
||||
ALLOWED_CATEGORIES = %w[uncategorized language library tool site_mechanic location subcommunity].freeze
|
||||
|
||||
belongs_to :badge, optional: true
|
||||
|
|
@ -36,14 +39,10 @@ class Tag < ActsAsTaggableOn::Tag
|
|||
|
||||
scope :eager_load_serialized_data, -> {}
|
||||
|
||||
include Searchable
|
||||
SEARCH_SERIALIZER = Search::TagSerializer
|
||||
SEARCH_CLASS = Search::Tag
|
||||
DATA_SYNC_CLASS = DataSync::Elasticsearch::Tag
|
||||
|
||||
# This model doesn't inherit from ApplicationRecord so this has to be included
|
||||
include Purgeable
|
||||
|
||||
# possible social previews templates for articles with a particular tag
|
||||
def self.social_preview_templates
|
||||
Rails.root.join("app/views/social_previews/articles").children.map { |ch| File.basename(ch, ".html.erb") }
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@ module Articles
|
|||
include Rails.application.routes.url_helpers
|
||||
include CloudinaryHelper
|
||||
|
||||
SOCIAL_PREVIEW_MIGRATION_DATETIME = Time.zone.parse("2019-04-22T00:00:00Z")
|
||||
|
||||
def initialize(article, **options)
|
||||
@article = article
|
||||
@height = options[:height] || 500
|
||||
@width = options[:width] || 1000
|
||||
end
|
||||
|
||||
SOCIAL_PREVIEW_MIGRATION_DATETIME = Time.zone.parse("2019-04-22T00:00:00Z")
|
||||
|
||||
def url
|
||||
image = user_defined_image
|
||||
if image.present?
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue