skyward 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +40 -6
  3. data/lib/skyward/generator/cli/new/template/.gitignore.tt +4 -0
  4. data/lib/skyward/generator/cli/new/template/AGENTS.md.tt +55 -0
  5. data/lib/skyward/generator/cli/new/template/Gemfile.tt +22 -0
  6. data/lib/skyward/generator/cli/new/template/Rakefile.tt +7 -0
  7. data/lib/skyward/generator/cli/new/template/Steepfile.tt +15 -0
  8. data/lib/skyward/generator/cli/new/template/app.rb.tt +9 -0
  9. data/lib/skyward/generator/cli/new/template/bin/ci.tt +26 -0
  10. data/lib/skyward/generator/cli/new/template/bin/setup.tt +7 -0
  11. data/lib/skyward/generator/cli/new/template/bin/test.tt +7 -0
  12. data/lib/skyward/generator/cli/new/template/boot.rb.tt +18 -0
  13. data/lib/skyward/generator/cli/new/template/config.ru.tt +4 -0
  14. data/lib/skyward/generator/cli/new/template/db/migrate/.keep.tt +0 -0
  15. data/lib/skyward/generator/cli/new/template/lib/health_api.rb.tt +12 -0
  16. data/lib/skyward/generator/cli/new/template/modules/.keep.tt +0 -0
  17. data/lib/skyward/generator/cli/new/template/rbs_collection.yaml.tt +8 -0
  18. data/lib/skyward/generator/cli/new/template/sig/generated/app.rbs.tt +3 -0
  19. data/lib/skyward/generator/cli/new/template/sig/generated/boot.rbs.tt +2 -0
  20. data/lib/skyward/generator/cli/new/template/sig/generated/health_api.rbs.tt +6 -0
  21. data/lib/skyward/generator/cli/new/template/test/app_test.rb.tt +27 -0
  22. data/lib/skyward/generator/cli/new/template/test/lib/health_api_test.rb.tt +11 -0
  23. data/lib/skyward/generator/cli/new/template/test/test_helper.rb.tt +25 -0
  24. data/lib/skyward/generator/cli/new/template.rb +32 -0
  25. data/lib/skyward/generator/cli/new.rb +56 -0
  26. data/lib/skyward/generator/cli.rb +4 -0
  27. data/lib/skyward/generator/commands.rb +14 -0
  28. data/lib/skyward/generator.rb +16 -0
  29. data/lib/skyward/version.rb +1 -1
  30. data/sig/generated/skyward/generator/cli/new/template.rbs +25 -0
  31. data/sig/generated/skyward/generator/cli/new.rbs +20 -0
  32. data/sig/generated/skyward/generator/cli.rbs +4 -0
  33. data/sig/generated/skyward/generator/commands.rbs +2 -0
  34. data/sig/generated/skyward/generator.rbs +4 -0
  35. data/sig/manual/skyward/generator/cli/new/template.rbs +3 -0
  36. data/sig/manual/skyward/generator/cli/new.rbs +3 -0
  37. metadata +66 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25b07027de4079421511c9e154f168f0b5750e13e6b6c48ecc13b8bedeacc0cc
4
- data.tar.gz: ef0e35790e2a866662926dc3818efd0e75efd036f989e2cc72cf6ac55b77bf08
3
+ metadata.gz: 0d5ad91d8d26c204af3b712b7fee66fab575d37c1cfeb3b6b3c97444c04f3656
4
+ data.tar.gz: 213282afcdea36418210140fa79ccdac2ab7365d188a2992e9ddd994d818b6f9
5
5
  SHA512:
6
- metadata.gz: 98d9d8a665576b3c7d05c8eccd34555375ae65260285caeda760463a3850bf518932c288f1e280afec0fe9e470c5a0299440795362a1973b816b4fcd6f0829f6
7
- data.tar.gz: 6b1cc2d352380d71d51f5bd9e4ac57243cb0b3734c3beb4111568e34e30948c1303bf240336e90adada62c6d3ffef26f0ab8effdb7a796e64a9364d28605c3fb
6
+ metadata.gz: 3afbb8bd0632c7dd29ba303341194e7688ba9f4b15dd6a8e9e6c6b39063cf4868b8d45ddf4bfc6003c5a3327cfc637118071ea08f7920a0c6c78d5096ed42ac3
7
+ data.tar.gz: 9ddc7eda951422bcdb69eb018291a26d44d09564d7a422c099991777a5a498426eedfd6246627d99a09f017c771736311de9e0588d51ae9f5a482dced2918211
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Skyward
2
2
 
3
3
  > [!CAUTION]
