├── log └── .keep ├── storage └── .keep ├── tmp ├── .keep ├── pids │ └── .keep └── storage │ └── .keep ├── vendor └── .keep ├── lib └── tasks │ └── .keep ├── app ├── models │ ├── concerns │ │ └── .keep │ ├── user.rb │ └── application_record.rb ├── controllers │ ├── concerns │ │ └── .keep │ ├── application_controller.rb │ └── users_controller.rb ├── views │ └── layouts │ │ ├── mailer.text.erb │ │ └── mailer.html.erb ├── mailers │ └── application_mailer.rb ├── lib │ ├── mailer.rb │ └── stripe.rb └── jobs │ └── application_job.rb ├── bin ├── rake ├── rails ├── docker-entrypoint ├── setup └── bundle ├── public └── robots.txt ├── config ├── environment.rb ├── boot.rb ├── initializers │ ├── filter_parameter_logging.rb │ ├── cors.rb │ └── inflections.rb ├── credentials.yml.enc ├── routes.rb ├── database.yml ├── locales │ └── en.yml ├── application.rb ├── puma.rb └── environments │ ├── development.rb │ ├── test.rb │ └── production.rb ├── config.ru ├── Rakefile ├── db ├── migrate │ └── 20230710142440_create_users.rb ├── seeds.rb └── schema.rb ├── .gitattributes ├── README.md ├── .dockerignore ├── .gitignore ├── Gemfile ├── Dockerfile └── Gemfile.lock /log/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /storage/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/pids/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/storage/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User < ApplicationRecord 2 | has_secure_password 3 | end 4 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::API 2 | end 3 | -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | primary_abstract_class 3 | end 4 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: "from@example.com" 3 | layout "mailer" 4 | end 5 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path("../config/application", __dir__) 3 | require_relative "../config/boot" 4 | require "rails/commands" 5 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative "config/environment" 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /bin/docker-entrypoint: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # If running the rails server then create or migrate existing database 4 | if [ "${*}" == "./bin/rails server" ]; then 5 | ./bin/rails db:prepare 6 | fi 7 | 8 | exec "${@}" 9 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) 2 | 3 | require "bundler/setup" # Set up gems listed in the Gemfile. 4 | require "bootsnap/setup" # Speed up boot time by caching expensive operations. 5 | -------------------------------------------------------------------------------- /app/lib/mailer.rb: -------------------------------------------------------------------------------- 1 | # This is a mock of a mail service API library. 2 | # Do not modify this file, just assume it comes from a gem. 3 | module MailerAPI 4 | def self.send_welcome_email(user) 5 | # calls mailer API 6 | # ... 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative "config/application" 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /db/migrate/20230710142440_create_users.rb: -------------------------------------------------------------------------------- 1 | class CreateUsers < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :users do |t| 4 | t.string :username 5 | t.string :email 6 | t.string :password_digest 7 | 8 | t.timestamps 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | # Automatically retry jobs that encountered a deadlock 3 | # retry_on ActiveRecord::Deadlocked 4 | 5 | # Most jobs are safe to ignore if the underlying records are no longer available 6 | # discard_on ActiveJob::DeserializationError 7 | end 8 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/controllers/users_controller.rb: -------------------------------------------------------------------------------- 1 | class UsersController < ApplicationController 2 | def index 3 | users = User.all 4 | render json: {users:} 5 | end 6 | 7 | def show 8 | user = User.find(params[:id]) 9 | render json: {user:} 10 | end 11 | 12 | def create 13 | # TODO: create registration action 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # See https://git-scm.com/docs/gitattributes for more about git attribute files. 2 | 3 | # Mark the database schema as having been generated. 4 | db/schema.rb linguist-generated 5 | 6 | # Mark any vendored files as having been vendored. 7 | vendor/* linguist-vendored 8 | config/credentials/*.yml.enc diff=rails_credentials 9 | config/credentials.yml.enc diff=rails_credentials 10 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure parameters to be filtered from the log file. Use this to limit dissemination of 4 | # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported 5 | # notations and behaviors. 6 | Rails.application.config.filter_parameters += [ 7 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn 8 | ] 9 | -------------------------------------------------------------------------------- /config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | Jbei1jBK2iTMlEzDDffi8MWVSW3TNOf8dSdnIZhi8w3Z3Rq7RJrzgK6yGUE/luQbU4Wb9pjGWwQ+7FYoH9gRs1d5Dib0WIM/+vRvcL0hW+uhHp/u6Y2vJdEjiPsAvHL3h3YmShx+XPFYTwLCcithZjoX0CYVDWlxvfpuigRLuoruXFuw8nUsRuNi/ia+pZatrS3tFKGtbRb9ehsH96TGnMCbQi4sfvcYP0SKLLmnz0PfvcVOQQY0TDgrNT6pdHBSUmLIZTLHC7s/sxTNevZOB9cCbNEE7hswOtAerx2cDixuO5SEQGPhXCJzrgpZo1swxeCFb9Z9GhfM5pPmN0l3HBCwwsm83pr4IkBwfdZJSC0BIcNJrSuPydL9g2Ae02sViX/VNutlSly/+sVDTQFT48acgx2Z--whE8U97luY49qTWT--B+2lEA+g7Mv5tXulRIDOpA== -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html 3 | 4 | # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. 5 | # Can be used by load balancers and uptime monitors to verify that the app is live. 6 | get "up" => "rails/health#show", as: :rails_health_check 7 | 8 | resources :users, only: [:index, :show, :create] 9 | end 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This README would normally document whatever steps are necessary to get the 4 | application up and running. 5 | 6 | Things you may want to cover: 7 | 8 | * Ruby version 9 | 10 | * System dependencies 11 | 12 | * Configuration 13 | 14 | * Database creation 15 | 16 | * Database initialization 17 | 18 | * How to run the test suite 19 | 20 | * Services (job queues, cache servers, search engines, etc.) 21 | 22 | * Deployment instructions 23 | 24 | * ... 25 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should ensure the existence of records required to run the application in every environment (production, 2 | # development, test). The code here should be idempotent so that it can be executed at any point in every environment. 3 | # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). 4 | # 5 | # Example: 6 | # 7 | # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| 8 | # MovieGenre.find_or_create_by!(name: genre_name) 9 | # end 10 | -------------------------------------------------------------------------------- /config/initializers/cors.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Avoid CORS issues when API is called from the frontend app. 4 | # Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin Ajax requests. 5 | 6 | # Read more: https://github.com/cyu/rack-cors 7 | 8 | # Rails.application.config.middleware.insert_before 0, Rack::Cors do 9 | # allow do 10 | # origins "example.com" 11 | # 12 | # resource "*", 13 | # headers: :any, 14 | # methods: [:get, :post, :put, :patch, :delete, :options, :head] 15 | # end 16 | # end 17 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, "\\1en" 8 | # inflect.singular /^(ox)en/i, "\\1" 9 | # inflect.irregular "person", "people" 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym "RESTful" 16 | # end 17 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite. Versions 3.8.0 and up are supported. 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem "sqlite3" 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: storage/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: storage/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: storage/production.sqlite3 26 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | # See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files. 2 | 3 | # Ignore git directory. 4 | /.git/ 5 | 6 | # Ignore bundler config. 7 | /.bundle 8 | 9 | # Ignore all default key files. 10 | /config/master.key 11 | /config/credentials/*.key 12 | 13 | # Ignore all environment files. 14 | /.env* 15 | !/.env.example 16 | 17 | # Ignore all logfiles and tempfiles. 18 | /log/* 19 | /tmp/* 20 | !/log/.keep 21 | !/tmp/.keep 22 | 23 | # Ignore pidfiles, but keep the directory. 24 | /tmp/pids/* 25 | !/tmp/pids/ 26 | !/tmp/pids/.keep 27 | 28 | # Ignore storage (uploaded files in development and any SQLite databases). 29 | /storage/* 30 | !/storage/.keep 31 | /tmp/storage/* 32 | !/tmp/storage/ 33 | !/tmp/storage/.keep 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore all logfiles and tempfiles. 11 | /log/* 12 | /tmp/* 13 | !/log/.keep 14 | !/tmp/.keep 15 | 16 | # Ignore pidfiles, but keep the directory. 17 | /tmp/pids/* 18 | !/tmp/pids/ 19 | !/tmp/pids/.keep 20 | 21 | # Ignore storage (uploaded files in development and any SQLite databases). 22 | /storage/* 23 | !/storage/.keep 24 | /tmp/storage/* 25 | !/tmp/storage/ 26 | !/tmp/storage/.keep 27 | 28 | # Ignore master key for decrypting credentials and more. 29 | /config/master.key 30 | -------------------------------------------------------------------------------- /app/lib/stripe.rb: -------------------------------------------------------------------------------- 1 | # This is a mock of a Stripe API library. 2 | # Do not modify this file, just assume it comes from a gem. 3 | module Stripe 4 | class Error < StandardError; end 5 | 6 | def self.create_customer_with_card(email:, number:, cve:, exp_month:, exp_year:, name:) 7 | # calls Stripe API... 8 | 9 | # Bad card raises an error 10 | if number == "4000000000000002" 11 | raise Stripe::Error.new("Your card has been declined.") 12 | end 13 | 14 | { 15 | id: "card_#{SecureRandom.hex(8)}", 16 | exp_month:, 17 | exp_year:, 18 | last4: number[-4..], 19 | fingerprint: Digest::MD5.hexdigest("#{number}#{exp_month}#{exp_year}"), 20 | cvc_check: "pass", 21 | # other attributes... 22 | customer: { 23 | id: "cus_#{SecureRandom.hex(8)}", 24 | email:, 25 | # other attributes... 26 | }, 27 | } 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization and 2 | # are automatically loaded by Rails. If you want to use locales other than 3 | # English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t "hello" 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t("hello") %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more about the API, please read the Rails Internationalization guide 20 | # at https://guides.rubyonrails.org/i18n.html. 21 | # 22 | # Be aware that YAML interprets the following case-insensitive strings as 23 | # booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings 24 | # must be quoted to be interpreted as strings. For example: 25 | # 26 | # en: 27 | # "yes": yup 28 | # enabled: "ON" 29 | 30 | en: 31 | hello: "Hello world" 32 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # This file is the source Rails uses to define your schema when running `bin/rails 6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to 7 | # be faster and is potentially less error prone than running all of your 8 | # migrations from scratch. Old migrations may fail to apply correctly if those 9 | # migrations use external dependencies or application code. 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema[7.0].define(version: 2023_07_10_142440) do 14 | create_table "users", force: :cascade do |t| 15 | t.string "username" 16 | t.string "email" 17 | t.string "password_digest" 18 | t.datetime "created_at", null: false 19 | t.datetime "updated_at", null: false 20 | end 21 | 22 | end 23 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "fileutils" 3 | 4 | # path to your application root. 5 | APP_ROOT = File.expand_path("..", __dir__) 6 | 7 | def system!(*args) 8 | system(*args, exception: true) 9 | end 10 | 11 | FileUtils.chdir APP_ROOT do 12 | # This script is a way to set up or update your development environment automatically. 13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome. 14 | # Add necessary setup steps to this file. 15 | 16 | puts "== Installing dependencies ==" 17 | system! "gem install bundler --conservative" 18 | system("bundle check") || system!("bundle install") 19 | 20 | # puts "\n== Copying sample files ==" 21 | # unless File.exist?("config/database.yml") 22 | # FileUtils.cp "config/database.yml.sample", "config/database.yml" 23 | # end 24 | 25 | puts "\n== Preparing database ==" 26 | system! "bin/rails db:prepare" 27 | 28 | puts "\n== Removing old logs and tempfiles ==" 29 | system! "bin/rails log:clear tmp:clear" 30 | 31 | puts "\n== Restarting application server ==" 32 | system! "bin/rails restart" 33 | end 34 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | # Use main development branch of Rails 4 | gem "rails", "~> 7.0" 5 | 6 | # Use sqlite3 as the database for Active Record 7 | gem "sqlite3", "~> 1.4" 8 | 9 | # Use the Puma web server [https://github.com/puma/puma] 10 | gem "puma", ">= 5.0" 11 | 12 | # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] 13 | gem "bcrypt", "~> 3.1.7" 14 | 15 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 16 | gem "tzinfo-data", platforms: %i[ mswin mswin64 mingw x64_mingw jruby ] 17 | 18 | # Reduces boot times through caching; required in config/boot.rb 19 | gem "bootsnap", require: false 20 | 21 | # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin Ajax possible 22 | # gem "rack-cors" 23 | 24 | group :development, :test do 25 | # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem 26 | gem "debug", platforms: %i[ mri mswin mswin64 mingw x64_mingw ] 27 | # Test framework 28 | gem "rspec-rails", "~> 6.0.0" 29 | end 30 | 31 | group :development do 32 | # Speed up commands on slow machines / big apps [https://github.com/rails/spring] 33 | # gem "spring" 34 | 35 | gem "error_highlight", ">= 0.4.0", platforms: [:ruby] 36 | end 37 | 38 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative "boot" 2 | 3 | require "rails" 4 | # Pick the frameworks you want: 5 | require "active_model/railtie" 6 | require "active_job/railtie" 7 | require "active_record/railtie" 8 | # require "active_storage/engine" 9 | require "action_controller/railtie" 10 | require "action_mailer/railtie" 11 | # require "action_mailbox/engine" 12 | # require "action_text/engine" 13 | require "action_view/railtie" 14 | # require "action_cable/engine" 15 | # require "rails/test_unit/railtie" 16 | 17 | # Require the gems listed in Gemfile, including any gems 18 | # you've limited to :test, :development, or :production. 19 | Bundler.require(*Rails.groups) 20 | 21 | module LivecodingBootstrap 22 | class Application < Rails::Application 23 | # Initialize configuration defaults for originally generated Rails version. 24 | config.load_defaults 7.0 25 | 26 | # Configuration for the application, engines, and railties goes here. 27 | # 28 | # These settings can be overridden in specific environments using the files 29 | # in config/environments, which are processed later. 30 | # 31 | # config.time_zone = "Central Time (US & Canada)" 32 | # config.eager_load_paths << Rails.root.join("extras") 33 | 34 | # Only loads a smaller set of middleware suitable for API only apps. 35 | # Middleware like session, flash, cookies can be added back manually. 36 | # Skip views, helpers and assets when generating a new resource. 37 | config.api_only = true 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /config/puma.rb: -------------------------------------------------------------------------------- 1 | # This configuration file will be evaluated by Puma. The top-level methods that 2 | # are invoked here are part of Puma's configuration DSL. For more information 3 | # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. 4 | 5 | # Puma can serve each request in a thread from an internal thread pool. 6 | # The `threads` method setting takes two numbers: a minimum and maximum. 7 | # Any libraries that use thread pools should be configured to match 8 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 9 | # and maximum; this matches the default thread size of Active Record. 10 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 11 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 12 | threads min_threads_count, max_threads_count 13 | 14 | # Specifies that the worker count should equal the number of processors in production. 15 | if ENV["RAILS_ENV"] == "production" 16 | worker_count = Integer(ENV.fetch("WEB_CONCURRENCY") { Concurrent.physical_processor_count }) 17 | workers worker_count if worker_count > 1 18 | end 19 | 20 | # Specifies the `worker_timeout` threshold that Puma will use to wait before 21 | # terminating a worker in development environments. 22 | worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" 23 | 24 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 25 | port ENV.fetch("PORT") { 3000 } 26 | 27 | # Specifies the `environment` that Puma will run in. 28 | environment ENV.fetch("RAILS_ENV") { "development" } 29 | 30 | # Specifies the `pidfile` that Puma will use. 31 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 32 | 33 | # Allow puma to be restarted by `bin/rails restart` command. 34 | plugin :tmp_restart 35 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax = docker/dockerfile:1 2 | 3 | # Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile 4 | ARG RUBY_VERSION=3.1.2 5 | FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base 6 | 7 | # Rails app lives here 8 | WORKDIR /rails 9 | 10 | # Set production environment 11 | ENV RAILS_ENV="production" \ 12 | BUNDLE_DEPLOYMENT="1" \ 13 | BUNDLE_PATH="/usr/local/bundle" \ 14 | BUNDLE_WITHOUT="development" 15 | 16 | 17 | # Throw-away build stage to reduce size of final image 18 | FROM base as build 19 | 20 | # Install packages needed to build gems 21 | RUN apt-get update -qq && \ 22 | apt-get install --no-install-recommends -y build-essential git pkg-config 23 | 24 | # Install application gems 25 | COPY Gemfile Gemfile.lock ./ 26 | RUN bundle install && \ 27 | rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ 28 | bundle exec bootsnap precompile --gemfile 29 | 30 | 31 | # Copy application code 32 | COPY . . 33 | 34 | # Precompile bootsnap code for faster boot times 35 | RUN bundle exec bootsnap precompile app/ lib/ 36 | 37 | 38 | # Final stage for app image 39 | FROM base 40 | 41 | # Install packages needed for deployment 42 | RUN apt-get update -qq && \ 43 | apt-get install --no-install-recommends -y curl libsqlite3-0 && \ 44 | rm -rf /var/lib/apt/lists /var/cache/apt/archives 45 | 46 | # Copy built artifacts: gems, application 47 | COPY --from=build /usr/local/bundle /usr/local/bundle 48 | COPY --from=build /rails /rails 49 | 50 | # Run and own only the runtime files as a non-root user for security 51 | RUN useradd rails --create-home --shell /bin/bash && \ 52 | chown -R rails:rails db log storage tmp 53 | USER rails:rails 54 | 55 | # Entrypoint prepares the database. 56 | ENTRYPOINT ["/rails/bin/docker-entrypoint"] 57 | 58 | # Start the server by default, this can be overwritten at runtime 59 | EXPOSE 3000 60 | CMD ["./bin/rails", "server"] 61 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # In the development environment your application's code is reloaded any time 7 | # it changes. This slows down response time but is perfect for development 8 | # since you don't have to restart the web server when you make code changes. 9 | config.enable_reloading = true 10 | 11 | # Do not eager load code on boot. 12 | config.eager_load = false 13 | 14 | # Show full error reports. 15 | config.consider_all_requests_local = true 16 | 17 | # Enable server timing 18 | config.server_timing = true 19 | 20 | # Enable/disable caching. By default caching is disabled. 21 | # Run rails dev:cache to toggle caching. 22 | if Rails.root.join("tmp/caching-dev.txt").exist? 23 | config.cache_store = :memory_store 24 | config.public_file_server.headers = { 25 | "Cache-Control" => "public, max-age=#{2.days.to_i}" 26 | } 27 | else 28 | config.action_controller.perform_caching = false 29 | 30 | config.cache_store = :null_store 31 | end 32 | 33 | # Don't care if the mailer can't send. 34 | config.action_mailer.raise_delivery_errors = false 35 | 36 | config.action_mailer.perform_caching = false 37 | 38 | # Print deprecation notices to the Rails logger. 39 | config.active_support.deprecation = :log 40 | 41 | # Raise exceptions for disallowed deprecations. 42 | config.active_support.disallowed_deprecation = :raise 43 | 44 | # Tell Active Support which deprecation messages to disallow. 45 | config.active_support.disallowed_deprecation_warnings = [] 46 | 47 | # Raise an error on page load if there are pending migrations. 48 | config.active_record.migration_error = :page_load 49 | 50 | # Highlight code that triggered database queries in logs. 51 | config.active_record.verbose_query_logs = true 52 | 53 | # Highlight code that enqueued background job in logs. 54 | config.active_job.verbose_enqueue_logs = true 55 | 56 | 57 | # Raises error for missing translations. 58 | # config.i18n.raise_on_missing_translations = true 59 | 60 | # Annotate rendered view with file names. 61 | # config.action_view.annotate_rendered_view_with_filenames = true 62 | 63 | # Uncomment if you wish to allow Action Cable access from any origin. 64 | # config.action_cable.disable_request_forgery_protection = true 65 | end 66 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | # The test environment is used exclusively to run your application's 4 | # test suite. You never need to work with it otherwise. Remember that 5 | # your test database is "scratch space" for the test suite and is wiped 6 | # and recreated between test runs. Don't rely on the data there! 7 | 8 | Rails.application.configure do 9 | # Settings specified here will take precedence over those in config/application.rb. 10 | 11 | # While tests run files are not watched, reloading is not necessary. 12 | config.enable_reloading = false 13 | 14 | # Eager loading loads your entire application. When running a single test locally, 15 | # this is usually not necessary, and can slow down your test suite. However, it's 16 | # recommended that you enable it in continuous integration systems to ensure eager 17 | # loading is working properly before deploying your code. 18 | config.eager_load = ENV["CI"].present? 19 | 20 | # Configure public file server for tests with Cache-Control for performance. 21 | config.public_file_server.enabled = true 22 | config.public_file_server.headers = { 23 | "Cache-Control" => "public, max-age=#{1.hour.to_i}" 24 | } 25 | 26 | # Show full error reports and disable caching. 27 | config.consider_all_requests_local = true 28 | config.action_controller.perform_caching = false 29 | config.cache_store = :null_store 30 | 31 | # Raise exceptions instead of rendering exception templates. 32 | config.action_dispatch.show_exceptions = :rescuable 33 | 34 | # Disable request forgery protection in test environment. 35 | config.action_controller.allow_forgery_protection = false 36 | 37 | config.action_mailer.perform_caching = false 38 | 39 | # Tell Action Mailer not to deliver emails to the real world. 40 | # The :test delivery method accumulates sent emails in the 41 | # ActionMailer::Base.deliveries array. 42 | config.action_mailer.delivery_method = :test 43 | 44 | # Print deprecation notices to the stderr. 45 | config.active_support.deprecation = :stderr 46 | 47 | # Raise exceptions for disallowed deprecations. 48 | config.active_support.disallowed_deprecation = :raise 49 | 50 | # Tell Active Support which deprecation messages to disallow. 51 | config.active_support.disallowed_deprecation_warnings = [] 52 | 53 | # Raises error for missing translations. 54 | # config.i18n.raise_on_missing_translations = true 55 | 56 | # Annotate rendered view with file names. 57 | # config.action_view.annotate_rendered_view_with_filenames = true 58 | end 59 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'bundle' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "rubygems" 12 | 13 | m = Module.new do 14 | module_function 15 | 16 | def invoked_as_script? 17 | File.expand_path($0) == File.expand_path(__FILE__) 18 | end 19 | 20 | def env_var_version 21 | ENV["BUNDLER_VERSION"] 22 | end 23 | 24 | def cli_arg_version 25 | return unless invoked_as_script? # don't want to hijack other binstubs 26 | return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` 27 | bundler_version = nil 28 | update_index = nil 29 | ARGV.each_with_index do |a, i| 30 | if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN 31 | bundler_version = a 32 | end 33 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ 34 | bundler_version = $1 35 | update_index = i 36 | end 37 | bundler_version 38 | end 39 | 40 | def gemfile 41 | gemfile = ENV["BUNDLE_GEMFILE"] 42 | return gemfile if gemfile && !gemfile.empty? 43 | 44 | File.expand_path("../Gemfile", __dir__) 45 | end 46 | 47 | def lockfile 48 | lockfile = 49 | case File.basename(gemfile) 50 | when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") 51 | else "#{gemfile}.lock" 52 | end 53 | File.expand_path(lockfile) 54 | end 55 | 56 | def lockfile_version 57 | return unless File.file?(lockfile) 58 | lockfile_contents = File.read(lockfile) 59 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ 60 | Regexp.last_match(1) 61 | end 62 | 63 | def bundler_requirement 64 | @bundler_requirement ||= 65 | env_var_version || 66 | cli_arg_version || 67 | bundler_requirement_for(lockfile_version) 68 | end 69 | 70 | def bundler_requirement_for(version) 71 | return "#{Gem::Requirement.default}.a" unless version 72 | 73 | bundler_gem_version = Gem::Version.new(version) 74 | 75 | bundler_gem_version.approximate_recommendation 76 | end 77 | 78 | def load_bundler! 79 | ENV["BUNDLE_GEMFILE"] ||= gemfile 80 | 81 | activate_bundler 82 | end 83 | 84 | def activate_bundler 85 | gem_error = activation_error_handling do 86 | gem "bundler", bundler_requirement 87 | end 88 | return if gem_error.nil? 89 | require_error = activation_error_handling do 90 | require "bundler/version" 91 | end 92 | return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) 93 | 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}'`" 94 | exit 42 95 | end 96 | 97 | def activation_error_handling 98 | yield 99 | nil 100 | rescue StandardError, LoadError => e 101 | e 102 | end 103 | end 104 | 105 | m.load_bundler! 106 | 107 | if m.invoked_as_script? 108 | load Gem.bin_path("bundler", "bundle") 109 | end 110 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # Code is not reloaded between requests. 7 | config.enable_reloading = false 8 | 9 | # Eager load code on boot. This eager loads most of Rails and 10 | # your application in memory, allowing both threaded web servers 11 | # and those relying on copy on write to perform better. 12 | # Rake tasks automatically ignore this option for performance. 13 | config.eager_load = true 14 | 15 | # Full error reports are disabled and caching is turned on. 16 | config.consider_all_requests_local = false 17 | 18 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] 19 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). 20 | # config.require_master_key = true 21 | 22 | # Enable static file serving from the `/public` folder (turn off if using NGINX/Apache for it). 23 | config.public_file_server.enabled = true 24 | 25 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 26 | # config.asset_host = "http://assets.example.com" 27 | 28 | # Specifies the header that your server uses for sending files. 29 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache 30 | # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX 31 | 32 | # Assume all access to the app is happening through a SSL-terminating reverse proxy. 33 | # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. 34 | # config.assume_ssl = true 35 | 36 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 37 | config.force_ssl = true 38 | 39 | # Log to STDOUT by default 40 | config.logger = ActiveSupport::Logger.new(STDOUT) 41 | .tap { |logger| logger.formatter = ::Logger::Formatter.new } 42 | .then { |logger| ActiveSupport::TaggedLogging.new(logger) } 43 | 44 | # Prepend all log lines with the following tags. 45 | config.log_tags = [ :request_id ] 46 | 47 | # Info include generic and useful information about system operation, but avoids logging too much 48 | # information to avoid inadvertent exposure of personally identifiable information (PII). Use "debug" 49 | # for everything. 50 | config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") 51 | 52 | # Use a different cache store in production. 53 | # config.cache_store = :mem_cache_store 54 | 55 | # Use a real queuing backend for Active Job (and separate queues per environment). 56 | # config.active_job.queue_adapter = :resque 57 | # config.active_job.queue_name_prefix = "livecoding_bootstrap_production" 58 | 59 | config.action_mailer.perform_caching = false 60 | 61 | # Ignore bad email addresses and do not raise email delivery errors. 62 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 63 | # config.action_mailer.raise_delivery_errors = false 64 | 65 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 66 | # the I18n.default_locale when a translation cannot be found). 67 | config.i18n.fallbacks = true 68 | 69 | # Don't log any deprecations. 70 | config.active_support.report_deprecations = false 71 | 72 | # Do not dump schema after migrations. 73 | config.active_record.dump_schema_after_migration = false 74 | 75 | # Enable DNS rebinding protection and other `Host` header attacks. 76 | # config.hosts = [ 77 | # "example.com", # Allow requests from example.com 78 | # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` 79 | # ] 80 | # Skip DNS rebinding protection for the default health check endpoint. 81 | # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } 82 | end 83 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (7.0.6) 5 | actionpack (= 7.0.6) 6 | activesupport (= 7.0.6) 7 | nio4r (~> 2.0) 8 | websocket-driver (>= 0.6.1) 9 | actionmailbox (7.0.6) 10 | actionpack (= 7.0.6) 11 | activejob (= 7.0.6) 12 | activerecord (= 7.0.6) 13 | activestorage (= 7.0.6) 14 | activesupport (= 7.0.6) 15 | mail (>= 2.7.1) 16 | net-imap 17 | net-pop 18 | net-smtp 19 | actionmailer (7.0.6) 20 | actionpack (= 7.0.6) 21 | actionview (= 7.0.6) 22 | activejob (= 7.0.6) 23 | activesupport (= 7.0.6) 24 | mail (~> 2.5, >= 2.5.4) 25 | net-imap 26 | net-pop 27 | net-smtp 28 | rails-dom-testing (~> 2.0) 29 | actionpack (7.0.6) 30 | actionview (= 7.0.6) 31 | activesupport (= 7.0.6) 32 | rack (~> 2.0, >= 2.2.4) 33 | rack-test (>= 0.6.3) 34 | rails-dom-testing (~> 2.0) 35 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 36 | actiontext (7.0.6) 37 | actionpack (= 7.0.6) 38 | activerecord (= 7.0.6) 39 | activestorage (= 7.0.6) 40 | activesupport (= 7.0.6) 41 | globalid (>= 0.6.0) 42 | nokogiri (>= 1.8.5) 43 | actionview (7.0.6) 44 | activesupport (= 7.0.6) 45 | builder (~> 3.1) 46 | erubi (~> 1.4) 47 | rails-dom-testing (~> 2.0) 48 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 49 | activejob (7.0.6) 50 | activesupport (= 7.0.6) 51 | globalid (>= 0.3.6) 52 | activemodel (7.0.6) 53 | activesupport (= 7.0.6) 54 | activerecord (7.0.6) 55 | activemodel (= 7.0.6) 56 | activesupport (= 7.0.6) 57 | activestorage (7.0.6) 58 | actionpack (= 7.0.6) 59 | activejob (= 7.0.6) 60 | activerecord (= 7.0.6) 61 | activesupport (= 7.0.6) 62 | marcel (~> 1.0) 63 | mini_mime (>= 1.1.0) 64 | activesupport (7.0.6) 65 | concurrent-ruby (~> 1.0, >= 1.0.2) 66 | i18n (>= 1.6, < 2) 67 | minitest (>= 5.1) 68 | tzinfo (~> 2.0) 69 | bcrypt (3.1.19) 70 | bootsnap (1.16.0) 71 | msgpack (~> 1.2) 72 | builder (3.2.4) 73 | concurrent-ruby (1.2.2) 74 | crass (1.0.6) 75 | date (3.3.3) 76 | debug (1.8.0) 77 | irb (>= 1.5.0) 78 | reline (>= 0.3.1) 79 | diff-lcs (1.5.0) 80 | error_highlight (0.5.1) 81 | erubi (1.12.0) 82 | globalid (1.1.0) 83 | activesupport (>= 5.0) 84 | i18n (1.14.1) 85 | concurrent-ruby (~> 1.0) 86 | io-console (0.6.0) 87 | irb (1.7.1) 88 | reline (>= 0.3.0) 89 | loofah (2.21.3) 90 | crass (~> 1.0.2) 91 | nokogiri (>= 1.12.0) 92 | mail (2.8.1) 93 | mini_mime (>= 0.1.1) 94 | net-imap 95 | net-pop 96 | net-smtp 97 | marcel (1.0.2) 98 | method_source (1.0.0) 99 | mini_mime (1.1.2) 100 | minitest (5.18.1) 101 | msgpack (1.7.1) 102 | net-imap (0.3.6) 103 | date 104 | net-protocol 105 | net-pop (0.1.2) 106 | net-protocol 107 | net-protocol (0.2.1) 108 | timeout 109 | net-smtp (0.3.3) 110 | net-protocol 111 | nio4r (2.5.9) 112 | nokogiri (1.15.3-x86_64-darwin) 113 | racc (~> 1.4) 114 | nokogiri (1.15.3-x86_64-linux) 115 | racc (~> 1.4) 116 | puma (6.3.0) 117 | nio4r (~> 2.0) 118 | racc (1.7.1) 119 | rack (2.2.7) 120 | rack-test (2.1.0) 121 | rack (>= 1.3) 122 | rails (7.0.6) 123 | actioncable (= 7.0.6) 124 | actionmailbox (= 7.0.6) 125 | actionmailer (= 7.0.6) 126 | actionpack (= 7.0.6) 127 | actiontext (= 7.0.6) 128 | actionview (= 7.0.6) 129 | activejob (= 7.0.6) 130 | activemodel (= 7.0.6) 131 | activerecord (= 7.0.6) 132 | activestorage (= 7.0.6) 133 | activesupport (= 7.0.6) 134 | bundler (>= 1.15.0) 135 | railties (= 7.0.6) 136 | rails-dom-testing (2.1.1) 137 | activesupport (>= 5.0.0) 138 | minitest 139 | nokogiri (>= 1.6) 140 | rails-html-sanitizer (1.6.0) 141 | loofah (~> 2.21) 142 | nokogiri (~> 1.14) 143 | railties (7.0.6) 144 | actionpack (= 7.0.6) 145 | activesupport (= 7.0.6) 146 | method_source 147 | rake (>= 12.2) 148 | thor (~> 1.0) 149 | zeitwerk (~> 2.5) 150 | rake (13.0.6) 151 | reline (0.3.6) 152 | io-console (~> 0.5) 153 | rspec-core (3.12.2) 154 | rspec-support (~> 3.12.0) 155 | rspec-expectations (3.12.3) 156 | diff-lcs (>= 1.2.0, < 2.0) 157 | rspec-support (~> 3.12.0) 158 | rspec-mocks (3.12.5) 159 | diff-lcs (>= 1.2.0, < 2.0) 160 | rspec-support (~> 3.12.0) 161 | rspec-rails (6.0.3) 162 | actionpack (>= 6.1) 163 | activesupport (>= 6.1) 164 | railties (>= 6.1) 165 | rspec-core (~> 3.12) 166 | rspec-expectations (~> 3.12) 167 | rspec-mocks (~> 3.12) 168 | rspec-support (~> 3.12) 169 | rspec-support (3.12.1) 170 | sqlite3 (1.6.3-x86_64-darwin) 171 | sqlite3 (1.6.3-x86_64-linux) 172 | thor (1.2.2) 173 | timeout (0.4.0) 174 | tzinfo (2.0.6) 175 | concurrent-ruby (~> 1.0) 176 | websocket-driver (0.7.5) 177 | websocket-extensions (>= 0.1.0) 178 | websocket-extensions (0.1.5) 179 | zeitwerk (2.6.8) 180 | 181 | PLATFORMS 182 | x86_64-darwin-22 183 | x86_64-linux 184 | 185 | DEPENDENCIES 186 | bcrypt (~> 3.1.7) 187 | bootsnap 188 | debug 189 | error_highlight (>= 0.4.0) 190 | puma (>= 5.0) 191 | rails (~> 7.0) 192 | rspec-rails (~> 6.0.0) 193 | sqlite3 (~> 1.4) 194 | tzinfo-data 195 | 196 | RUBY VERSION 197 | ruby 3.1.2p20 198 | 199 | BUNDLED WITH 200 | 2.4.13 201 | --------------------------------------------------------------------------------