style: rubocop

This commit is contained in:
Neetpone 2024-04-04 04:21:23 -04:00 committed by Neetpone
parent 7349fba52f
commit 902e2d422b
66 changed files with 430 additions and 154 deletions

58
.rubocop.yml Normal file
View file

@ -0,0 +1,58 @@
inherit_from: .rubocop_todo.yml
AllCops:
SuggestExtensions: false
NewCops: enable
Exclude:
- db/migrate/*.rb
- db/schema.rb
- vendor/**/*
- public/**/*
- tmp/**/*
- spec/rails_helper.rb
- lib/tasks/auto_annotate_models.rake
Style/FetchEnvVar:
Enabled: false
# I just don't like it
Layout/EmptyLineAfterMagicComment:
Enabled: false
# These next two are stylistic choices I don't agree with
Style/MultilineIfModifier:
Enabled: false
Style/IfUnlessModifier:
Enabled: false
# It just feels wrong
Style/HashSyntax:
EnforcedShorthandSyntax: never
# This is too convenient not to
Style/GlobalVars:
AllowedVariables:
- $redis
Style/FrozenStringLiteralComment:
Enabled: true
# Don't like it
Style/EmptyMethod:
Enabled: false
Style/ClassVars:
Enabled: false
Style/ClassAndModuleChildren:
EnforcedStyle: compact
# This does the oppposite of what I want to do.
Layout/HashAlignment:
Enabled: false
Layout/CaseIndentation:
IndentOneStep: true
Style/NumericPredicate:
Enabled: false

124
.rubocop_todo.yml Normal file
View file

@ -0,0 +1,124 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-04-04 07:59:52 UTC using RuboCop version 1.62.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
Exclude:
- 'db/schema.rb'
# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_braces
Layout/FirstHashElementIndentation:
EnforcedStyle: consistent
# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideHashLiteralBraces:
Exclude:
- 'app/controllers/search_controller.rb'
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, compact, no_space
Layout/SpaceInsideParens:
Exclude:
- 'app/controllers/search_controller.rb'
# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
Layout/SpaceInsidePercentLiteralDelimiters:
Exclude:
- 'Gemfile'
# Offense count: 6
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 48
# Offense count: 3
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 53
# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 16
# Offense count: 12
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 50
# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 17
# Offense count: 2
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Exclude:
- 'app/helpers/search_helper.rb'
# Offense count: 22
# Configuration parameters: AllowedConstants.
Style/Documentation:
Enabled: false
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/GlobalStdStream:
Exclude:
- 'config/environments/production.rb'
# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: literals, strict
Style/MutableConstant:
Exclude:
- 'app/controllers/search_controller.rb'
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/PerlBackrefs:
Exclude:
- 'bin/bundle'
# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SafeForConstants.
Style/RedundantFetchBlock:
Exclude:
- 'config/puma.rb'
-
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: RequireEnglish.
# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
Style/SpecialGlobalVars:
EnforcedStyle: use_perl_names
# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 198

28
Gemfile
View file

@ -1,43 +1,45 @@
source "https://rubygems.org" # frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" } git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.2.2" ruby '3.2.2'
gem "rails", "~> 7.0.8", ">= 7.0.8.1"
gem "sprockets-rails"
gem "pg", "~> 1.1"
gem "puma", "~> 5.0"
gem 'slim-rails'
gem 'kaminari' gem 'kaminari'
gem 'pg', '~> 1.1'
gem 'puma', '~> 5.0'
gem 'rails', '~> 7.0.8', '>= 7.0.8.1'
gem 'redcarpet' gem 'redcarpet'
gem 'slim-rails'
gem 'sprockets-rails'
gem 'redis' gem 'redis'
gem 'elasticsearch-model' gem 'elasticsearch-model'
gem 'model-msearch'
gem 'fancy_searchable', github: 'Twibooru/fancy_searchable', ref: '40687c9' gem 'fancy_searchable', github: 'Twibooru/fancy_searchable', ref: '40687c9'
gem 'model-msearch'
gem 'sidekiq' gem 'sidekiq'
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] gem 'tzinfo-data', platforms: %i[ mingw mswin x64_mingw jruby ]
# Use Sass to process CSS # Use Sass to process CSS
# gem "sassc-rails" # gem "sassc-rails"
group :development, :test do group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ] gem 'debug', platforms: %i[ mri mingw x64_mingw ]
end end
group :development do group :development do
gem "web-console"
gem 'annotate' gem 'annotate'
gem 'bullet' gem 'bullet'
gem 'rubocop', require: false
gem 'web-console'
end end
group :test do group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara" gem 'capybara'
gem "selenium-webdriver" gem 'selenium-webdriver'
end end