4
- > **Work in progress: Skyward doesn't do anything yet.** Version 0.1 is a skeleton. The gems install and load, but none of the features described here are built. This README is the spec for what's coming, not documentation of what exists. Don't depend on it yet.
4
+ > Skyward is pre-1.0. Everything this README describes is built, as [Status](#status) lists, but parts of the [Skyward API](../skyward-api/README.md#status) and [Skyward ORM](../skyward-orm/README.md#status) specs aren't yet. Any release may change the API, so don't run it in production yet.
5
5
 
6
- Typed Ruby web apps, where an endpoint is a method and a row is a value. This gem installs both halves of Skyward:
6
+ This gem installs both halves of Skyward, and adds `skyward new`, which writes an app that uses them:
7
7
 
8
- - [Skyward API](../skyward-api/README.md), a web framework where an endpoint is a method, typed with RBS.
9
- - [Skyward ORM](../skyward-orm/README.md), an ORM where a class is a table and its rows are frozen values, typed with RBS.
8
+ - [Skyward API](../skyward-api/README.md), a web framework where an endpoint is a method and its RBS signature is the API contract.
9
+ - [Skyward ORM](../skyward-orm/README.md), an ORM where a class is a table, its rows are frozen values and its migrations are written for you.
10
10
 
11
11
  Each works without the other. Add this gem when you want both.
12
12
 
@@ -29,8 +29,42 @@ Skyward supports every Ruby that isn't end-of-life (3.3 and later, as of Novembe
29
29
  $ skyward new todos
30
30
  ```
31
31
 
32
- `skyward new` writes a working app: `app.rb` and `boot.rb`, a `Steepfile` with typing set up, tests, `bin/ci`, and an `AGENTS.md` that teaches an agent working in the app its conventions.
32
+ `skyward new` writes a blank, working app: `app.rb` and `boot.rb`, one endpoint, a `Steepfile` with typing set up, tests, `bin/ci`, and an `AGENTS.md` that teaches an agent working in the app its conventions. It has no resource to copy: [`examples/todos`](../examples/todos/README.md) is a worked one to read. Then it runs `bundle install` in the app, unless you pass `--skip-bundle`.
33
+
34
+ The name is lowercase letters, digits and underscores, starting with a letter, so it names the app's directory and, camelized, its title (`my_app` is `MyApp`). `skyward new` refuses a directory that already has files in it.
35
+
36
+ | Path | Holds |
37
+ | --- | --- |
38
+ | `Gemfile` | `skyward` at the version that wrote the app, `sqlite3`, Falcon to serve the app in development (`skyward serve`) and in production, and Steep, rbs-inline, Minitest and Rake |
39
+ | `boot.rb` | loads `lib/` and `modules/` with Zeitwerk, eager loads them and connects to `DATABASE_URL`, or SQLite at `db/todos.sqlite3` without it |
40
+ | `app.rb` | requires `boot.rb` and assigns `App = Skyward.app(docs: true, ...)`, which mounts `HealthAPI`, and is where each API you add is wired to its collaborators |
41
+ | `config.ru` | runs `App` |
42
+ | `lib/health_api.rb` | `HealthAPI`, the app's one endpoint, `GET /up`, for load balancers and uptime checks |
43
+ | `modules/` | empty, for the app's code, one directory per resource |
44
+ | `db/migrate/` | empty, for the migrations `skyward migration` writes |
45
+ | `sig/generated` | the signatures rbs-inline generates from the app's inline annotations |
46
+ | `Steepfile`, `rbs_collection.yaml` | Steep with every diagnostic an error, and the gem signatures it reads |
47
+ | `test/` | a test of `HealthAPI`, which calls its method, and of `App`, which checks over HTTP that it mounts `HealthAPI` at `/up` and serves `/openapi.json` and `/docs`, each in a transaction that's rolled back, on in-memory SQLite or `TEST_DATABASE_URL` |
48
+ | `bin/setup` | installs the gems and the gem signatures, and migrates the database |
49
+ | `bin/test` | runs the tests |
50
+ | `bin/ci` | regenerates the signatures and fails if they changed, runs the tests, then runs `skyward check` on a database of its own |
51
+ | `AGENTS.md` | the app's conventions: an endpoint is a method, signatures are generated, outcomes are values matched with `case`/`when`, collaborators are wired in `app.rb`, migrations are generated and reviewed, and `bin/ci` runs before pushing |
52
+ | `.gitignore` | the database, the installed gem signatures and the bundle |
53
+
54
+ ```sh
55
+ $ cd todos
56
+ $ bin/setup
57
+ $ bundle exec skyward serve # http://localhost:9292/docs
58
+ ```
59
+
60
+ The app is an API with no frontend. Its consumers generate their clients from its OpenAPI document, at `/openapi.json`.
61
+
62
+ [The getting-started guide](../docs/getting-started.md) walks through an app step by step, from `skyward new` to a table class, its migration, a typed API mounted in `app.rb`, its tests, `bin/ci`, `skyward serve` and the OpenAPI document.
33
63
 
34
64
  ## Status
35
65
 
36
- This README is the spec. Skyward 0.1 is a skeleton: `require "skyward"` loads both gems, and `skyward new` isn't built yet. It arrives once Skyward API and Skyward ORM are both built.
66
+ This README is the spec, and this section lists each part of it that's built, as it lands. `require "skyward"` loads both gems.
67
+
68
+ - **One reading of each type.** The `skyward` gem's tests hold Skyward API and Skyward ORM to the promise both READMEs make, that a row read from the database and the same class sent as JSON are the same thing, on SQLite and on PostgreSQL. A table class with a column of every type both read (`Integer`, `Float`, `BigDecimal`, `String`, `bool`, `Date`, `Time`, a union of symbols, `Hash[String, untyped]` and an `Array[T]` of each of those but the Hash, a nullable one of each scalar and of the Hash, and a nullable `Array[String]?`) makes the round trip: a row the ORM inserts, returned from an endpoint typed with the class, read back with `Skyward::API::Test.client` and posted to an endpoint that takes the class as `body:`, arrives `==` to the row the database holds, a `Time` with microseconds and a non-UTC offset included, a `BigDecimal` with more digits than a `Float` holds, a `Hash[String, untyped]` that nests an object in an array in an object and holds a Float, an Integer past 64 bits, `null`, `false`, an empty object and a non-ASCII key, and Arrays, an empty one among them, whose Strings hold a comma, a quote, a brace, a backslash and `"NULL"`. The class's OpenAPI component and the ORM's columns agree, field by field, on name, type, an Array's items, nullability and enum values. The types only one gem reads are listed in the test, so teaching either gem a type means updating the list: for now `Hash[String, T]` with any `T` but `untyped`, `Array[T]` of any other `T`, records, classes with typed readers, unions of them and literals are read by Skyward API alone.
69
+ - **`skyward new`.** `skyward new NAME` writes the app [Starting an app](#starting-an-app) describes, every file of it from a function of the name alone, then runs `bundle install` in it unless given `--skip-bundle`, outside any bundle `skyward` runs under, so `bundle exec skyward new` installs the app's Gemfile, not the outer one. The app is blank: its one endpoint is `GET /up`, and `modules/` and `db/migrate/` are empty, each holding only a `.keep` so git keeps it. A missing name, more than one, a name that isn't lowercase letters, digits and underscores starting with a letter, or a path that exists and isn't an empty directory prints why and exits 1, writing nothing. The packaging check builds and installs the gems, runs `skyward new demo`, and fails unless the app's own `bin/ci` passes with them, Steep, `skyward check` and `skyward migrate` with no migrations included.
70
+ - **The getting-started guide and `llms.txt`.** [`docs/getting-started.md`](../docs/getting-started.md) walks a newcomer from `gem install skyward` to a running, tested, documented API, showing each step's command, code and output, for Skyward 0.3. It starts from the blank app and builds a resource from nothing: a table class, its migration, a typed API mounted in `app.rb`, its tests, `bin/ci`, `skyward serve` and `curl`. Every command in it has been run, in order, on a fresh app. [`llms.txt`](../llms.txt), at the repository root, points agents at the guide, each gem's README and the `AGENTS.md` that `skyward new` writes, as raw Markdown.
@@ -0,0 +1,4 @@
1
+ /.bundle/
2
+ /vendor/
3
+ /.gem_rbs_collection/
4
+ /db/*.sqlite3*
@@ -0,0 +1,55 @@
1
+ # {{title}}
2
+
3
+ A JSON API built with Skyward: [Skyward API](https://github.com/bottrall/skyward/blob/main/skyward-api/README.md) serves it and [Skyward ORM](https://github.com/bottrall/skyward/blob/main/skyward-orm/README.md) stores it. It has no frontend: consumers generate their clients from its OpenAPI document, at `/openapi.json`, and `/docs` is its API reference.
4
+
5
+ ## Workflow
6
+
7
+ - Run `bin/setup` once, and again after pulling: it installs the gems and the gem signatures Steep reads, and migrates the development database.
8
+ - `bin/test` runs the tests. `bin/ci` runs everything CI runs; run it before pushing.
9
+ - `bundle exec skyward serve` serves the app on `PORT` (default 9292) and reloads it on every change. `bundle exec skyward routes` lists the endpoints.
10
+ - The app connects to `DATABASE_URL`, or to SQLite at `db/{{name}}.sqlite3` without it.
11
+
12
+ ## Layout
13
+
14
+ - `boot.rb` loads `lib/` and `modules/` with Zeitwerk, eager loads them and calls `Skyward.connect`. The ORM's commands load it.
15
+ - `app.rb` requires `boot.rb` and assigns `App`, mounting each API. The API's commands load it, and `config.ru` runs it.
16
+ - `modules/` groups the code by domain, one directory per resource, and file paths match constant names: `modules/todos/record.rb` is `Todos::Record`, the table class, and `modules/todos/api.rb` is `Todos::API`, its endpoints. `modules/todos.rb` only declares `module Todos`, so rbs-inline gives it a signature. [`examples/todos`](https://github.com/bottrall/skyward/tree/main/examples/todos) is a worked resource.
17
+ - `lib/` holds what belongs to no domain, such as `lib/health_api.rb`, `HealthAPI`, which answers `GET /up` for load balancers and uptime checks.
18
+ - `test/` mirrors the code it tests.
19
+
20
+ ## Endpoints
21
+
22
+ - An endpoint is a public method on a class that subclasses `Skyward::API`, routed at the top of the class with `get`, `post`, `put`, `patch` or `delete`. Its keywords are its inputs (path parameters, the query string and `body:`), and what it returns is the response.
23
+ - Each API object is created once, at boot, and shared by every request, so per-request data arrives as arguments, never as instance state.
24
+ - A response other than 200 comes from a helper, such as `created`, `not_found` or `unprocessable`, and the method's return type names it (`Responses::NotFound`).
25
+ - An expected outcome is a value, never an exception: a query returns the row or `nil`, and a write returns how many rows it changed, or the rows `into` asks for, or a `Skyward::ORM::Violation`. Match it with `case`/`when` and turn it into a response. Steep can't type-check `case`/`in`, so don't use it.
26
+
27
+ ## Wiring
28
+
29
+ - An API takes its collaborators as keywords to `initialize`, typed with the smallest type it uses. `app.rb` is the one place that wires them: `Todos::API.new(todos: Todos::Record)`.
30
+ - A test passes its own in through the same front door, so tests need no mocks.
31
+
32
+ ## Types
33
+
34
+ - Every method is typed with rbs-inline comments: one `# @rbs name: Type` per parameter and a `# @rbs return: Type`. Constants, `Data.define` members and `attr_reader`s take a trailing `#: Type`, and an `attr_reader` also needs a `# @dynamic name` line above it. Each Ruby file outside `test/` starts with `# rbs_inline: enabled`.
35
+ - A file that names Skyward API's types starts with `# @rbs use Skyward::API::*` and writes them relative to it (`Responses::NotFound`).
36
+ - `sig/generated` is generated from those comments, so never edit it or regenerate it by hand: every `skyward` command that reads types (`serve`, `routes`, `openapi`, `migration`, `migrate`, `rollback` and `status`) regenerates it first, and `bin/ci` regenerates it and fails when that changed it, for you to commit. Hand-written signatures, such as interfaces, go in `sig/manual`.
37
+ - The types are the contract: Skyward API coerces and validates every request against them, the OpenAPI document is built from them, and Steep checks the code against them, with every diagnostic an error.
38
+
39
+ ## Database
40
+
41
+ - A table class subclasses `Skyward::ORM::Record`, and its typed `attr_reader`s are its columns. Its rows are frozen values, so compare them with `==`.
42
+ - Never write a migration by hand. Change the table class, run `bundle exec skyward migration NAME`, review the SQL it writes to `db/migrate/`, run `bundle exec skyward migrate`, and commit the migration with the class.
43
+ - The database enforces the rules, such as a title's length, and a write it refuses returns a `Skyward::ORM::Violation` to match.
44
+
45
+ ## Tests
46
+
47
+ - Tests are Minitest, in spec style (`describe`/`it`).
48
+ - An endpoint's behaviour is tested by calling its method, in its API's test, which mirrors the API's path: `test/lib/health_api_test.rb` for `HealthAPI`. Skyward API coerces and validates each request against the signature, so the tests don't repeat that over HTTP.
49
+ - `test/app_test.rb` covers mounting, which is what `app.rb` decides. Through `Skyward::API::Test.client(App)`, it makes one request to each API at the path it's mounted at, and checks that `/openapi.json` lists every path and `/docs` is served. A new API adds one request at its mount path, and a new endpoint only adds its path to that list.
50
+ - Every test runs in a transaction that's rolled back after it, the HTTP tests included, so each starts from an empty database.
51
+ - The tests use their own database, migrated from empty each run: in-memory SQLite, or `TEST_DATABASE_URL`. They never touch `DATABASE_URL`.
52
+
53
+ ## CI
54
+
55
+ `bin/ci` regenerates the signatures and fails if they changed, runs the tests, then runs `skyward check`, which boots the app in strict mode, so an untyped endpoint fails it, and runs Steep.
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "skyward", "= {{version}}"
6
+ gem "sqlite3", "~> 2.10"
7
+
8
+ # Falcon serves the app in development (skyward serve) and in production. The
9
+ # app's code never requires it, which keeps its signatures out of the RBS
10
+ # collection.
11
+ gem "falcon", "~> 0.57", require: false
12
+
13
+ group :development, :test do
14
+ # skyward check runs both.
15
+ gem "rbs-inline", "~> 0.14", require: false
16
+ gem "steep", "~> 2.1", require: false
17
+ end
18
+
19
+ group :test do
20
+ gem "minitest", "~> 6.0"
21
+ gem "rake", "~> 13.4"
22
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "minitest/test_task"
4
+
5
+ Minitest::TestTask.create
6
+
7
+ task default: :test
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ D = Steep::Diagnostic
4
+
5
+ target :app do
6
+ signature "sig"
7
+
8
+ check "*.rb", "lib", "modules"
9
+
10
+ # The Skyward gems' signatures come with the gems, and the rest from the RBS
11
+ # collection, which bin/setup installs.
12
+ collection_config "rbs_collection.yaml"
13
+
14
+ configure_code_diagnostics(D::Ruby.all_error)
15
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rbs_inline: enabled
4
+
5
+ require_relative "boot"
6
+
7
+ App = Skyward.app(docs: true, title: "{{title}}") do |app|
8
+ app.mount HealthAPI.new
9
+ end #: Skyward::API::_RackApp
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env bash
2
+ set -e
3
+ cd "$(dirname "$0")/.."
4
+
5
+ scratch=$(mktemp -d)
6
+ trap 'rm -rf "$scratch"' EXIT
7
+
8
+ bundle exec rbs collection install
9
+
10
+ # Regenerating the signatures is how they're kept current, so a stale one
11
+ # fails here, already fixed, for you to review and commit.
12
+ mkdir -p sig/generated
13
+ mv sig/generated "$scratch/committed"
14
+ bundle exec rbs-inline --output=sig/generated *.rb lib modules
15
+ if ! diff -r "$scratch/committed" sig/generated; then
16
+ echo "sig/generated was out of date, and bin/ci has regenerated it. Review and commit it." >&2
17
+ exit 1
18
+ fi
19
+
20
+ bin/test
21
+
22
+ # skyward check boots the app, which connects with the schema check on, so it
23
+ # runs on a database of its own, migrated from empty.
24
+ export DATABASE_URL="sqlite://$scratch/check.sqlite3"
25
+ bundle exec skyward migrate
26
+ bundle exec skyward check
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ set -e
3
+ cd "$(dirname "$0")/.."
4
+
5
+ bundle install
6
+ bundle exec rbs collection install
7
+ bundle exec skyward migrate
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ # Any arguments go to rake, so `bin/test N=/404/` runs only the tests whose
3
+ # names match.
4
+ set -e
5
+ cd "$(dirname "$0")/.."
6
+
7
+ exec bundle exec rake test "$@"
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rbs_inline: enabled
4
+
5
+ require "skyward"
6
+ require "zeitwerk"
7
+
8
+ loader = Zeitwerk::Loader.new
9
+ loader.push_dir("#{__dir__}/lib")
10
+ loader.push_dir("#{__dir__}/modules")
11
+ loader.inflector.inflect("api" => "API", "health_api" => "HealthAPI")
12
+ # skyward serve unloads the app's code to reload it, which Zeitwerk allows only
13
+ # for a loader set up with reloading on.
14
+ loader.enable_reloading if ENV["RACK_ENV"] == "development"
15
+ loader.setup
16
+ loader.eager_load
17
+
18
+ Skyward.connect(ENV.fetch("DATABASE_URL", "sqlite://#{__dir__}/db/{{name}}.sqlite3"))
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "app"
4
+ run App
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rbs_inline: enabled
4
+
5
+ class HealthAPI < Skyward::API
6
+ description "Whether the app is up, for load balancers and uptime checks."
7
+
8
+ get "/up", to: :show, summary: "Report that the app is up."
9
+
10
+ # @rbs return: { status: "ok" }
11
+ def show = { status: "ok" }
12
+ end
@@ -0,0 +1,8 @@
1
+ sources:
2
+ - type: git
3
+ name: ruby/gem_rbs_collection
4
+ remote: https://github.com/ruby/gem_rbs_collection.git
5
+ revision: main
6
+ repo_dir: gems
7
+
8
+ path: .gem_rbs_collection
@@ -0,0 +1,3 @@
1
+ # Generated from app.rb with RBS::Inline
2
+
3
+ App: Skyward::API::_RackApp
@@ -0,0 +1,2 @@
1
+ # Generated from boot.rb with RBS::Inline
2
+
@@ -0,0 +1,6 @@
1
+ # Generated from lib/health_api.rb with RBS::Inline
2
+
3
+ class HealthAPI < Skyward::API
4
+ # @rbs return: { status: "ok" }
5
+ def show: () -> { status: "ok" }
6
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ describe "App" do
6
+ let(:client) { Skyward::API::Test.client(App) }
7
+
8
+ describe "GET /up" do
9
+ it "says the app is up" do
10
+ assert_equal({ status: "ok" }, client.get("/up").json)
11
+ end
12
+ end
13
+
14
+ describe "GET /openapi.json" do
15
+ it "documents every endpoint" do
16
+ paths = client.get("/openapi.json").json[:paths].keys
17
+
18
+ assert_equal %i[/up], paths
19
+ end
20
+ end
21
+
22
+ describe "GET /docs" do
23
+ it "serves the API reference" do
24
+ assert_includes client.get("/docs").body, "<title>{{title}}</title>"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ describe HealthAPI do
6
+ describe "#show" do
7
+ it "says the app is up" do
8
+ assert_equal({ status: "ok" }, HealthAPI.new.show)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "minitest/autorun"
4
+ require "skyward"
5
+ require "stringio"
6
+
7
+ # A database of the suite's own, migrated from empty each run, unless
8
+ # TEST_DATABASE_URL names another, so the tests never run against the
9
+ # DATABASE_URL the app uses.
10
+ ENV["DATABASE_URL"] = ENV.fetch("TEST_DATABASE_URL", "sqlite://:memory:")
11
+
12
+ # App logs every request to the $stdout it boots with, which would bury the
13
+ # test report, so it boots with one of its own. Its boot.rb connects with the
14
+ # schema check on, which an unmigrated database fails, so the check waits for
15
+ # Skyward.migrate.
16
+ stdout = $stdout
17
+ $stdout = StringIO.new
18
+ Skyward::ORM::Connection::SESSION.without_check { require_relative "../app" }
19
+ $stdout = stdout
20
+ Skyward.migrate(File.expand_path("../db/migrate", __dir__))
21
+
22
+ # Every test, App's HTTP tests too, runs in a transaction that's rolled back
23
+ # after it. The test client calls App on the test's fiber, so its requests run
24
+ # in that transaction.
25
+ Minitest::Test.include(Skyward::ORM::Transactional)
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skyward::Generator::CLI::New::Template
4
+ extend self
5
+
6
+ DIRECTORY = "#{__dir__}/template".freeze #: String
7
+
8
+ # Every file there ends in it, so none of the tools that read the gem's own
9
+ # Ruby, signatures and Steepfile takes the app's for the gem's.
10
+ SUFFIX = ".tt" #: String
11
+
12
+ PLACEHOLDER = /\{\{\w+\}\}/ #: Regexp
13
+
14
+ # FNM_DOTMATCH, so the app gets its .gitignore, and the .keep files that make
15
+ # git keep its empty directories.
16
+ FILES = Dir.glob("**/*#{SUFFIX}", File::FNM_DOTMATCH, base: DIRECTORY).to_h do |file|
17
+ [file.delete_suffix(SUFFIX), File.read(File.join(DIRECTORY, file))]
18
+ end.freeze #: Hash[String, String]
19
+
20
+ # @rbs name: String
21
+ # @rbs return: Hash[String, String]
22
+ def files(name)
23
+ values = { "{{name}}" => name, "{{title}}" => title(name), "{{version}}" => Skyward::VERSION }
24
+ FILES.transform_values { |content| content.gsub(PLACEHOLDER) { |key| values.fetch(key) } }
25
+ end
26
+
27
+ private
28
+
29
+ # @rbs name: String
30
+ # @rbs return: String
31
+ def title(name) = name.split("_").map(&:capitalize).join
32
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+
5
+ module Skyward::Generator::CLI::New
6
+ extend self
7
+
8
+ SKIP_BUNDLE = "--skip-bundle" #: String
9
+
10
+ # Lowercase, so it names one directory on every filesystem, and a constant
11
+ # once camelized.
12
+ NAME = /\A[a-z][a-z0-9_]*\z/ #: Regexp
13
+
14
+ # @rbs (Array[String] args, directory: String, env: Hash[String, String], out: _Writer,
15
+ # kernel: singleton(Kernel)) -> void
16
+ def run(args, directory:, env:, out:, kernel:)
17
+ names = args - [SKIP_BUNDLE]
18
+ problem = problem(names, directory)
19
+ return kernel.abort(problem) if problem
20
+
21
+ name = names.fetch(0)
22
+ app = File.join(directory, name)
23
+ Template.files(name).each do |path, content|
24
+ file = File.join(app, path)
25
+ FileUtils.mkdir_p(File.dirname(file))
26
+ File.write(file, content)
27
+ File.chmod(0o755, file) if path.start_with?("bin/")
28
+ out.write("Wrote #{File.join(name, path)}\n")
29
+ end
30
+ # system merges env into this process's environment unless told to replace it.
31
+ unless args.include?(SKIP_BUNDLE) || kernel.system(env, "bundle", "install", chdir: app, unsetenv_others: true)
32
+ return kernel.abort("skyward: bundle install failed in #{name}. Fix what it printed, then run bin/setup there.")
33
+ end
34
+
35
+ out.write("Next: cd #{name} && bin/setup\n")
36
+ end
37
+
38
+ private
39
+
40
+ # @rbs names: Array[String]
41
+ # @rbs directory: String
42
+ # @rbs return: String?
43
+ def problem(names, directory)
44
+ name = names.first
45
+ unless name && names.size == 1
46
+ return "skyward: new takes one NAME, the app's directory.\nUsage: skyward new NAME [#{SKIP_BUNDLE}]"
47
+ end
48
+ unless name.match?(NAME)
49
+ return "skyward: #{name} can't name an app. Use lowercase letters, digits and underscores, " \
50
+ "starting with a letter, as in my_app."
51
+ end
52
+
53
+ app = File.join(directory, name)
54
+ "skyward: #{name} already exists and isn't an empty directory." if File.exist?(app) && !Dir.empty?(app)
55
+ end
56
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skyward::Generator::CLI
4
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "skyward/generator"
4
+
5
+ Skyward::Core::CLI.register(
6
+ "new",
7
+ "Write a new app in NAME/ and install its gems, unless given --skip-bundle"
8
+ ) do |args|
9
+ # Under bundle exec, the app's bundle install would otherwise read the
10
+ # Gemfile skyward runs under, not the app's.
11
+ # RBS doesn't declare Bundler.unbundled_env.
12
+ env = defined?(Bundler) ? Bundler.unbundled_env : ENV.to_h # steep:ignore NoMethod
13
+ Skyward::Generator::CLI::New.run(args, directory: Dir.pwd, env:, out: $stdout, kernel: Kernel)
14
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "skyward/core"
4
+ require "zeitwerk"
5
+ require_relative "version"
6
+
7
+ loader = Zeitwerk::Loader.for_gem_extension(Skyward)
8
+ loader.inflector.inflect("cli" => "CLI")
9
+ # The skyward executable loads it, and it defines no constant.
10
+ loader.ignore("#{__dir__}/generator/commands.rb")
11
+ # It defines Skyward::VERSION, not the Skyward::Version its name means to the loader.
12
+ loader.ignore("#{__dir__}/version.rb")
13
+ loader.setup
14
+
15
+ module Skyward::Generator
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Skyward
4
- VERSION = "0.2.0" #: String
4
+ VERSION = "0.4.0" #: String
5
5
  end
@@ -0,0 +1,25 @@
1
+ # Generated from lib/skyward/generator/cli/new/template.rb with RBS::Inline
2
+
3
+ module Skyward::Generator::CLI::New::Template
4
+ DIRECTORY: String
5
+
6
+ # Every file there ends in it, so none of the tools that read the gem's own
7
+ # Ruby, signatures and Steepfile takes the app's for the gem's.
8
+ SUFFIX: String
9
+
10
+ PLACEHOLDER: Regexp
11
+
12
+ # FNM_DOTMATCH, so the app gets its .gitignore, and the .keep files that make
13
+ # git keep its empty directories.
14
+ FILES: Hash[String, String]
15
+
16
+ # @rbs name: String
17
+ # @rbs return: Hash[String, String]
18
+ def files: (String name) -> Hash[String, String]
19
+
20
+ private
21
+
22
+ # @rbs name: String
23
+ # @rbs return: String
24
+ def title: (String name) -> String
25
+ end
@@ -0,0 +1,20 @@
1
+ # Generated from lib/skyward/generator/cli/new.rb with RBS::Inline
2
+
3
+ module Skyward::Generator::CLI::New
4
+ SKIP_BUNDLE: String
5
+
6
+ # Lowercase, so it names one directory on every filesystem, and a constant
7
+ # once camelized.
8
+ NAME: Regexp
9
+
10
+ # @rbs (Array[String] args, directory: String, env: Hash[String, String], out: _Writer,
11
+ # kernel: singleton(Kernel)) -> void
12
+ def run: (Array[String] args, directory: String, env: Hash[String, String], out: _Writer, kernel: singleton(Kernel)) -> void
13
+
14
+ private
15
+
16
+ # @rbs names: Array[String]
17
+ # @rbs directory: String
18
+ # @rbs return: String?
19
+ def problem: (Array[String] names, String directory) -> String?
20
+ end
@@ -0,0 +1,4 @@
1
+ # Generated from lib/skyward/generator/cli.rb with RBS::Inline
2
+
3
+ module Skyward::Generator::CLI
4
+ end
@@ -0,0 +1,2 @@
1
+ # Generated from lib/skyward/generator/commands.rb with RBS::Inline
2
+
@@ -0,0 +1,4 @@
1
+ # Generated from lib/skyward/generator.rb with RBS::Inline
2
+
3
+ module Skyward::Generator
4
+ end
@@ -0,0 +1,3 @@
1
+ module Skyward::Generator::CLI::New::Template
2
+ extend ::Skyward::Generator::CLI::New::Template
3
+ end
@@ -0,0 +1,3 @@
1
+ module Skyward::Generator::CLI::New
2
+ extend ::Skyward::Generator::CLI::New
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skyward
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Bottrall
@@ -15,28 +15,56 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.2.0
18
+ version: 0.4.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.2.0
25
+ version: 0.4.0
26
+ - !ruby/object:Gem::Dependency
27
+ name: skyward-core
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.4.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '='
38
+ - !ruby/object:Gem::Version
39
+ version: 0.4.0
26
40
  - !ruby/object:Gem::Dependency
27
41
  name: skyward-orm
28
42
  requirement: !ruby/object:Gem::Requirement
29
43
  requirements:
30
44
  - - '='
31
45
  - !ruby/object:Gem::Version
32
- version: 0.2.0
46
+ version: 0.4.0
33
47
  type: :runtime
34
48
  prerelease: false
35
49
  version_requirements: !ruby/object:Gem::Requirement
36
50
  requirements:
37
51
  - - '='
38
52
  - !ruby/object:Gem::Version
39
- version: 0.2.0
53
+ version: 0.4.0
54
+ - !ruby/object:Gem::Dependency
55
+ name: zeitwerk
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.8'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.8'
40
68
  email:
41
69
  - jakebottrall@gmail.com
42
70
  executables: []
@@ -45,9 +73,42 @@ extra_rdoc_files: []
45
73
  files:
46
74
  - README.md
47
75
  - lib/skyward.rb
76
+ - lib/skyward/generator.rb
77
+ - lib/skyward/generator/cli.rb
78
+ - lib/skyward/generator/cli/new.rb
79
+ - lib/skyward/generator/cli/new/template.rb
80
+ - lib/skyward/generator/cli/new/template/.gitignore.tt
81
+ - lib/skyward/generator/cli/new/template/AGENTS.md.tt
82
+ - lib/skyward/generator/cli/new/template/Gemfile.tt
83
+ - lib/skyward/generator/cli/new/template/Rakefile.tt
84
+ - lib/skyward/generator/cli/new/template/Steepfile.tt
85
+ - lib/skyward/generator/cli/new/template/app.rb.tt
86
+ - lib/skyward/generator/cli/new/template/bin/ci.tt
87
+ - lib/skyward/generator/cli/new/template/bin/setup.tt
88
+ - lib/skyward/generator/cli/new/template/bin/test.tt
89
+ - lib/skyward/generator/cli/new/template/boot.rb.tt
90
+ - lib/skyward/generator/cli/new/template/config.ru.tt
91
+ - lib/skyward/generator/cli/new/template/db/migrate/.keep.tt
92
+ - lib/skyward/generator/cli/new/template/lib/health_api.rb.tt
93
+ - lib/skyward/generator/cli/new/template/modules/.keep.tt
94
+ - lib/skyward/generator/cli/new/template/rbs_collection.yaml.tt
95
+ - lib/skyward/generator/cli/new/template/sig/generated/app.rbs.tt
96
+ - lib/skyward/generator/cli/new/template/sig/generated/boot.rbs.tt
97
+ - lib/skyward/generator/cli/new/template/sig/generated/health_api.rbs.tt
98
+ - lib/skyward/generator/cli/new/template/test/app_test.rb.tt
99
+ - lib/skyward/generator/cli/new/template/test/lib/health_api_test.rb.tt
100
+ - lib/skyward/generator/cli/new/template/test/test_helper.rb.tt
101
+ - lib/skyward/generator/commands.rb
48
102
  - lib/skyward/version.rb
49
103
  - sig/generated/skyward.rbs
104
+ - sig/generated/skyward/generator.rbs
105
+ - sig/generated/skyward/generator/cli.rbs
106
+ - sig/generated/skyward/generator/cli/new.rbs
107
+ - sig/generated/skyward/generator/cli/new/template.rbs
108
+ - sig/generated/skyward/generator/commands.rbs
50
109
  - sig/generated/skyward/version.rbs
110
+ - sig/manual/skyward/generator/cli/new.rbs
111
+ - sig/manual/skyward/generator/cli/new/template.rbs
51
112
  homepage: https://github.com/bottrall/skyward
52
113
  licenses:
53
114
  - MIT