Namespace all classes under Domus
Assisted-by: Claude Sonnet 4.6 via Claude Code
diff --git a/Rakefile b/Rakefile
index 3c67845..f3575f0 100644
--- a/Rakefile
+++ b/Rakefile
@@ -21,7 +21,7 @@ task default: :test
desc "Start dev server with pre-seeded in-memory database"
task :dev do
- Sequel::Migrator.run(DB, "db/migrate") unless Dir.empty?("db/migrate")
+ Sequel::Migrator.run(Domus::DB, "db/migrate") unless Dir.empty?("db/migrate")
require "rack"
Rack::Server.start(config: "config.ru", Port: 9292)
@@ -33,16 +33,16 @@ namespace :db do
if Dir.empty?("db/migrate")
puts "No migrations."
else
- Sequel::Migrator.run(DB, "db/migrate")
+ Sequel::Migrator.run(Domus::DB, "db/migrate")
puts "Migrated."
end
end
desc "Rollback the last migration"
task :rollback do
- version = DB[:schema_migrations].order(Sequel.desc(:filename)).limit(1).get(:filename)
+ version = Domus::DB[:schema_migrations].order(Sequel.desc(:filename)).limit(1).get(:filename)
if version
- Sequel::Migrator.run(DB, "db/migrate", target: 0, current: version.sub(/\.rb$/, ""))
+ Sequel::Migrator.run(Domus::DB, "db/migrate", target: 0, current: version.sub(/\.rb$/, ""))
puts "Rolled back #{version}."
else
puts "Nothing to rollback."
diff --git a/config.ru b/config.ru
index d8576e9..2f617a8 100644
--- a/config.ru
+++ b/config.ru
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require_relative "app"
+require_relative "lib/app"
-run App
+run Domus::App
diff --git a/lib/app.rb b/lib/app.rb
index 09938f0..6306b52 100644
--- a/lib/app.rb
+++ b/lib/app.rb
@@ -3,16 +3,18 @@
require "roda"
require_relative "views/layout"
-class App < Roda
- route do |r|
- r.root do
- render_with_layout { "ok" }
+module Domus
+ class App < Roda
+ route do |r|
+ r.root do
+ render_with_layout { "ok" }
+ end
end
- end
- private
+ private
- def render_with_layout(&block)
- Views::Layout.new(&block).call
+ def render_with_layout(&block)
+ Views::Layout.new(&block).call
+ end
end
end
diff --git a/lib/config.rb b/lib/config.rb
index b41817a..a2d12b4 100644
--- a/lib/config.rb
+++ b/lib/config.rb
@@ -1,7 +1,9 @@
# frozen_string_literal: true
-class Config < Data.define(:database_url)
- def self.from_env
- new(database_url: ENV.fetch("DATABASE_URL"))
+module Domus
+ class Config < Data.define(:database_url)
+ def self.from_env
+ new(database_url: ENV.fetch("DATABASE_URL"))
+ end
end
end
diff --git a/lib/db.rb b/lib/db.rb
index ae8a2dc..362481f 100644
--- a/lib/db.rb
+++ b/lib/db.rb
@@ -5,4 +5,6 @@ require "sequel/extensions/migration"
require_relative "config"
-DB = Sequel.sqlite(Config.from_env.database_url)
+module Domus
+ DB = Sequel.sqlite(Config.from_env.database_url)
+end
diff --git a/lib/middleware/auth.rb b/lib/middleware/auth.rb
index f444559..c6a2e16 100644
--- a/lib/middleware/auth.rb
+++ b/lib/middleware/auth.rb
@@ -1,25 +1,26 @@
# frozen_string_literal: true
-module Middleware
-end
-
-class Middleware::Auth
- def initialize(app, header: "X-Forwarded-User")
- @app = app
- @header = header
- end
+module Domus
+ module Middleware
+ class Auth
+ def initialize(app, header: "X-Forwarded-User")
+ @app = app
+ @header = header
+ end
- def call(env)
- user = env["HTTP_#{header_name}"]
- return [401, {}, ["Unauthorized"]] unless user
+ def call(env)
+ user = env["HTTP_#{header_name}"]
+ return [401, {}, ["Unauthorized"]] unless user
- env["domus.user"] = user
- @app.call(env)
- end
+ env["domus.user"] = user
+ @app.call(env)
+ end
- private
+ private
- def header_name
- @header.upcase.tr("-", "_")
+ def header_name
+ @header.upcase.tr("-", "_")
+ end
+ end
end
end
diff --git a/lib/views/layout.rb b/lib/views/layout.rb
index 8e71449..127d737 100644
--- a/lib/views/layout.rb
+++ b/lib/views/layout.rb
@@ -2,26 +2,27 @@
require "phlex"
-module Views
-end
-
-class Views::Layout < Phlex::HTML
- def initialize(title: "Domus", &content)
- @title = title
- @content = content
- end
+module Domus
+ module Views
+ class Layout < Phlex::HTML
+ def initialize(title: "Domus", &content)
+ @title = title
+ @content = content
+ end
- def view_template
- doctype
+ def view_template
+ doctype
- html(lang: "en") do
- head do
- title { @title }
- script defer: true, src: "https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"
- end
+ html(lang: "en") do
+ head do
+ title { @title }
+ script defer: true, src: "https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"
+ end
- body do
- yield
+ body do
+ yield
+ end
+ end
end
end
end
diff --git a/test/test_app.rb b/test/test_app.rb
index c6c7065..bc36c87 100644
--- a/test/test_app.rb
+++ b/test/test_app.rb
@@ -8,7 +8,7 @@ class TestApp < Minitest::Test
include Rack::Test::Methods
def app
- App
+ Domus::App
end
def test_root
diff --git a/test/test_auth.rb b/test/test_auth.rb
index caa98e2..7be1bad 100644
--- a/test/test_auth.rb
+++ b/test/test_auth.rb
@@ -9,7 +9,7 @@ class TestAuth < Minitest::Test
def app
inner = proc { |env| [200, {}, ["hello #{env['domus.user']}"]] }
- Middleware::Auth.new(inner)
+ Domus::Middleware::Auth.new(inner)
end
def test_allows_request_with_header