Skip to content

Commit

Permalink
app: update code to Rails 6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kemenaran committed Mar 25, 2021
1 parent de9fab7 commit 5990439
Show file tree
Hide file tree
Showing 25 changed files with 310 additions and 87 deletions.
5 changes: 3 additions & 2 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
load File.expand_path("spring", __dir__)
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
require_relative "../config/boot"
require "rails/commands"
5 changes: 3 additions & 2 deletions bin/rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
load File.expand_path("spring", __dir__)
require_relative "../config/boot"
require "rake"
Rake.application.run
13 changes: 7 additions & 6 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env ruby
require 'fileutils'
require "fileutils"

# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
Expand All @@ -9,10 +9,11 @@ def system!(*args)
end

FileUtils.chdir APP_ROOT do
# This script is a starting point to setup your application.
# This script is a way to set up or update your development environment automatically.
# 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.

puts "\n== Installing dependencies =="
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')

Expand All @@ -29,11 +30,11 @@ FileUtils.chdir APP_ROOT do

# Create the database, load the schema, and initialize it with the seed data
puts "\n== Preparing database =="
system! 'bin/rails db:setup'
system! 'bin/rails db:prepare'

puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'

puts "\n== Done =="
puts "You can now start the application server with `bin/rails server`."
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end
21 changes: 9 additions & 12 deletions bin/spring
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
#!/usr/bin/env ruby
if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"])
gem "bundler"
require "bundler"

# This file loads spring without using Bundler, in order to be fast.
# It gets overwritten when you run the `spring binstub` command.

unless defined?(Spring)
require 'rubygems'
require 'bundler'

lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
spring = lockfile.specs.detect { |spec| spec.name == "spring" }
if spring
# Load Spring without loading other gems in the Gemfile, for speed.
Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring|
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
gem 'spring', spring.version
require 'spring/binstub'
gem "spring", spring.version
require "spring/binstub"
rescue Gem::LoadError
# Ignore when Spring is not installed.
end
end
12 changes: 9 additions & 3 deletions bin/yarn
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/usr/bin/env ruby
APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
begin
exec "yarnpkg", *ARGV
rescue Errno::ENOENT
yarn = ENV["PATH"].split(File::PATH_SEPARATOR).
select { |dir| File.expand_path(dir) != __dir__ }.
product(["yarn", "yarn.cmd", "yarn.ps1"]).
map { |dir, file| File.expand_path(file, dir) }.
find { |file| File.executable?(file) }

if yarn
exec yarn, *ARGV
else
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
Expand Down
3 changes: 2 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is used by Rack-based servers to start the application.

require ::File.expand_path('config/environment', __dir__)
require_relative "config/environment"

run Rails.application
Rails.application.load_server
14 changes: 7 additions & 7 deletions config/application.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path('boot', __dir__)
require_relative "boot"

require 'rails/all'
require "rails/all"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Expand All @@ -10,11 +10,13 @@

module TPS
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.0

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
# in config/environments, which are processed later.

Rails.autoloaders.main.ignore(Rails.root.join('lib/cops'))
Rails.autoloaders.main.ignore(Rails.root.join('lib/linters'))
Expand All @@ -36,8 +38,6 @@ class Application < Rails::Application
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
config.assets.precompile += ['.woff']

config.active_job.queue_adapter = :delayed_job

# The default list used to be accessible through `ActionView::Base.sanitized_allowed_tags`,
# but a regression in Rails 6.0 makes it unavailable.
# It should be fixed in Rails 6.1.
Expand Down
14 changes: 7 additions & 7 deletions config/cable.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
production:
adapter: redis
url: redis://localhost:6379

development:
adapter: redis
url: redis://localhost:6379
adapter: async

test:
adapter: async
adapter: test

production:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: tps_production
2 changes: 1 addition & 1 deletion config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Load the Rails application.
require_relative 'application'
require_relative "application"

# Initialize the Rails application.
Rails.application.initialize!
44 changes: 38 additions & 6 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,56 @@
require "active_support/core_ext/integer/time"

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# Verifies that versions and hashed value of the package contents in the project's package.json
config.webpacker.check_yarn_integrity = true

# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# In the development environment your application's code is reloaded any time
# it changes. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false

# Do not eager load code on boot.
config.eager_load = false

# Show full error reports.
config.consider_all_requests_local = true

# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join('tmp', 'caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true

config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{2.days.to_i}"
}
else
config.action_controller.perform_caching = false

config.cache_store = :null_store
end

config.public_file_server.enabled = true
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = ENV['FOG_ENABLED'] == 'enabled' ? :openstack : :local

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

# Raise exceptions for disallowed deprecations.
config.active_support.disallowed_deprecation = :raise

# Tell Active Support which deprecation messages to disallow.
config.active_support.disallowed_deprecation_warnings = []

# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load

Expand Down Expand Up @@ -83,12 +107,20 @@
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true

# We use the async adapter by default, but delayed_job can be set using
# RAILS_QUEUE_ADAPTER=delayed_job bin/rails server
config.active_job.queue_adapter = ENV.fetch('RAILS_QUEUE_ADAPTER', 'async').to_sym

# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true

if ENV['IGN_CARTE_REFERER']
config.hosts << ENV['IGN_CARTE_REFERER']
end
Expand Down
69 changes: 57 additions & 12 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "active_support/core_ext/integer/time"

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

Expand All @@ -17,33 +19,36 @@
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like
# NGINX, varnish or squid.
# config.action_dispatch.rack_cache = true
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
# config.require_master_key = true

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

# Compress JavaScripts and CSS.
# config.assets.js_compressor = :uglifier
# Compress CSS using a preprocessor.
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.asset_host = 'http://assets.example.com'

# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true

# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

# Mount Action Cable outside main process or domain.
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true

Expand All @@ -58,10 +63,13 @@
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

# Use a different cache store in production.
# config.cache_store = :memory_store
# config.cache_store = :mem_cache_store

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Use a real queuing backend for Active Job (and separate queues per environment).
config.active_job.queue_adapter = :delayed_job
# config.active_job.queue_name_prefix = "tps_production"

config.action_mailer.perform_caching = false

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
Expand Down Expand Up @@ -108,12 +116,49 @@
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify

# Log disallowed deprecations.
config.active_support.disallowed_deprecation = :log

# Tell Active Support which deprecation messages to disallow.
config.active_support.disallowed_deprecation_warnings = []

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new

# Use a different logger for distributed setups.
# require "syslog/logger"
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

# Inserts middleware to perform automatic connection switching.
# The `database_selector` hash is used to pass options to the DatabaseSelector
# middleware. The `delay` is used to determine how long to wait after a write
# to send a subsequent read to the primary.
#
# The `database_resolver` class is used by the middleware to determine which
# database is appropriate to use based on the time delay.
#
# The `database_resolver_context` class is used by the middleware to set
# timestamps for the last write to the primary. The resolver uses the context
# class timestamps to determine how long to wait before reading from the
# replica.
#
# By default Rails will store a last write timestamp in the session. The
# DatabaseSelector middleware is designed as such you can define your own
# strategy for connection switching and pass that into the middleware through
# these configuration options.
# config.active_record.database_selector = { delay: 2.seconds }
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
# config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session

Rails.application.routes.default_url_options = {
protocol: :https,
host: ENV['APP_HOST']
Expand Down
Loading

0 comments on commit 5990439

Please sign in to comment.