A skeleton web application configured to use Sinatra and ActiveRecord

*: Update everything to work with Ruby 3.4

NOTE: activerecord now uses 0 and 1 for false and true values in
sqlite3 boolean columns, so a migration should be run to update all
rows using boolean values from f->0 and t->1

This also has to move from unicorn to puma to use rackup

+131 -78
+1
.ruby-version
··· 1 + 3.4
+11 -10
Gemfile
··· 1 1 source "https://rubygems.org" 2 2 3 - ruby ">= 2.5.0" 3 + ruby ">= 3.4" 4 4 5 5 gem "rack" 6 6 7 - gem "sinatra", "< 3.0" 8 - gem "sinatra-contrib", "< 3.0" 9 - gem "erubis" 7 + gem "sinatra", "< 4.2" 8 + gem "erubi" 10 9 11 10 gem "rack_csrf" 12 11 13 - gem "activerecord", "~> 5.2" 12 + gem "activerecord", "~> 8.0" 13 + gem "sinatra-contrib" 14 14 gem "sinatra-activerecord" 15 15 16 16 gem "sqlite3" 17 - 18 17 # for mysql connections 19 18 #gem "mysql2" 20 19 21 - gem "unicorn" 20 + gem "puma" 21 + gem "rackup" 22 + 22 23 gem "json" 23 - 24 24 gem "bcrypt" 25 25 26 26 # for email and notification exceptions 27 - gem "mail", "~> 2.7.1" # https://github.com/mikel/mail/issues/1489 27 + gem "mail" 28 28 gem "pony" 29 29 30 30 # for development 31 - gem "shotgun" 31 + gem "rerun" 32 + gem "rb-kqueue" 32 33 gem "irb", :require => false 33 34 34 35 # for testing
+114 -63
Gemfile.lock
··· 1 1 GEM 2 2 remote: https://rubygems.org/ 3 3 specs: 4 - activemodel (5.2.8.1) 5 - activesupport (= 5.2.8.1) 6 - activerecord (5.2.8.1) 7 - activemodel (= 5.2.8.1) 8 - activesupport (= 5.2.8.1) 9 - arel (>= 9.0) 10 - activesupport (5.2.8.1) 11 - concurrent-ruby (~> 1.0, >= 1.0.2) 12 - i18n (>= 0.7, < 2) 13 - minitest (~> 5.1) 14 - tzinfo (~> 1.1) 15 - arel (9.0.0) 4 + activemodel (8.0.2) 5 + activesupport (= 8.0.2) 6 + activerecord (8.0.2) 7 + activemodel (= 8.0.2) 8 + activesupport (= 8.0.2) 9 + timeout (>= 0.4.0) 10 + activesupport (8.0.2) 11 + base64 12 + benchmark (>= 0.3) 13 + bigdecimal 14 + concurrent-ruby (~> 1.0, >= 1.3.1) 15 + connection_pool (>= 2.2.5) 16 + drb 17 + i18n (>= 1.6, < 2) 18 + logger (>= 1.4.2) 19 + minitest (>= 5.1) 20 + securerandom (>= 0.3) 21 + tzinfo (~> 2.0, >= 2.0.5) 22 + uri (>= 0.13.1) 23 + base64 (0.2.0) 16 24 bcrypt (3.1.20) 17 - concurrent-ruby (1.2.3) 18 - erubis (2.7.0) 19 - i18n (1.14.4) 25 + benchmark (0.4.0) 26 + bigdecimal (3.1.9) 27 + concurrent-ruby (1.3.5) 28 + connection_pool (2.5.0) 29 + date (3.4.1) 30 + drb (2.2.1) 31 + erubi (1.13.1) 32 + ffi (1.17.1) 33 + i18n (1.14.7) 20 34 concurrent-ruby (~> 1.0) 21 - io-console (0.7.2) 22 - irb (1.12.0) 23 - rdoc 35 + io-console (0.8.0) 36 + irb (1.15.1) 37 + pp (>= 0.6.0) 38 + rdoc (>= 4.0.0) 24 39 reline (>= 0.4.2) 25 - json (2.7.1) 26 - kgio (2.11.4) 27 - mail (2.7.1) 40 + json (2.10.2) 41 + listen (3.9.0) 42 + rb-fsevent (~> 0.10, >= 0.10.3) 43 + rb-inotify (~> 0.9, >= 0.9.10) 44 + logger (1.6.6) 45 + mail (2.8.1) 28 46 mini_mime (>= 0.1.1) 47 + net-imap 48 + net-pop 49 + net-smtp 29 50 mini_mime (1.1.5) 30 - mini_portile2 (2.8.5) 31 - minitest (5.22.2) 51 + mini_portile2 (2.8.8) 52 + minitest (5.25.4) 32 53 multi_json (1.15.0) 33 - mustermann (2.0.2) 54 + mustermann (3.0.3) 34 55 ruby2_keywords (~> 0.0.1) 56 + net-imap (0.5.6) 57 + date 58 + net-protocol 59 + net-pop (0.1.2) 60 + net-protocol 61 + net-protocol (0.2.2) 62 + timeout 63 + net-smtp (0.5.1) 64 + net-protocol 65 + nio4r (2.7.4) 35 66 pony (1.13.1) 36 67 mail (>= 2.0) 37 - psych (5.1.2) 68 + pp (0.6.2) 69 + prettyprint 70 + prettyprint (0.2.0) 71 + psych (5.2.3) 72 + date 38 73 stringio 39 - rack (2.2.8.1) 40 - rack-protection (2.2.4) 41 - rack 42 - rack-test (2.1.0) 74 + puma (6.6.0) 75 + nio4r (~> 2.0) 76 + rack (3.1.12) 77 + rack-protection (4.1.1) 78 + base64 (>= 0.1.0) 79 + logger (>= 1.6.0) 80 + rack (>= 3.0.0, < 4) 81 + rack-session (2.1.0) 82 + base64 (>= 0.1.0) 83 + rack (>= 3.0.0) 84 + rack-test (2.2.0) 43 85 rack (>= 1.3) 44 86 rack_csrf (2.7.0) 45 87 rack (>= 1.1.0) 46 - raindrops (0.20.1) 47 - rake (13.1.0) 48 - rdoc (6.6.2) 88 + rackup (2.2.1) 89 + rack (>= 3) 90 + rake (13.2.1) 91 + rb-fsevent (0.11.2) 92 + rb-inotify (0.11.1) 93 + ffi (~> 1.0) 94 + rb-kqueue (0.2.8) 95 + ffi (>= 0.5.0) 96 + rdoc (6.12.0) 49 97 psych (>= 4.0.0) 50 - reline (0.4.3) 98 + reline (0.6.0) 51 99 io-console (~> 0.5) 100 + rerun (0.14.0) 101 + listen (~> 3.0) 52 102 ruby2_keywords (0.0.5) 53 - shotgun (0.9.2) 54 - rack (>= 1.0) 55 - sinatra (2.2.4) 56 - mustermann (~> 2.0) 57 - rack (~> 2.2) 58 - rack-protection (= 2.2.4) 103 + securerandom (0.4.1) 104 + sinatra (4.1.1) 105 + logger (>= 1.6.0) 106 + mustermann (~> 3.0) 107 + rack (>= 3.0.0, < 4) 108 + rack-protection (= 4.1.1) 109 + rack-session (>= 2.0.0, < 3) 59 110 tilt (~> 2.0) 60 - sinatra-activerecord (2.0.27) 111 + sinatra-activerecord (2.0.28) 61 112 activerecord (>= 4.1) 62 113 sinatra (>= 1.0) 63 - sinatra-contrib (2.2.4) 64 - multi_json 65 - mustermann (~> 2.0) 66 - rack-protection (= 2.2.4) 67 - sinatra (= 2.2.4) 114 + sinatra-contrib (4.1.1) 115 + multi_json (>= 0.0.2) 116 + mustermann (~> 3.0) 117 + rack-protection (= 4.1.1) 118 + sinatra (= 4.1.1) 68 119 tilt (~> 2.0) 69 - sqlite3 (1.7.2) 120 + sqlite3 (2.6.0) 70 121 mini_portile2 (~> 2.8.0) 71 - stringio (3.1.0) 72 - thread_safe (0.3.6) 73 - tilt (2.3.0) 74 - tzinfo (1.2.11) 75 - thread_safe (~> 0.1) 76 - unicorn (6.1.0) 77 - kgio (~> 2.6) 78 - raindrops (~> 0.7) 122 + stringio (3.1.5) 123 + tilt (2.6.0) 124 + timeout (0.4.3) 125 + tzinfo (2.0.6) 126 + concurrent-ruby (~> 1.0) 127 + uri (1.0.3) 79 128 80 129 PLATFORMS 81 130 ruby 82 131 83 132 DEPENDENCIES 84 - activerecord (~> 5.2) 133 + activerecord (~> 8.0) 85 134 bcrypt 86 - erubis 135 + erubi 87 136 irb 88 137 json 89 - mail (~> 2.7.1) 138 + mail 90 139 minitest 91 140 pony 141 + puma 92 142 rack 93 143 rack-test 94 144 rack_csrf 145 + rackup 95 146 rake 96 - shotgun 97 - sinatra (< 3.0) 147 + rb-kqueue 148 + rerun 149 + sinatra (< 4.2) 98 150 sinatra-activerecord 99 - sinatra-contrib (< 3.0) 151 + sinatra-contrib 100 152 sqlite3 101 - unicorn 102 153 103 154 RUBY VERSION 104 - ruby 2.6.6p146 155 + ruby 3.4.2p28 105 156 106 157 BUNDLED WITH 107 - 2.5.6 158 + 2.6.2
+1 -1
bin/server
··· 20 20 if [ X"$RACK_ENV" = X"production" -o X"$RACK_ENV" = X"deployment" ]; then 21 21 bundle exec rackup --port 4567 $P/../config.ru 22 22 else 23 - bundle exec shotgun --port 4567 $P/../config.ru 23 + bundle exec rerun --dir app -- rackup --port 4567 $P/../config.ru 24 24 fi
+1
config/development.rb
··· 1 1 class App 2 2 set :show_exceptions, true 3 3 set :raise_errors, false 4 + set :public_folder, "public" 4 5 end
+2 -2
lib/app.rb
··· 135 135 end 136 136 137 137 # allow erb views to be named view.html.erb 138 - Tilt.prefer Tilt::ErubisTemplate 139 - Tilt.register Tilt::ErubisTemplate, "html.erb" 138 + Tilt.prefer Tilt::ErubiTemplate 139 + Tilt.register Tilt::ErubiTemplate, "html.erb" 140 140 141 141 # before every request, store controller for Logger 142 142 before do
+1 -1
lib/db.rb
··· 17 17 class Db 18 18 def self.connect(environment:) 19 19 dbconfig = YAML.load(File.read("#{App.root}/db/config.yml")) 20 - ActiveRecord::Base.dump_schema_after_migration = false 20 + ActiveRecord.dump_schema_after_migration = false 21 21 ActiveRecord::Base.establish_connection dbconfig[environment] 22 22 end 23 23 end
-1
lib/logging.rb
··· 28 28 began_at = Time.now.to_f 29 29 request = Sinatra::Request.new(env) 30 30 status, headers, body = @app.call(env) 31 - headers = Rack::Utils::HeaderHash[headers] 32 31 headers["X-Request-Id"] = request.uuid 33 32 body = Rack::BodyProxy.new(body) { 34 33 log(env, request, status, headers, began_at)