View file

@ -80,6 +80,7 @@ GEM
annotate (3.2.0) annotate (3.2.0)
activerecord (>= 3.2, < 8.0) activerecord (>= 3.2, < 8.0)
rake (>= 10.4, < 14.0) rake (>= 10.4, < 14.0)
ast (2.4.2)
base64 (0.2.0) base64 (0.2.0)
bindex (0.8.1) bindex (0.8.1)
builder (3.2.4) builder (3.2.4)
@ -128,6 +129,7 @@ GEM
irb (1.12.0) irb (1.12.0)
rdoc rdoc
reline (>= 0.4.2) reline (>= 0.4.2)
json (2.7.2)
kaminari (1.2.2) kaminari (1.2.2)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2) kaminari-actionview (= 1.2.2)
@ -140,6 +142,7 @@ GEM
activerecord activerecord
kaminari-core (= 1.2.2) kaminari-core (= 1.2.2)
kaminari-core (1.2.2) kaminari-core (1.2.2)
language_server-protocol (3.17.0.3)
loofah (2.22.0) loofah (2.22.0)
crass (~> 1.0.2) crass (~> 1.0.2)
nokogiri (>= 1.12.0) nokogiri (>= 1.12.0)
@ -170,6 +173,10 @@ GEM
nio4r (2.7.1) nio4r (2.7.1)
nokogiri (1.16.3-x86_64-linux) nokogiri (1.16.3-x86_64-linux)
racc (~> 1.4) racc (~> 1.4)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
pg (1.5.6) pg (1.5.6)
psych (5.1.2) psych (5.1.2)
stringio stringio
@ -208,6 +215,7 @@ GEM
rake (>= 12.2) rake (>= 12.2)
thor (~> 1.0) thor (~> 1.0)
zeitwerk (~> 2.5) zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.1.0) rake (13.1.0)
rdoc (6.6.3.1) rdoc (6.6.3.1)
psych (>= 4.0.0) psych (>= 4.0.0)
@ -220,6 +228,20 @@ GEM
reline (0.5.0) reline (0.5.0)
io-console (~> 0.5) io-console (~> 0.5)
rexml (3.2.6) rexml (3.2.6)
rubocop (1.62.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
ruby-progressbar (1.13.0)
rubyzip (2.3.2) rubyzip (2.3.2)
selenium-webdriver (4.19.0) selenium-webdriver (4.19.0)
base64 (~> 0.2) base64 (~> 0.2)
@ -252,6 +274,7 @@ GEM
timeout (0.4.1) timeout (0.4.1)
tzinfo (2.0.6) tzinfo (2.0.6)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
uniform_notifier (1.16.0) uniform_notifier (1.16.0)
uri (0.13.0) uri (0.13.0)
web-console (4.2.1) web-console (4.2.1)
@ -284,6 +307,7 @@ DEPENDENCIES
rails (~> 7.0.8, >= 7.0.8.1) rails (~> 7.0.8, >= 7.0.8.1)
redcarpet redcarpet
redis redis
rubocop
selenium-webdriver selenium-webdriver
sidekiq sidekiq
slim-rails slim-rails

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true
# Add your own tasks in files placed in lib/tasks ending in .rake, # 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. # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require_relative "config/application" require_relative 'config/application'
Rails.application.load_tasks Rails.application.load_tasks

View file

@ -1,4 +1,3 @@
module ApplicationCable # frozen_string_literal: true
class Channel < ActionCable::Channel::Base class ApplicationCable::Channel < ActionCable::Channel::Base
end
end end

View file

@ -1,4 +1,3 @@
module ApplicationCable # frozen_string_literal: true
class Connection < ActionCable::Connection::Base class ApplicationCable::Connection < ActionCable::Connection::Base
end
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
before_action :start_timer before_action :start_timer
before_action :setup_pagination_and_tags before_action :setup_pagination_and_tags

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class AuthorsController < ApplicationController class AuthorsController < ApplicationController
def show def show
@author = Author.find(params[:id]) @author = Author.find(params[:id])

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'redcarpet' require 'redcarpet'
class ChaptersController < ApplicationController class ChaptersController < ApplicationController
@ -17,7 +18,7 @@ class ChaptersController < ApplicationController
# This is fucking bad, this gets rid of the redundant title - this should be fixed upstairs, # This is fucking bad, this gets rid of the redundant title - this should be fixed upstairs,
# in the actual generation of the Markdown. # in the actual generation of the Markdown.
if body.length >= 2 && body[0] == @chapter.title && body[1].length > 0 && body[1][0] == '=' if body.length >= 2 && body[0] == @chapter.title && !body[1].empty? && body[1][0] == '='
body = body[2..] body = body[2..]
end end

View file

@ -1,8 +1,9 @@
# frozen_string_literal: true
require 'open-uri' require 'open-uri'
# Handles proxying images from the FiMFiction CDN and caching them locally, in case they disappear. # Handles proxying images from the FiMFiction CDN and caching them locally, in case they disappear.
class ImagesController < ApplicationController class ImagesController < ApplicationController
#noinspection RubyMismatchedArgumentType # noinspection RubyMismatchedArgumentType
def show def show
url = params[:url] url = params[:url]
parsed = URI.parse(url) parsed = URI.parse(url)
@ -15,16 +16,17 @@ class ImagesController < ApplicationController
ext = File.extname(url) ext = File.extname(url)
hash = Digest::SHA256.hexdigest(url) hash = Digest::SHA256.hexdigest(url)
path = Rails.root.join('public', 'cached-images', hash + ext) path = Rails.root.join('public', 'cached-images', hash + ext)
our_url = '/cached-images/' + hash + ext our_url = "/cached-images/#{hash}#{ext}"
if File.exist? path if File.exist? path
redirect_to our_url redirect_to our_url
return return
end end
File.open(path, 'wb') do |fp| File.binwrite(
fp.write(Net::HTTP.get(parsed)) path,
end Net::HTTP.get(parsed)
)
redirect_to our_url redirect_to our_url
end end

View file

@ -1,7 +1,8 @@
# frozen_string_literal: true
# This whole class is a giant mess but I coded it fast so give me a break. # This whole class is a giant mess but I coded it fast so give me a break.
class SearchController < ApplicationController class SearchController < ApplicationController
ALLOWED_SORT_DIRS = [:asc, :desc] ALLOWED_SORT_DIRS = %i[asc desc]
ALLOWED_SORT_FIELDS = [:title, :author, :date_published, :date_updated, :num_words, :rel] ALLOWED_SORT_FIELDS = %i[title author date_published date_updated num_words rel]
before_action :load_tags before_action :load_tags
@ -74,10 +75,10 @@ class SearchController < ApplicationController
# returns: [included tags, excluded tags] # returns: [included tags, excluded tags]
def parse_tag_queries def parse_tag_queries
tag_searches = (@search_params['tags'] + ',' + @search_params['characters']).split(',').reject &:blank? tag_searches = "#{@search_params['tags']},#{@search_params['characters']}".split(',').reject(&:blank?)
[ [
tag_searches.select { |t| t[0] != '-' }, tag_searches.reject { |t| t[0] == '-' },
tag_searches.select { |t| t[0] == '-' } tag_searches.select { |t| t[0] == '-' }
.map { |t| t[1..] } .map { |t| t[1..] }
] ]
@ -89,11 +90,11 @@ class SearchController < ApplicationController
# we need to sort on the keyword versions of text fields, to avoid using fielddata. # we need to sort on the keyword versions of text fields, to avoid using fielddata.
sf = case sf sf = case sf
when :rel then when :rel
:_score :_score
when :title then when :title
:title_keyword :title_keyword
when :author then when :author
:author_keyword :author_keyword
else else
sf sf
@ -111,7 +112,7 @@ class SearchController < ApplicationController
if params[:scope].present? if params[:scope].present?
result = $redis.get("search_scope/#{params[:scope]}") result = $redis.get("search_scope/#{params[:scope]}")
if result.present? if result.present?
@search_params = JSON.load(result) @search_params = JSON.parse(result)
@scope_key = params[:scope] @scope_key = params[:scope]
scope_valid = true scope_valid = true
else else

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class StaticPagesController < ApplicationController class StaticPagesController < ApplicationController
def about def about
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class StoriesController < ApplicationController class StoriesController < ApplicationController
def index def index
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module ApplicationHelper module ApplicationHelper
# https://infusion.media/content-marketing/how-to-calculate-reading-time/ # https://infusion.media/content-marketing/how-to-calculate-reading-time/
def reading_time(words) def reading_time(words)

View file

@ -1,2 +1,3 @@
# frozen_string_literal: true
module AuthorsHelper module AuthorsHelper
end end

View file

@ -1,2 +1,3 @@
# frozen_string_literal: true
module ChaptersHelper module ChaptersHelper
end end

View file

@ -1,2 +1,3 @@
# frozen_string_literal: true
module ImagesHelper module ImagesHelper
end end

View file

@ -1,15 +1,16 @@
# frozen_string_literal: true
module SearchHelper module SearchHelper
def rating_display(rating) def rating_display(rating)
case rating case rating
when 'everyone' then when 'everyone'
tag.div class: 'frating ev', title: 'Rated Everyone' do tag.div class: 'frating ev', title: 'Rated Everyone' do
'Everyone' 'Everyone'
end end
when 'teen' then when 'teen'
tag.div class: 'frating', title: 'Rated Teen' do tag.div class: 'frating', title: 'Rated Teen' do
'Teen' 'Teen'
end end
when 'explicit' then when 'explicit'
tag.div class: 'frating', title: 'Rated Explicit' do tag.div class: 'frating', title: 'Rated Explicit' do
'Explicit' 'Explicit'
end end
@ -18,19 +19,19 @@ module SearchHelper
def status_display(status) def status_display(status)
case status case status
when 'complete' then when 'complete'
tag.div class: 'fstatus sc', title: 'Complete' do tag.div class: 'fstatus sc', title: 'Complete' do
'Complete' 'Complete'
end end
when 'incomplete' then when 'incomplete'
tag.div class: 'fstatus si', title: 'Incomplete' do tag.div class: 'fstatus si', title: 'Incomplete' do
'Incomplete' 'Incomplete'
end end
when 'hiatus' then when 'hiatus'
tag.div class: 'fstatus sh', title: 'On Hiatus' do tag.div class: 'fstatus sh', title: 'On Hiatus' do
'On Hiatus' 'On Hiatus'
end end
when 'cancelled' then when 'cancelled'
tag.div class: 'fstatus sn', title: 'Cancelled' do tag.div class: 'fstatus sn', title: 'Cancelled' do
'Cancelled' 'Cancelled'
end end

View file

@ -1,2 +1,3 @@
# frozen_string_literal: true
module StaticPagesHelper module StaticPagesHelper
end end

View file

@ -1,2 +1,3 @@
# frozen_string_literal: true
module StoriesHelper module StoriesHelper
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module StoryIndex module StoryIndex
def self.included(base) def self.included(base)
base.settings index: { number_of_shards: 5, max_result_window: 10_000_000 } do base.settings index: { number_of_shards: 5, max_result_window: 10_000_000 } do
@ -31,10 +32,10 @@ module StoryIndex
[date_published: :desc] [date_published: :desc]
end end
def allowed_search_fields(access_options = {}) def allowed_search_fields(_access_options = {})
[:title, :completion_status, :content_rating, :date_published, :date_updated, :date_modified, %i[title completion_status content_rating date_published date_updated date_modified
:num_comments, :num_views, :num_words, :rating, :short_description, :description_html, num_comments num_views num_words rating short_description description_html
:title, :title_keyword, :tags, :author, :author_keyword] title title_keyword tags author author_keyword]
end end
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class ApplicationJob < ActiveJob::Base class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock # Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked # retry_on ActiveRecord::Deadlocked

View file

@ -4,8 +4,8 @@ class IndexUpdateJob < ApplicationJob
queue_as :high queue_as :high
def perform(cls, id) def perform(cls, id)
obj = cls.constantize.find(id) obj = cls.constantize.find(id)
obj.update_index(defer: false) if obj obj&.update_index(defer: false)
rescue StandardError => ex rescue StandardError => e
Rails.logger.error ex.message Rails.logger.error e.message
end end
end end

View file

@ -1,10 +1,12 @@
# frozen_string_literal: true
class RecountWordsJob < ApplicationJob class RecountWordsJob < ApplicationJob
def perform(*) def perform(*)
Story.find_each do |story| Story.find_each do |story|
word_count = 0 word_count = 0
story.chapters.each do |chapter| story.chapters.each do |chapter|
next unless chapter.body next unless chapter.body
count = chapter.body.split(' ').size
count = chapter.body.split.size
chapter.update_columns( chapter.update_columns(
num_words: count num_words: count
) )

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base class ApplicationRecord < ActiveRecord::Base
primary_abstract_class primary_abstract_class
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# == Schema Information # == Schema Information
# #
# Table name: authors # Table name: authors

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# == Schema Information # == Schema Information
# #
# Table name: chapters # Table name: chapters

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# == Schema Information # == Schema Information
# #
# Table name: stories # Table name: stories

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# == Schema Information # == Schema Information
# #
# Table name: story_taggings # Table name: story_taggings

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# == Schema Information # == Schema Information
# #
# Table name: tags # Table name: tags

View file

@ -8,7 +8,7 @@
# this file is here to facilitate running it. # this file is here to facilitate running it.
# #
require "rubygems" require 'rubygems'
m = Module.new do m = Module.new do
module_function module_function
@ -18,12 +18,13 @@ m = Module.new do
end end
def env_var_version def env_var_version
ENV["BUNDLER_VERSION"] ENV['BUNDLER_VERSION']
end end
def cli_arg_version def cli_arg_version
return unless invoked_as_script? # don't want to hijack other binstubs return unless invoked_as_script? # don't want to hijack other binstubs
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`
bundler_version = nil bundler_version = nil
update_index = nil update_index = nil
ARGV.each_with_index do |a, i| ARGV.each_with_index do |a, i|
@ -31,6 +32,7 @@ m = Module.new do
bundler_version = a bundler_version = a
end end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
bundler_version = $1 bundler_version = $1
update_index = i update_index = i
end end
@ -38,16 +40,16 @@ m = Module.new do
end end
def gemfile def gemfile
gemfile = ENV["BUNDLE_GEMFILE"] gemfile = ENV['BUNDLE_GEMFILE']
return gemfile if gemfile && !gemfile.empty? return gemfile if gemfile && !gemfile.empty?
File.expand_path("../Gemfile", __dir__) File.expand_path('../Gemfile', __dir__)
end end
def lockfile def lockfile
lockfile = lockfile =
case File.basename(gemfile) case File.basename(gemfile)
when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") when 'gems.rb' then gemfile.sub(/\.rb$/, '.locked')
else "#{gemfile}.lock" else "#{gemfile}.lock"
end end
File.expand_path(lockfile) File.expand_path(lockfile)
@ -55,8 +57,10 @@ m = Module.new do
def lockfile_version def lockfile_version
return unless File.file?(lockfile) return unless File.file?(lockfile)
lockfile_contents = File.read(lockfile) lockfile_contents = File.read(lockfile)
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
Regexp.last_match(1) Regexp.last_match(1)
end end
@ -76,20 +80,22 @@ m = Module.new do
end end
def load_bundler! def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile ENV['BUNDLE_GEMFILE'] ||= gemfile
activate_bundler activate_bundler
end end
def activate_bundler def activate_bundler
gem_error = activation_error_handling do gem_error = activation_error_handling do
gem "bundler", bundler_requirement gem 'bundler', bundler_requirement
end end
return if gem_error.nil? return if gem_error.nil?
require_error = activation_error_handling do require_error = activation_error_handling do
require "bundler/version" require 'bundler/version'
end end
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
exit 42 exit 42
end end
@ -105,5 +111,5 @@ end
m.load_bundler! m.load_bundler!
if m.invoked_as_script? if m.invoked_as_script?
load Gem.bin_path("bundler", "bundle") load Gem.bin_path('bundler', 'bundle')
end end

View file

@ -1,4 +1,5 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true
require_relative "../config/application" require_relative '../config/application'
require "importmap/commands" require 'importmap/commands'

View file

@ -1,4 +1,5 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
APP_PATH = File.expand_path("../config/application", __dir__) # frozen_string_literal: true
require_relative "../config/boot" APP_PATH = File.expand_path('../config/application', __dir__)
require "rails/commands" require_relative '../config/boot'
require 'rails/commands'

View file

@ -1,4 +1,5 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require_relative "../config/boot" # frozen_string_literal: true
require "rake" require_relative '../config/boot'
require 'rake'
Rake.application.run Rake.application.run

View file

@ -1,8 +1,9 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require "fileutils" # frozen_string_literal: true
require 'fileutils'
# path to your application root. # path to your application root.
APP_ROOT = File.expand_path("..", __dir__) APP_ROOT = File.expand_path('..', __dir__)
def system!(*args) def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==") system(*args) || abort("\n== Command #{args} failed ==")
@ -13,9 +14,9 @@ FileUtils.chdir APP_ROOT do
# This script is idempotent, so that you can run it at any time and get an expectable outcome. # This script is idempotent, so that you can run it at any time and get an expectable outcome.
# Add necessary setup steps to this file. # Add necessary setup steps to this file.
puts "== Installing dependencies ==" puts '== Installing dependencies =='
system! "gem install bundler --conservative" system! 'gem install bundler --conservative'
system("bundle check") || system!("bundle install") system('bundle check') || system!('bundle install')
# puts "\n== Copying sample files ==" # puts "\n== Copying sample files =="
# unless File.exist?("config/database.yml") # unless File.exist?("config/database.yml")
@ -23,11 +24,11 @@ FileUtils.chdir APP_ROOT do
# end # end
puts "\n== Preparing database ==" puts "\n== Preparing database =="
system! "bin/rails db:prepare" system! 'bin/rails db:prepare'
puts "\n== Removing old logs and tempfiles ==" puts "\n== Removing old logs and tempfiles =="
system! "bin/rails log:clear tmp:clear" system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server ==" puts "\n== Restarting application server =="
system! "bin/rails restart" system! 'bin/rails restart'
end end

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true
# This file is used by Rack-based servers to start the application. # This file is used by Rack-based servers to start the application.
require_relative "config/environment" require_relative 'config/environment'
run Rails.application run Rails.application
Rails.application.load_server Rails.application.load_server

View file

@ -1,25 +1,32 @@
require_relative "boot" # frozen_string_literal: true
require_relative 'boot'
require "rails" require 'rails'
# Pick the frameworks you want: # Pick the frameworks you want:
require "active_model/railtie" require 'active_model/railtie'
require "active_job/railtie" require 'active_job/railtie'
require "active_record/railtie" require 'active_record/railtie'
# require "active_storage/engine" # require "active_storage/engine"
require "action_controller/railtie" require 'action_controller/railtie'
# require "action_mailer/railtie" # require "action_mailer/railtie"
# require "action_mailbox/engine" # require "action_mailbox/engine"
# require "action_text/engine" # require "action_text/engine"
require "action_view/railtie" require 'action_view/railtie'
require "action_cable/engine" require 'action_cable/engine'
require "rails/test_unit/railtie" require 'rails/test_unit/railtie'
# Require the gems listed in Gemfile, including any gems # Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production. # you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups) Bundler.require(*Rails.groups)
module Foalfetch # Configuration for the application, engines, and railties goes here.
class Application < Rails::Application #
# These settings can be overridden in specific environments using the files
# in config/environments, which are processed later.
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
class Foalfetch::Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version. # Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0 config.load_defaults 7.0
@ -30,5 +37,4 @@ module Foalfetch
# #
# config.time_zone = "Central Time (US & Canada)" # config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras") # config.eager_load_paths << Rails.root.join("extras")
end
end end

View file

@ -1,3 +1,4 @@
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) # frozen_string_literal: true
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require "bundler/setup" # Set up gems listed in the Gemfile. require 'bundler/setup' # Set up gems listed in the Gemfile.

View file

@ -1,5 +1,6 @@
# frozen_string_literal: true
# Load the Rails application. # Load the Rails application.
require_relative "application" require_relative 'application'
# Initialize the Rails application. # Initialize the Rails application.
Rails.application.initialize! Rails.application.initialize!

View file

@ -1,4 +1,5 @@
require "active_support/core_ext/integer/time" # frozen_string_literal: true
require 'active_support/core_ext/integer/time'
Rails.application.configure do Rails.application.configure do
config.after_initialize do config.after_initialize do
@ -28,13 +29,13 @@ Rails.application.configure do
# Enable/disable caching. By default caching is disabled. # Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching. # Run rails dev:cache to toggle caching.
if Rails.root.join("tmp/caching-dev.txt").exist? if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true config.action_controller.enable_fragment_cache_logging = true
config.cache_store = :memory_store config.cache_store = :memory_store
config.public_file_server.headers = { config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{2.days.to_i}" 'Cache-Control' => "public, max-age=#{2.days.to_i}"
} }
else else
config.action_controller.perform_caching = false config.action_controller.perform_caching = false

View file

@ -1,4 +1,5 @@
require "active_support/core_ext/integer/time" # frozen_string_literal: true
require 'active_support/core_ext/integer/time'
Rails.application.configure do Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb. # Settings specified here will take precedence over those in config/application.rb.
@ -22,7 +23,7 @@ Rails.application.configure do
# Disable serving static files from the `/public` folder by default since # Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this. # Apache or NGINX already handles this.
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress CSS using a preprocessor. # Compress CSS using a preprocessor.
# config.assets.css_compressor = :sass # config.assets.css_compressor = :sass
@ -50,7 +51,7 @@ Rails.application.configure do
config.log_level = :info config.log_level = :info
# Prepend all log lines with the following tags. # Prepend all log lines with the following tags.
config.log_tags = [ :request_id ] config.log_tags = [:request_id]
# Use a different cache store in production. # Use a different cache store in production.
# config.cache_store = :mem_cache_store # config.cache_store = :mem_cache_store
@ -67,13 +68,13 @@ Rails.application.configure do
config.active_support.report_deprecations = false config.active_support.report_deprecations = false
# Use default logging formatter so that PID and timestamp are not suppressed. # Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new config.log_formatter = Logger::Formatter.new
# Use a different logger for distributed setups. # Use a different logger for distributed setups.
# require "syslog/logger" # require "syslog/logger"
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")
if ENV["RAILS_LOG_TO_STDOUT"].present? if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new(STDOUT) logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger) config.logger = ActiveSupport::TaggedLogging.new(logger)

View file

@ -1,4 +1,5 @@
require "active_support/core_ext/integer/time" # frozen_string_literal: true
require 'active_support/core_ext/integer/time'
# The test environment is used exclusively to run your application's # The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that # test suite. You never need to work with it otherwise. Remember that
@ -14,12 +15,12 @@ Rails.application.configure do
# Eager loading loads your whole application. When running a single test locally, # Eager loading loads your whole application. When running a single test locally,
# this probably isn't necessary. It's a good idea to do in a continuous integration # this probably isn't necessary. It's a good idea to do in a continuous integration
# system, or in some way before deploying your code. # system, or in some way before deploying your code.
config.eager_load = ENV["CI"].present? config.eager_load = ENV['CI'].present?
# Configure public file server for tests with Cache-Control for performance. # Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true config.public_file_server.enabled = true
config.public_file_server.headers = { config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{1.hour.to_i}" 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
} }
# Show full error reports and disable caching. # Show full error reports and disable caching.

View file

@ -1,7 +1,8 @@
# frozen_string_literal: true
# Pin npm packages by running ./bin/importmap # Pin npm packages by running ./bin/importmap
pin "application" pin 'application'
pin "@hotwired/turbo-rails", to: "turbo.min.js" pin '@hotwired/turbo-rails', to: 'turbo.min.js'
pin "@hotwired/stimulus", to: "stimulus.min.js" pin '@hotwired/stimulus', to: 'stimulus.min.js'
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" pin '@hotwired/stimulus-loading', to: 'stimulus-loading.js'
pin_all_from "app/javascript/controllers", under: "controllers" pin_all_from 'app/javascript/controllers', under: 'controllers'

View file

@ -1,7 +1,8 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # 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. # Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = "1.0" Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path. # Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path # Rails.application.config.assets.paths << Emoji.images_path

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Define an application-wide content security policy. # Define an application-wide content security policy.

View file

@ -1,8 +1,9 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Configure parameters to be filtered from the log file. Use this to limit dissemination of # Configure parameters to be filtered from the log file. Use this to limit dissemination of
# sensitive information. See the ActiveSupport::ParameterFilter documentation for supported # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported
# notations and behaviors. # notations and behaviors.
Rails.application.config.filter_parameters += [ Rails.application.config.filter_parameters += %i[
:passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn passw secret token _key crypt salt certificate otp ssn
] ]

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections # Add new inflection rules using the following format. Inflections

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# Define an application-wide HTTP permissions policy. For further # Define an application-wide HTTP permissions policy. For further
# information see https://developers.google.com/web/updates/2018/06/feature-policy # information see https://developers.google.com/web/updates/2018/06/feature-policy
# #

View file

@ -2,7 +2,7 @@
ENV['REDIS_HOST'] ||= 'localhost' ENV['REDIS_HOST'] ||= 'localhost'
#require 'hiredis' # require 'hiredis'
require 'redis' require 'redis'
$redis = Redis.new(host: ENV['REDIS_HOST']) $redis = Redis.new(host: ENV['REDIS_HOST'])

View file

@ -1,28 +1,29 @@
# frozen_string_literal: true
# Puma can serve each request in a thread from an internal thread pool. # Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum. # The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match # 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 # 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. # and maximum; this matches the default thread size of Active Record.
# #
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
threads min_threads_count, max_threads_count threads min_threads_count, max_threads_count
# Specifies the `worker_timeout` threshold that Puma will use to wait before # Specifies the `worker_timeout` threshold that Puma will use to wait before
# terminating a worker in development environments. # terminating a worker in development environments.
# #
worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development'
# Specifies the `port` that Puma will listen on to receive requests; default is 3000. # 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. # Specifies the `environment` that Puma will run in.
# #
environment ENV.fetch("RAILS_ENV") { "development" } environment ENV.fetch('RAILS_ENV') { 'development' }
# Specifies the `pidfile` that Puma will use. # Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' }
# Specifies the number of `workers` to boot in clustered mode. # Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together # Workers are forked web server processes. If using threads and workers together

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
Rails.application.routes.draw do Rails.application.routes.draw do
root 'search#index' root 'search#index'
post '/search' => 'search#search' post '/search' => 'search#search'

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# This file should contain all the record creation needed to seed the database with its default values. # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
# #

View file

@ -1,4 +1,5 @@
require "test_helper" # frozen_string_literal: true
require 'test_helper'
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400] driven_by :selenium, using: :chrome, screen_size: [1400, 1400]

View file

@ -1,4 +1,5 @@
require "test_helper" # frozen_string_literal: true
require 'test_helper'
class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
# test "connects with cookies" do # test "connects with cookies" do

View file

@ -1,4 +1,5 @@
require "test_helper" # frozen_string_literal: true
require 'test_helper'
class AuthorsControllerTest < ActionDispatch::IntegrationTest class AuthorsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do # test "the truth" do

View file

@ -1,4 +1,5 @@
require "test_helper" # frozen_string_literal: true
require 'test_helper'
class ChaptersControllerTest < ActionDispatch::IntegrationTest class ChaptersControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do # test "the truth" do

View file

@ -1,4 +1,5 @@
require "test_helper" # frozen_string_literal: true
require 'test_helper'
class ImagesControllerTest < ActionDispatch::IntegrationTest class ImagesControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do # test "the truth" do

View file

@ -1,4 +1,5 @@
require "test_helper" # frozen_string_literal: true
require 'test_helper'
class SearchControllerTest < ActionDispatch::IntegrationTest class SearchControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do # test "the truth" do

View file

@ -1,4 +1,5 @@
require "test_helper" # frozen_string_literal: true
require 'test_helper'
class StaticPagesControllerTest < ActionDispatch::IntegrationTest class StaticPagesControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do # test "the truth" do

View file

@ -1,4 +1,5 @@
require "test_helper" # frozen_string_literal: true
require 'test_helper'
class StoriesControllerTest < ActionDispatch::IntegrationTest class StoriesControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do # test "the truth" do

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# == Schema Information # == Schema Information
# #
# Table name: authors # Table name: authors
@ -10,7 +11,7 @@
# num_blog_posts :integer default(0), not null # num_blog_posts :integer default(0), not null
# num_followers :integer default(0), not null # num_followers :integer default(0), not null
# #
require "test_helper" require 'test_helper'
class AuthorTest < ActiveSupport::TestCase class AuthorTest < ActiveSupport::TestCase
# test "the truth" do # test "the truth" do

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# == Schema Information # == Schema Information
# #
# Table name: chapters # Table name: chapters
@ -16,7 +17,7 @@
# #
# index_chapters_on_story_id (story_id) # index_chapters_on_story_id (story_id)
# #
require "test_helper" require 'test_helper'
class ChapterTest < ActiveSupport::TestCase class ChapterTest < ActiveSupport::TestCase
# test "the truth" do # test "the truth" do

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# == Schema Information # == Schema Information
# #
# Table name: stories # Table name: stories
@ -25,7 +26,7 @@
# #
# index_stories_on_author_id (author_id) # index_stories_on_author_id (author_id)
# #
require "test_helper" require 'test_helper'
class StoryTest < ActiveSupport::TestCase class StoryTest < ActiveSupport::TestCase
# test "the truth" do # test "the truth" do

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# == Schema Information # == Schema Information
# #
# Table name: tags # Table name: tags
@ -7,7 +8,7 @@
# type :text not null # type :text not null
# old_id :text # old_id :text
# #
require "test_helper" require 'test_helper'
class TagTest < ActiveSupport::TestCase class TagTest < ActiveSupport::TestCase
# test "the truth" do # test "the truth" do

View file

@ -1,6 +1,7 @@
ENV["RAILS_ENV"] ||= "test" # frozen_string_literal: true
require_relative "../config/environment" ENV['RAILS_ENV'] ||= 'test'
require "rails/test_help" require_relative '../config/environment'
require 'rails/test_help'
class ActiveSupport::TestCase class ActiveSupport::TestCase
# Run tests in parallel with specified workers # Run tests in parallel with specified workers