Commit bca4cc4
Changed files (31)
app
assets
config
channels
application_cable
jobs
models
config
app/assets/config/manifest.js
@@ -0,0 +1,3 @@
+//= link_tree ../images
+//= link_directory ../javascripts .js
+//= link_directory ../stylesheets .css
app/assets/javascripts/channels/.keep
app/assets/javascripts/cable.js
@@ -0,0 +1,13 @@
+// Action Cable provides the framework to deal with WebSockets in Rails.
+// You can generate new channels where WebSocket features live using the rails generate channel command.
+//
+//= require action_cable
+//= require_self
+//= require_tree ./channels
+
+(function() {
+ this.App || (this.App = {});
+
+ App.cable = ActionCable.createConsumer();
+
+}).call(this);
app/channels/application_cable/channel.rb
@@ -0,0 +1,4 @@
+module ApplicationCable
+ class Channel < ActionCable::Channel::Base
+ end
+end
app/channels/application_cable/connection.rb
@@ -0,0 +1,4 @@
+module ApplicationCable
+ class Connection < ActionCable::Connection::Base
+ end
+end
app/jobs/application_job.rb
@@ -0,0 +1,2 @@
+class ApplicationJob < ActiveJob::Base
+end
app/models/application_record.rb
@@ -0,0 +1,3 @@
+class ApplicationRecord < ActiveRecord::Base
+ self.abstract_class = true
+end
bin/rails
@@ -1,9 +1,4 @@
#!/usr/bin/env ruby
-begin
- load File.expand_path("../spring", __FILE__)
-rescue LoadError => e
- raise unless e.message.include?("spring")
-end
-APP_PATH = File.expand_path("../../config/application", __FILE__)
-require_relative "../config/boot"
-require "rails/commands"
+APP_PATH = File.expand_path('../config/application', __dir__)
+require_relative '../config/boot'
+require 'rails/commands'
bin/rake
@@ -1,9 +1,4 @@
#!/usr/bin/env ruby
-begin
- load File.expand_path('../spring', __FILE__)
-rescue LoadError => e
- raise unless e.message.include?('spring')
-end
require_relative '../config/boot'
require 'rake'
Rake.application.run
bin/setup
@@ -1,28 +1,34 @@
#!/usr/bin/env ruby
require 'pathname'
+require 'fileutils'
+include FileUtils
# path to your application root.
-APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
-Dir.chdir APP_ROOT do
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
# This script is a starting point to setup your application.
- # Add necessary setup steps to this file:
- puts "\n== Copying sample files =="
- unless File.exist?("config/database.yml")
- system "cp config/database.yml.example config/database.yml"
- end
+ # Add necessary setup steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
- puts "== Installing dependencies =="
- system "gem install bundler --conservative"
- system "bundle check || bundle install"
+ # puts "\n== Copying sample files =="
+ # unless File.exist?('config/database.yml')
+ # cp 'config/database.yml.sample', 'config/database.yml'
+ # end
puts "\n== Preparing database =="
- system "bin/rake db:setup"
+ system! 'bin/rails db:setup'
puts "\n== Removing old logs and tempfiles =="
- system "rm -f log/*"
- system "rm -rf tmp/cache"
+ system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
- system "touch tmp/restart.txt"
+ system! 'bin/rails restart'
end
bin/update
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+require 'pathname'
+require 'fileutils'
+include FileUtils
+
+# path to your application root.
+APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
+ # This script is a way to update your development environment automatically.
+ # Add necessary update steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ puts "\n== Updating database =="
+ system! 'bin/rails db:migrate'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
config/environments/development.rb
@@ -9,14 +9,29 @@ Rails.application.configure do
# Do not eager load code on boot.
config.eager_load = false
- # Show full error reports and disable caching.
- config.consider_all_requests_local = true
- config.action_controller.perform_caching = false
+ # Show full error reports.
+ config.consider_all_requests_local = true
+
+ # Enable/disable caching. By default caching is disabled.
+ if Rails.root.join('tmp/caching-dev.txt').exist?
+ config.action_controller.perform_caching = true
+
+ config.cache_store = :memory_store
+ config.public_file_server.headers = {
+ 'Cache-Control' => 'public, max-age=172800'
+ }
+ else
+ config.action_controller.perform_caching = false
+
+ config.cache_store = :null_store
+ end
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews"
+ config.action_mailer.perform_caching = false
+
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
@@ -26,30 +41,18 @@ Rails.application.configure do
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
- config.assets.debug = false
- config.assets.compress = false
-
- # 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.debug = true
- # Adds additional error checking when serving assets at runtime.
- # Checks for improperly declared sprockets dependencies.
- # Raises helpful error messages.
- config.assets.raise_runtime_errors = true
+ # Suppress logger output for asset requests.
+ config.assets.quiet = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
- config.action_mailer.delivery_method = :smtp
- config.action_mailer.smtp_settings = {
- address: ENV["SMTP_HOST"],
- port: ENV["SMTP_PORT"],
- domain: ENV["SMTP_DOMAIN"],
- user_name: ENV["SMTP_USERNAME"],
- password: ENV["SMTP_PASSWORD"],
- authentication: :login,
- enable_starttls_auto: true
- }
+
+ # 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
+
config.after_initialize do
Bullet.enable = true
Bullet.console = true
config/environments/production.rb
@@ -14,15 +14,9 @@ Rails.application.configure do
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
-
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
- config.serve_static_files = ENV["RAILS_SERVE_STATIC_FILES"].present?
+ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
@@ -31,15 +25,19 @@ Rails.application.configure do
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
- # 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
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+ config.action_controller.asset_host = ENV["ASSET_HOST"]
+
# 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
+ # 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
@@ -49,33 +47,19 @@ Rails.application.configure do
config.log_level = :warn
# Prepend all log lines with the following tags.
- # config.log_tags = [ :subdomain, :uuid ]
-
- # Use a different logger for distributed setups.
- # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
+ config.log_tags = [ :request_id ]
# Use a different cache store in production.
config.cache_store = :mem_cache_store
- # Enable serving of images, stylesheets, and JavaScripts from an asset server.
- config.action_controller.asset_host = ENV["ASSET_HOST"]
+ # Use a real queuing backend for Active Job (and separate queues per environment)
+ # config.active_job.queue_adapter = :resque
+ # config.active_job.queue_name_prefix = "stronglifters_#{Rails.env}"
+ 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.
# config.action_mailer.raise_delivery_errors = false
- config.action_mailer.default_options = {
- from: ENV["DEFAULT_FROM_ADDRESS"]
- }
- config.action_mailer.delivery_method = :smtp
- config.action_mailer.smtp_settings = {
- address: ENV["SMTP_HOST"],
- port: ENV["SMTP_PORT"],
- domain: ENV["SMTP_DOMAIN"],
- user_name: ENV["SMTP_USERNAME"],
- password: ENV["SMTP_PASSWORD"],
- authentication: :login,
- enable_starttls_auto: true
- }
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
@@ -87,6 +71,30 @@ Rails.application.configure do
# 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
+
+ config.action_mailer.default_options = {
+ from: ENV["DEFAULT_FROM_ADDRESS"]
+ }
+ config.action_mailer.delivery_method = :smtp
+ config.action_mailer.smtp_settings = {
+ address: ENV["SMTP_HOST"],
+ port: ENV["SMTP_PORT"],
+ domain: ENV["SMTP_DOMAIN"],
+ user_name: ENV["SMTP_USERNAME"],
+ password: ENV["SMTP_PASSWORD"],
+ authentication: :login,
+ enable_starttls_auto: true
+ }
end
config/environments/test.rb
@@ -12,43 +12,40 @@ Rails.application.configure do
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
- # Configure static file server for tests with Cache-Control for performance.
- config.serve_static_files = true
- config.static_cache_control = 'public, max-age=3600'
+ # Configure public file server for tests with Cache-Control for performance.
+ 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
- config.action_mailer.default_options = { from: "from@example.com" }
-
# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
+ config.action_mailer.perform_caching = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
- # Randomize the order test cases are executed.
- config.active_support.test_order = :random
-
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
- # Access to rack session
+ config.action_mailer.default_options = { from: "from@example.com" }
config.middleware.use RackSessionAccess::Middleware
-
- config.after_initialize do
+ config.after_intialize do
Bullet.enable = true
Bullet.bullet_logger = true
- Bullet.raise = true # raise an error if n+1 query occurs
+ Bullet.raise = true
end
config.log_level = :fatal
end
config/initializers/application_controller_renderer.rb
@@ -0,0 +1,6 @@
+# Be sure to restart your server when you modify this file.
+
+# ApplicationController.renderer.defaults.merge!(
+# http_host: 'example.org',
+# https: false
+# )
config/initializers/new_framework_defaults.rb
@@ -0,0 +1,24 @@
+# Be sure to restart your server when you modify this file.
+#
+# This file contains migration options to ease your Rails 5.0 upgrade.
+#
+# Read the Rails 5.0 release notes for more info on each option.
+
+# Enable per-form CSRF tokens. Previous versions had false.
+Rails.application.config.action_controller.per_form_csrf_tokens = true
+
+# Enable origin-checking CSRF mitigation. Previous versions had false.
+Rails.application.config.action_controller.forgery_protection_origin_check = true
+
+# Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`.
+# Previous versions had false.
+ActiveSupport.to_time_preserves_timezone = true
+
+# Require `belongs_to` associations by default. Previous versions had false.
+Rails.application.config.active_record.belongs_to_required_by_default = true
+
+# Do not halt callback chains when a callback returns false. Previous versions had true.
+ActiveSupport.halt_callback_chains_on_return_false = false
+
+# Configure SSL options to enable HSTS with subdomains. Previous versions had false.
+Rails.application.config.ssl_options = { hsts: { subdomains: true } }
config/initializers/wrap_parameters.rb
@@ -5,10 +5,10 @@
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
- wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
+ wrap_parameters format: [:json]
end
# To enable root element in JSON for ActiveRecord objects.
# ActiveSupport.on_load(:active_record) do
-# self.include_root_in_json = true
+# self.include_root_in_json = true
# end
config/application.rb
@@ -1,5 +1,6 @@
-require File.expand_path('../boot', __FILE__)
+require_relative "boot"
+require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
@@ -7,6 +8,7 @@ require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
+require "action_cable/engine"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
@@ -20,14 +22,6 @@ module Stronglifters
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
- # config.time_zone = 'Central Time (US & Canada)'
-
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
- # config.i18n.default_locale = :de
-
# Override field_with_errors div insertion that breaks field formatting
config.action_view.field_error_proc = Proc.new { |html_tag, _instance|
html_tag
config/boot.rb
@@ -1,3 +1,3 @@
-ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' # Set up gems listed in the Gemfile.
config/cable.yml
@@ -0,0 +1,9 @@
+development:
+ adapter: async
+
+test:
+ adapter: async
+
+production:
+ adapter: redis
+ url: redis://localhost:6379/1
config/environment.rb
@@ -1,5 +1,5 @@
# Load the Rails application.
-require File.expand_path('../application', __FILE__)
+require_relative 'application'
# Initialize the Rails application.
Rails.application.initialize!
config/puma.rb
@@ -1,15 +1,47 @@
-workers Integer(ENV['WEB_CONCURRENCY'] || 2)
-threads_count = Integer(ENV['MAX_THREADS'] || 5)
+# Puma can serve each request in a thread from an internal thread pool.
+# The `threads` method setting takes two numbers a minimum and maximum.
+# 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
+# and maximum, this matches the default thread size of Active Record.
+#
+threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count
-preload_app!
+# Specifies the `port` that Puma will listen on to receive requests, default is 3000.
+#
+port ENV.fetch("PORT") { 3000 }
+
+# Specifies the `environment` that Puma will run in.
+#
+environment ENV.fetch("RAILS_ENV") { "development" }
-rackup DefaultRackup
-port ENV['PORT'] || 3000
-environment ENV['RACK_ENV'] || 'development'
+# Specifies the number of `workers` to boot in clustered mode.
+# Workers are forked webserver processes. If using threads and workers together
+# the concurrency of the application would be max `threads` * `workers`.
+# Workers do not work on JRuby or Windows (both of which do not support
+# processes).
+#
+workers ENV.fetch("WEB_CONCURRENCY") { 2 }
+# Use the `preload_app!` method when specifying a `workers` number.
+# This directive tells Puma to first boot the application and load code
+# before forking the application. This takes advantage of Copy On Write
+# process behavior so workers use less memory. If you use this option
+# you need to make sure to reconnect any threads in the `on_worker_boot`
+# block.
+#
+preload_app!
+
+# The code in the `on_worker_boot` will be called if you are using
+# clustered mode by specifying a number of `workers`. After each worker
+# process is booted this block will be run, if you are using `preload_app!`
+# option you will want to use this block to reconnect to any threads
+# or connections that may have been created at application boot, Ruby
+# cannot share connections between processes.
+#
on_worker_boot do
- # Worker specific setup for Rails 4.1+
- # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
- ActiveRecord::Base.establish_connection
+ ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end
+
+# Allow puma to be restarted by `rails restart` command.
+plugin :tmp_restart
config/secrets.yml
@@ -5,7 +5,7 @@
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
-# You can use `rake secret` to generate a secure secret key.
+# You can use `rails secret` to generate a secure secret key.
# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.
config/spring.rb
@@ -0,0 +1,6 @@
+%w(
+ .ruby-version
+ .rbenv-vars
+ tmp/restart.txt
+ tmp/caching-dev.txt
+).each { |path| Spring.watch(path) }
public/apple-touch-icon-precomposed.png
public/apple-touch-icon.png
.gitignore
@@ -22,3 +22,6 @@ pkg
public/assets
erd.pdf
db/data
+
+# Ignore Byebug command history file.
+.byebug_history
config.ru
@@ -1,4 +1,5 @@
# This file is used by Rack-based servers to start the application.
-require ::File.expand_path('../config/environment', __FILE__)
+require_relative 'config/environment'
+
run Rails.application
Gemfile
@@ -2,7 +2,7 @@ source "https://rubygems.org" do
gem "bcrypt", "~> 3.1.7"
gem "brakeman", group: :development, require: false
gem "bullet", group: [:development, :test]
- gem "byebug", group: [:development, :test]
+ gem "byebug", group: [:development, :test], platform: :mri
gem "capistrano", "3.4.1"
gem "capistrano-bundler", "~> 1.1", require: false, group: :development
gem "capistrano-rails", group: :development
@@ -10,7 +10,7 @@ source "https://rubygems.org" do
gem "carmen"
gem "chartkick"
gem "codeclimate-test-reporter", require: nil, group: :test
- gem "coffee-rails", "~> 4.1"
+ gem "coffee-rails", "~> 4.2"
gem "coveralls", require: false, group: :test
gem "cucumber-rails", require: false, group: :test
gem "dalli"
@@ -32,40 +32,43 @@ source "https://rubygems.org" do
gem "groupdate"
gem "http_accept_language"
gem "i18n-tasks", group: :development
- gem "jbuilder", "~> 2.0"
+ gem "jbuilder", "~> 2.5"
gem "jquery-rails"
gem "jquery-turbolinks"
+ gem "listen", "~> 3.0.5"
gem "kaminari"
gem "meta_request", group: :development
gem "pg"
gem "poltergeist", group: :test
- gem "puma"
+ gem "puma", '~> 3.0'
gem "rack-mini-profiler", group: :development
gem "rack-timeout"
gem "rack_session_access", group: :test
gem "ractive-rails"
- gem "rails", "~> 4.2"
+ gem "rails", "~> 5.0.0"
gem "rails-erd", group: :development
gem "rails-i18n", "~> 4.0.0"
gem "rails_12factor", group: :production
+ gem "redis", "~> 3.0"
gem "rspec-rails", group: :test
gem "rubyzip", require: "zip"
gem "sass-rails", "~> 5.0"
gem "scale"
gem "sdoc", "~> 0.4", group: :doc
gem "sidekiq"
- gem "spring", group: [:development, :test]
+ gem "spring", group: [:development]
gem "spring-commands-cucumber", group: :test
gem "spring-commands-rspec", group: :test
gem "spring-commands-teaspoon", group: :test
+ gem "spring-watcher-listen", "~> 2.0.0"
gem "sprockets-rails", "2.3.3"
gem "stackprof", group: :development
gem "teaspoon-jasmine", group: :test
gem "therubyracer", platforms: :ruby
- gem "turbolinks"
+ gem "turbolinks", '~> 5'
gem "uglifier", ">= 1.3.0"
gem "vcr", group: :test
- gem "web-console", "~> 2.0", group: :development
+ gem "web-console", group: :development
gem "webmock", group: :test
gem "yelp"
end
Rakefile
@@ -1,7 +1,7 @@
# 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.
-require File.expand_path('../config/application', __FILE__)
+require_relative 'config/application'
Rails.application.load_tasks