skyward-core 0.1.0 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +13 -6
- data/exe/skyward +7 -0
- data/lib/skyward/core/boot_error.rb +4 -0
- data/lib/skyward/core/cli/executable.rb +24 -0
- data/lib/skyward/core/cli/registry.rb +33 -0
- data/lib/skyward/core/cli.rb +47 -0
- data/lib/skyward/core/signatures/inline.rb +77 -0
- data/lib/skyward/core/signatures/loader.rb +35 -0
- data/lib/skyward/core/signatures.rb +17 -0
- data/lib/skyward/core/types/reader.rb +244 -0
- data/lib/skyward/core/types.rb +59 -0
- data/lib/skyward/core/version.rb +5 -1
- data/lib/skyward/core.rb +6 -0
- data/sig/generated/skyward/core/boot_error.rbs +4 -0
- data/sig/generated/skyward/core/cli/executable.rbs +15 -0
- data/sig/generated/skyward/core/cli/registry.rbs +36 -0
- data/sig/generated/skyward/core/cli.rbs +24 -0
- data/sig/generated/skyward/core/signatures/inline.rbs +38 -0
- data/sig/generated/skyward/core/signatures/loader.rbs +16 -0
- data/sig/generated/skyward/core/signatures.rbs +15 -0
- data/sig/generated/skyward/core/types/reader.rbs +110 -0
- data/sig/generated/skyward/core/types.rbs +144 -0
- data/sig/manual/skyward/core/cli/executable.rbs +3 -0
- data/sig/manual/skyward/core/cli.rbs +3 -0
- data/sig/manual/skyward/core/signatures/inline.rbs +3 -0
- data/sig/manual/skyward/core/signatures.rbs +3 -0
- metadata +41 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 707a5a84c350a7f1277035bfa2f2671a7c8297f5bf620b5c8a34b5d4167a3005
|
|
4
|
+
data.tar.gz: 42857fbc309d41e5dcf1d68be4962766f6022cd8f1429d41e46d763ce05eae58
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a4416139d3ffbd9649cc53e7a6040f865c61af299364b81739662e8356bfdd9fbebbb95cc9a76410d10973046c38eb30afb8047d153959626ddabc49c29839e4
|
|
7
|
+
data.tar.gz: e4005e6ceccb54ba121a36c526fe653a866c2129d006f28fcf18ad13109e4ed8e4ba2a377a5d6ddd6f19a1d91b63ca25f8abcb0b979e199d1fc8dbbae30550c1
|
data/README.md
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
# Skyward Core
|
|
2
2
|
|
|
3
3
|
> [!CAUTION]
|
|
4
|
-
>
|
|
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
6
|
The plumbing that [Skyward API](../skyward-api/README.md) and [Skyward ORM](../skyward-orm/README.md) share. You don't add it to your Gemfile: each of them depends on it, at exactly the same version.
|
|
7
7
|
|
|
8
8
|
## What it owns
|
|
9
9
|
|
|
10
|
-
- **The `Skyward` namespace.** Skyward Core opens it, and every Skyward gem's Zeitwerk loader extends it.
|
|
10
|
+
- **The `Skyward` namespace.** Skyward Core opens it, and every Skyward gem's Zeitwerk loader extends it. Each gem's names live in that gem's own namespace there: `Skyward::Core`, `Skyward::API` and `Skyward::ORM`.
|
|
11
11
|
- **The `skyward` command.** It comes with Skyward Core, so it's there whichever Skyward gems you install. Each gem adds its own commands to it.
|
|
12
12
|
- **Loading RBS signatures.** One loader finds your app's signatures and those of the gems it uses, for every Skyward gem.
|
|
13
|
+
- **Keeping `sig/generated` current.** One function regenerates your app's `sig/generated` from its Ruby with rbs-inline, and the Skyward commands that read types call it first, so you never run rbs-inline by hand. `skyward check` only checks it's current, for CI.
|
|
13
14
|
- **Reading RBS types.** One reader turns a signature into values that Skyward API and Skyward ORM each build their own mappings on, so a `Todo` read from the database and a `Todo` sent as JSON are the same thing.
|
|
14
|
-
- **`Skyward::BootError`**, which every Skyward gem raises when your app can't boot, saying why.
|
|
15
|
+
- **`Skyward::Core::BootError`**, which every Skyward gem raises when your app can't boot, saying why.
|
|
15
16
|
|
|
16
17
|
## Adding commands
|
|
17
18
|
|
|
18
19
|
The `skyward` executable finds each installed gem's `lib/skyward/<gem>/commands.rb` with `Gem.find_files` and loads it, and that file registers the gem's commands:
|
|
19
20
|
|
|
20
21
|
```ruby
|
|
21
|
-
Skyward::
|
|
22
|
+
Skyward::Core::CLI.register("routes", "List every route and the method that serves it") do |args|
|
|
22
23
|
# ...
|
|
23
24
|
end
|
|
24
25
|
```
|
|
25
26
|
|
|
26
|
-
`skyward` with no command,
|
|
27
|
+
`skyward` with no command, `skyward help`, `--help` or `-h` lists every registered command with its description. An unknown command prints the same list and exits with status 1. A command fails by exiting (`abort "why"`); one that returns has succeeded.
|
|
27
28
|
|
|
28
29
|
## Ruby
|
|
29
30
|
|
|
@@ -31,4 +32,10 @@ Skyward supports every Ruby that isn't end-of-life (3.3 and later, as of Novembe
|
|
|
31
32
|
|
|
32
33
|
## Status
|
|
33
34
|
|
|
34
|
-
This README is the spec
|
|
35
|
+
This README is the spec, and this section lists each part of it that's built, as it lands. The gem opens the `Skyward` namespace and sets up its loader.
|
|
36
|
+
|
|
37
|
+
- **The `skyward` command.** The executable loads each installed gem's `commands.rb`, `Skyward::Core::CLI.register` adds a command, and `skyward` lists them and runs one, as [Adding commands](#adding-commands) describes. For the commands to run other gems' executables, `Skyward::Core::CLI::Executable.find(name, feature: name)` returns the path of gem `name`'s executable `name` when `feature` can be required in the bundle `skyward` runs in, or `nil` otherwise, and `Skyward::Core::CLI::Executable::CAPTURE` runs a command with an environment in a directory and returns its output, errors included, and whether it succeeded.
|
|
38
|
+
- **Loading RBS signatures.** `Skyward::Core::Signatures.load(directory)` returns an `RBS::DefinitionBuilder` over every `.rbs` file under `directory`, the `sig/` of each Skyward gem that has registered it with `Skyward::Core::Signatures.register(path)`, and the `date` and `time` libraries. Skyward Core registers its own. A directory that doesn't exist contributes nothing. A file that doesn't parse, a name declared twice, or a class whose declarations disagree on its type parameters raises `Skyward::Core::BootError` naming the file and line.
|
|
39
|
+
- **Keeping `sig/generated` current.** `Skyward::Core::Signatures::Inline.generate(directory, rbs_inline:, capture:)` runs the rbs-inline executable at `rbs_inline` through `capture`, in `directory` and in its default opt-in mode, which reads only files marked `# rbs_inline: enabled`, over every `.rb` file there outside `test/`, `spec/`, `vendor/`, `tmp/` and hidden directories, into a scratch directory, as `skyward check` does. It then writes each file whose content differs to `directory`'s `sig/generated`, leaving the others untouched, removes each file there that rbs-inline no longer generates, and any directory that leaves empty, and returns `nil`. When rbs-inline fails, it changes nothing and returns a message with rbs-inline's output, for the command to report. With no `rbs_inline`, as in a bundle without rbs-inline, it runs nothing and returns `nil`, so the app runs with `sig/generated` as committed.
|
|
40
|
+
- **Reading RBS types.** `Skyward::Core::Types::Reader.new(builder)` takes the `RBS::DefinitionBuilder` that `Skyward::Core::Signatures.load` returns, and `read(type)` turns an RBS type into a frozen `Data` value from `Skyward::Core::Types`: a `Scalar` (`:integer`, `:float`, `:string`, `:bool`, `:date`, `:time` or `:untyped`), a `Literal` (a String, Integer, boolean or `nil`), an `Enum` of Symbols, a `Nullable`, an `ArrayOf`, a `HashOf` (a `Hash[String, T]`, of its values' type), a `Record` or `Named` class with `Field`s (a name, a type and whether it's required), or a `Union`. It expands aliases, generic ones included, reads `T?` and `T | nil` as `Nullable` and a union of symbol literals as one `Enum`, and flattens nested unions, dropping duplicates. A class is `Named` when its RBS declares public instance `attr_reader`s, rbs-inline's `Data.define` output included: its fields come from its own declarations, in written order, across every file that reopens it, skipping `private` sections. A type it can't read, such as an interface, a tuple, a proc, a `Hash` whose keys aren't `String`s or a class with no readers, comes back as an `Unreadable` naming the type, the class and reader it was found at (`Todo#tags`) and what to use instead, for the caller to raise `Skyward::Core::BootError` with its own context. A class with no loaded Ruby class, or a type that refers to itself, raises `Skyward::Core::BootError`. `type_name(klass)` finds a Ruby class's RBS declaration (none for an anonymous class), and `method_type(type_name, method)` a method's signature, raising `Skyward::Core::BootError` when RBS can't build the class.
|
|
41
|
+
- **`Skyward::Core::BootError`**, for any Skyward gem to raise when an app can't boot.
|
data/exe/skyward
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "skyward/core"
|
|
5
|
+
|
|
6
|
+
Skyward::Core::CLI.first_per_gem(Gem.find_files("skyward/*/commands.rb")).each { |file| load file }
|
|
7
|
+
exit Skyward::Core::CLI.run(ARGV, registry: Skyward::Core::CLI::REGISTRY, out: $stdout)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::CLI::Executable
|
|
4
|
+
extend self
|
|
5
|
+
|
|
6
|
+
# @rbs! type capture = ^(Hash[String, String] env, Array[String] command, String chdir) -> [String, bool]
|
|
7
|
+
|
|
8
|
+
CAPTURE = lambda do |env, command, chdir|
|
|
9
|
+
# RBS doesn't list the [:child, :out] spelling of this redirect.
|
|
10
|
+
output = IO.popen(env, command, chdir:, err: [:child, 1], &:read)
|
|
11
|
+
# RBS doesn't declare Process.last_status, set by the popen above.
|
|
12
|
+
[output, Process.last_status.success?] # steep:ignore NoMethod
|
|
13
|
+
end #: capture
|
|
14
|
+
|
|
15
|
+
# Under Bundler, Gem.find_files and Gem.bin_path see only the bundle's gems,
|
|
16
|
+
# so a gem installed outside the app's bundle isn't found. Checking first
|
|
17
|
+
# spares rescuing the error bin_path raises for a missing gem.
|
|
18
|
+
# @rbs name: String
|
|
19
|
+
# @rbs feature: String
|
|
20
|
+
# @rbs return: String?
|
|
21
|
+
def find(name, feature: name)
|
|
22
|
+
Gem.bin_path(name, name) unless Gem.find_files("#{feature}.rb").empty?
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Skyward::Core::CLI::Registry
|
|
4
|
+
# @rbs @commands: Hash[String, Command]
|
|
5
|
+
|
|
6
|
+
Command = Data.define(
|
|
7
|
+
:name, #: String
|
|
8
|
+
:description, #: String
|
|
9
|
+
:action #: ^(Array[String]) -> void
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
# @rbs return: void
|
|
13
|
+
def initialize
|
|
14
|
+
@commands = {}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# @rbs name: String
|
|
18
|
+
# @rbs description: String
|
|
19
|
+
# @rbs &action: (Array[String]) -> void
|
|
20
|
+
# @rbs return: void
|
|
21
|
+
def register(name, description, &action)
|
|
22
|
+
raise ArgumentError, "a command named #{name} is already registered" if @commands.key?(name)
|
|
23
|
+
|
|
24
|
+
@commands[name] = Command.new(name:, description:, action:)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @rbs name: String
|
|
28
|
+
# @rbs return: Command?
|
|
29
|
+
def find(name) = @commands[name]
|
|
30
|
+
|
|
31
|
+
# @rbs return: Array[Command]
|
|
32
|
+
def commands = @commands.values.sort_by(&:name)
|
|
33
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::CLI
|
|
4
|
+
extend self
|
|
5
|
+
|
|
6
|
+
REGISTRY = Registry.new #: Registry
|
|
7
|
+
|
|
8
|
+
# @rbs name: String
|
|
9
|
+
# @rbs description: String
|
|
10
|
+
# @rbs &: (Array[String]) -> void
|
|
11
|
+
# @rbs return: void
|
|
12
|
+
def register(name, description, &) = REGISTRY.register(name, description, &)
|
|
13
|
+
|
|
14
|
+
# @rbs paths: Array[String]
|
|
15
|
+
# @rbs return: Array[String]
|
|
16
|
+
def first_per_gem(paths) = paths.uniq { |path| File.basename(File.dirname(path)) }
|
|
17
|
+
|
|
18
|
+
# @rbs (Array[String] argv, registry: Registry, out: _Writer) -> Integer
|
|
19
|
+
def run(argv, registry:, out:)
|
|
20
|
+
name, *args = argv
|
|
21
|
+
case name
|
|
22
|
+
when nil, "help", "--help", "-h"
|
|
23
|
+
out.write(help(registry))
|
|
24
|
+
0
|
|
25
|
+
else
|
|
26
|
+
command = registry.find(name)
|
|
27
|
+
if command
|
|
28
|
+
command.action.call(args)
|
|
29
|
+
0
|
|
30
|
+
else
|
|
31
|
+
out.write("skyward: no command named #{name}\n", help(registry))
|
|
32
|
+
1
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
# @rbs registry: Registry
|
|
40
|
+
# @rbs return: String
|
|
41
|
+
def help(registry)
|
|
42
|
+
commands = registry.commands
|
|
43
|
+
width = commands.map { |command| command.name.length }.max || 0
|
|
44
|
+
rows = commands.map { |command| " #{command.name.ljust(width)} #{command.description}\n" }
|
|
45
|
+
["Usage: skyward COMMAND [ARGS]\n", *rows].join
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "tmpdir"
|
|
5
|
+
|
|
6
|
+
module Skyward::Core::Signatures::Inline
|
|
7
|
+
extend self
|
|
8
|
+
|
|
9
|
+
OUTPUT = "sig/generated" #: String
|
|
10
|
+
|
|
11
|
+
# None holds the app's contract: its tests, its installed gems and scratch.
|
|
12
|
+
UNCHECKED = %w[test spec vendor tmp].freeze #: Array[String]
|
|
13
|
+
|
|
14
|
+
# rbs-inline writes to scratch, so a file it no longer generates can be
|
|
15
|
+
# removed, and only a file whose content changed is written: skyward serve
|
|
16
|
+
# reloads on every .rbs file written.
|
|
17
|
+
# @rbs directory: String
|
|
18
|
+
# @rbs rbs_inline: String?
|
|
19
|
+
# @rbs capture: Skyward::Core::CLI::Executable::capture
|
|
20
|
+
# @rbs return: String?
|
|
21
|
+
def generate(directory, rbs_inline:, capture:)
|
|
22
|
+
return unless rbs_inline
|
|
23
|
+
|
|
24
|
+
files = run(directory, rbs_inline:, capture:)
|
|
25
|
+
case files
|
|
26
|
+
when String then "rbs-inline couldn't regenerate #{OUTPUT}:\n#{files}"
|
|
27
|
+
else
|
|
28
|
+
write(File.join(directory, OUTPUT), files)
|
|
29
|
+
nil
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @rbs directory: String
|
|
34
|
+
# @rbs rbs_inline: String
|
|
35
|
+
# @rbs capture: Skyward::Core::CLI::Executable::capture
|
|
36
|
+
# @rbs return: Hash[String, String] | String
|
|
37
|
+
def run(directory, rbs_inline:, capture:)
|
|
38
|
+
Dir.mktmpdir("skyward-signatures") do |output|
|
|
39
|
+
log, ok = capture.call({}, [Gem.ruby, rbs_inline, "--output=#{output}", *sources(directory)], directory)
|
|
40
|
+
ok ? rbs_files(output) : log
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @rbs directory: String
|
|
45
|
+
# @rbs return: Array[String]
|
|
46
|
+
def sources(directory)
|
|
47
|
+
roots = Dir.glob("*/", base: directory).map { |root| root.delete_suffix("/") } - UNCHECKED
|
|
48
|
+
files = Dir.glob("*.rb", base: directory)
|
|
49
|
+
[*files, *roots.reject { |root| Dir.glob("#{root}/**/*.rb", base: directory).empty? }].sort
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @rbs directory: String
|
|
53
|
+
# @rbs return: Hash[String, String]
|
|
54
|
+
def rbs_files(directory)
|
|
55
|
+
Dir.glob("**/*.rbs", base: directory).to_h { |file| [file, File.read(File.join(directory, file))] }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
# @rbs generated: String
|
|
61
|
+
# @rbs files: Hash[String, String]
|
|
62
|
+
# @rbs return: void
|
|
63
|
+
def write(generated, files)
|
|
64
|
+
current = rbs_files(generated)
|
|
65
|
+
files.reject { |file, source| current[file] == source }.each do |file, source|
|
|
66
|
+
path = File.join(generated, file)
|
|
67
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
68
|
+
File.write(path, source)
|
|
69
|
+
end
|
|
70
|
+
(current.keys - files.keys).each { |file| File.delete(File.join(generated, file)) }
|
|
71
|
+
# Deepest first, so a directory emptied of directories goes too.
|
|
72
|
+
Dir.glob("**/*/", base: generated).sort.reverse_each do |dir|
|
|
73
|
+
path = File.join(generated, dir)
|
|
74
|
+
Dir.rmdir(path) if Dir.empty?(path)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rbs"
|
|
4
|
+
|
|
5
|
+
class Skyward::Core::Signatures::Loader
|
|
6
|
+
# @rbs @gems: Array[String]
|
|
7
|
+
|
|
8
|
+
# @rbs return: void
|
|
9
|
+
def initialize
|
|
10
|
+
@gems = []
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @rbs path: String
|
|
14
|
+
# @rbs return: void
|
|
15
|
+
def register(path)
|
|
16
|
+
@gems |= [File.expand_path(path)]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# @rbs directory: String
|
|
20
|
+
# @rbs return: RBS::DefinitionBuilder
|
|
21
|
+
def load(directory)
|
|
22
|
+
loader = RBS::EnvironmentLoader.new
|
|
23
|
+
[directory, *@gems].each { |path| loader.add(path: Pathname(path)) }
|
|
24
|
+
%w[date time].each { |library| loader.add(library:, version: nil) }
|
|
25
|
+
env = RBS::Environment.from_loader(loader).resolve_type_names
|
|
26
|
+
# RBS otherwise defers this conflict until a definition is built, past boot.
|
|
27
|
+
env.validate_type_params
|
|
28
|
+
RBS::DefinitionBuilder.new(env:)
|
|
29
|
+
rescue RBS::DuplicatedDeclarationError => e
|
|
30
|
+
locations = e.decls.map { |decl| RBS::Location.to_string(decl.location) }
|
|
31
|
+
raise Skyward::Core::BootError, "Can't load the RBS signatures: #{e.name} is declared at #{locations.join(" and ")}"
|
|
32
|
+
rescue RBS::ParsingError, RBS::GenericParameterMismatchError => e
|
|
33
|
+
raise Skyward::Core::BootError, "Can't load the RBS signatures: #{e.message}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::Signatures
|
|
4
|
+
extend self
|
|
5
|
+
|
|
6
|
+
# One for the process, so the sig/ each Skyward gem registers when required
|
|
7
|
+
# is in every load the app boots from.
|
|
8
|
+
LOADER = Loader.new #: Loader
|
|
9
|
+
|
|
10
|
+
# @rbs path: String
|
|
11
|
+
# @rbs return: void
|
|
12
|
+
def register(path) = LOADER.register(path)
|
|
13
|
+
|
|
14
|
+
# @rbs directory: String
|
|
15
|
+
# @rbs return: RBS::DefinitionBuilder
|
|
16
|
+
def load(directory) = LOADER.load(directory)
|
|
17
|
+
end
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Skyward::Core::Types::Reader
|
|
4
|
+
# @rbs @builder: RBS::DefinitionBuilder
|
|
5
|
+
|
|
6
|
+
SCALARS = {
|
|
7
|
+
"::Integer" => :integer,
|
|
8
|
+
"::Float" => :float,
|
|
9
|
+
"::String" => :string,
|
|
10
|
+
"::Date" => :date,
|
|
11
|
+
"::Time" => :time
|
|
12
|
+
}.freeze #: Hash[String, Skyward::Core::Types::scalar]
|
|
13
|
+
|
|
14
|
+
NIL_LITERAL = Skyward::Core::Types::Literal.new(value: nil) #: Skyward::Core::Types::Literal
|
|
15
|
+
|
|
16
|
+
# @rbs builder: RBS::DefinitionBuilder
|
|
17
|
+
# @rbs return: void
|
|
18
|
+
def initialize(builder)
|
|
19
|
+
@builder = builder
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# @rbs type: RBS::Types::t
|
|
23
|
+
# @rbs return: Skyward::Core::Types::result
|
|
24
|
+
def read(type) = read_within(type, [])
|
|
25
|
+
|
|
26
|
+
# @rbs klass: Module
|
|
27
|
+
# @rbs return: RBS::TypeName?
|
|
28
|
+
def type_name(klass)
|
|
29
|
+
# An anonymous class has no name, whatever Module#name's signature says.
|
|
30
|
+
return if klass.name.to_s.empty?
|
|
31
|
+
|
|
32
|
+
type_name = RBS::TypeName.parse("::#{klass.name}")
|
|
33
|
+
type_name if @builder.env.class_decl?(type_name)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @rbs type_name: RBS::TypeName
|
|
37
|
+
# @rbs method_name: Symbol
|
|
38
|
+
# @rbs return: RBS::MethodType?
|
|
39
|
+
def method_type(type_name, method_name)
|
|
40
|
+
@builder.build_instance(type_name).methods[method_name]&.method_types&.first
|
|
41
|
+
rescue RBS::DefinitionError => e
|
|
42
|
+
raise Skyward::Core::BootError, "Can't read the RBS signatures: #{e.message}"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
# @rbs type: RBS::Types::t
|
|
48
|
+
# @rbs path: Array[String]
|
|
49
|
+
# @rbs return: Skyward::Core::Types::result
|
|
50
|
+
def read_within(type, path)
|
|
51
|
+
case type
|
|
52
|
+
when RBS::Types::Bases::Bool then Skyward::Core::Types::Scalar.new(name: :bool)
|
|
53
|
+
when RBS::Types::Bases::Any then Skyward::Core::Types::Scalar.new(name: :untyped)
|
|
54
|
+
when RBS::Types::Bases::Nil then NIL_LITERAL
|
|
55
|
+
when RBS::Types::Literal then literal(type.literal)
|
|
56
|
+
when RBS::Types::Optional
|
|
57
|
+
all_readable([read_within(type.type, path), NIL_LITERAL]) { |members| union(members) }
|
|
58
|
+
when RBS::Types::Union
|
|
59
|
+
all_readable(type.types.map { |member| read_within(member, path) }) { |members| union(members) }
|
|
60
|
+
when RBS::Types::Alias then alias_type(type, path)
|
|
61
|
+
when RBS::Types::Record then record(type, path)
|
|
62
|
+
when RBS::Types::ClassInstance then instance(type, path)
|
|
63
|
+
when RBS::Types::Tuple then unreadable(type, "Array[T], or a record")
|
|
64
|
+
else unreadable(type)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# @rbs value: RBS::Types::Literal::literal
|
|
69
|
+
# @rbs return: Skyward::Core::Types::t
|
|
70
|
+
def literal(value)
|
|
71
|
+
case value
|
|
72
|
+
when Symbol then Skyward::Core::Types::Enum.new(symbols: [value])
|
|
73
|
+
else Skyward::Core::Types::Literal.new(value:)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# @rbs types: Array[Skyward::Core::Types::t]
|
|
78
|
+
# @rbs return: Skyward::Core::Types::t
|
|
79
|
+
def union(types)
|
|
80
|
+
members = types.flat_map { |type| flatten(type) }.uniq
|
|
81
|
+
enums = members.filter_map { |member| member.is_a?(Skyward::Core::Types::Enum) ? member : nil }
|
|
82
|
+
if members.size == 1 then members.fetch(0)
|
|
83
|
+
elsif members.include?(NIL_LITERAL) then Skyward::Core::Types::Nullable.new(type: union(members - [NIL_LITERAL]))
|
|
84
|
+
elsif enums.size == members.size then Skyward::Core::Types::Enum.new(symbols: enums.flat_map(&:symbols).uniq)
|
|
85
|
+
else Skyward::Core::Types::Union.new(types: members)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# @rbs type: Skyward::Core::Types::t
|
|
90
|
+
# @rbs return: Array[Skyward::Core::Types::t]
|
|
91
|
+
def flatten(type)
|
|
92
|
+
case type
|
|
93
|
+
when Skyward::Core::Types::Union then type.types
|
|
94
|
+
when Skyward::Core::Types::Nullable then [type.type, NIL_LITERAL]
|
|
95
|
+
else [type]
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# @rbs type: RBS::Types::Alias
|
|
100
|
+
# @rbs path: Array[String]
|
|
101
|
+
# @rbs return: Skyward::Core::Types::result
|
|
102
|
+
def alias_type(type, path)
|
|
103
|
+
read_within(@builder.expand_alias2(type.name, type.args), enter(written(type), path))
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# @rbs type: RBS::Types::Record
|
|
107
|
+
# @rbs path: Array[String]
|
|
108
|
+
# @rbs return: Skyward::Core::Types::result
|
|
109
|
+
def record(type, path)
|
|
110
|
+
keys = type.all_fields.map { |key, (_, required)| [key.to_s.to_sym, required] } #: Array[[Symbol, bool]]
|
|
111
|
+
results = type.all_fields.values.map { |(field_type, _)| read_within(field_type, path) }
|
|
112
|
+
all_readable(results) { |types| Skyward::Core::Types::Record.new(fields: fields(keys, types)) }
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# @rbs type: RBS::Types::ClassInstance
|
|
116
|
+
# @rbs path: Array[String]
|
|
117
|
+
# @rbs return: Skyward::Core::Types::result
|
|
118
|
+
def instance(type, path)
|
|
119
|
+
name = type.name.to_s
|
|
120
|
+
scalar = SCALARS.fetch(name, nil)
|
|
121
|
+
if scalar then Skyward::Core::Types::Scalar.new(name: scalar)
|
|
122
|
+
elsif name == "::Array" && type.args.size != 1 then unreadable(type, "Array[T]")
|
|
123
|
+
elsif name == "::Array"
|
|
124
|
+
all_readable(type.args.map { |arg| read_within(arg, path) }) do |items|
|
|
125
|
+
Skyward::Core::Types::ArrayOf.new(type: items.fetch(0))
|
|
126
|
+
end
|
|
127
|
+
elsif name == "::Hash" then hash_of(type, path)
|
|
128
|
+
else named(type, path)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# @rbs type: RBS::Types::ClassInstance
|
|
133
|
+
# @rbs path: Array[String]
|
|
134
|
+
# @rbs return: Skyward::Core::Types::result
|
|
135
|
+
def hash_of(type, path)
|
|
136
|
+
key, *values = type.args.map { |arg| read_within(arg, path) }
|
|
137
|
+
unless key == Skyward::Core::Types::Scalar.new(name: :string) && values.size == 1
|
|
138
|
+
return unreadable(type, "Hash[String, T] (only String keys are supported)")
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
all_readable(values) { |read| Skyward::Core::Types::HashOf.new(type: read.fetch(0)) }
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# @rbs type: RBS::Types::ClassInstance
|
|
145
|
+
# @rbs path: Array[String]
|
|
146
|
+
# @rbs return: Skyward::Core::Types::result
|
|
147
|
+
def named(type, path)
|
|
148
|
+
readers = public_readers(type.name)
|
|
149
|
+
return unreadable(type) if readers.empty?
|
|
150
|
+
|
|
151
|
+
name = written(type.name)
|
|
152
|
+
klass = ruby_class(name)
|
|
153
|
+
within = enter(name, path)
|
|
154
|
+
keys = readers.map { |reader| [reader.name, true] } #: Array[[Symbol, bool]]
|
|
155
|
+
results = readers.map { |reader| locate(read_within(reader.type, within), "#{name}##{reader.name}") }
|
|
156
|
+
all_readable(results) { |types| Skyward::Core::Types::Named.new(name:, klass:, fields: fields(keys, types)) }
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# @rbs type_name: RBS::TypeName
|
|
160
|
+
# @rbs return: Array[RBS::AST::Members::AttrReader]
|
|
161
|
+
def public_readers(type_name)
|
|
162
|
+
entry = @builder.env.class_entry(type_name, normalized: true)
|
|
163
|
+
return [] unless entry
|
|
164
|
+
|
|
165
|
+
entry.each_decl.flat_map do |decl|
|
|
166
|
+
case decl
|
|
167
|
+
when RBS::AST::Declarations::Class then declared_public_readers(decl)
|
|
168
|
+
else []
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# @rbs decl: RBS::AST::Declarations::Class
|
|
174
|
+
# @rbs return: Array[RBS::AST::Members::AttrReader]
|
|
175
|
+
def declared_public_readers(decl)
|
|
176
|
+
sections = decl.members.slice_before do |member|
|
|
177
|
+
member.is_a?(RBS::AST::Members::Public) || member.is_a?(RBS::AST::Members::Private)
|
|
178
|
+
end
|
|
179
|
+
sections.flat_map do |section|
|
|
180
|
+
default = section.first.is_a?(RBS::AST::Members::Private) ? :private : :public
|
|
181
|
+
section.filter_map do |member|
|
|
182
|
+
next unless member.is_a?(RBS::AST::Members::AttrReader) && member.kind == :instance
|
|
183
|
+
|
|
184
|
+
member if (member.visibility || default) == :public
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
# @rbs name: String
|
|
190
|
+
# @rbs return: Class
|
|
191
|
+
def ruby_class(name)
|
|
192
|
+
found = Object.const_get(name) if Object.const_defined?(name)
|
|
193
|
+
return found if found.is_a?(Class)
|
|
194
|
+
|
|
195
|
+
raise Skyward::Core::BootError, "#{name} has an RBS signature, but no Ruby class is loaded with that name"
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# @rbs name: String
|
|
199
|
+
# @rbs path: Array[String]
|
|
200
|
+
# @rbs return: Array[String]
|
|
201
|
+
def enter(name, path)
|
|
202
|
+
return [*path, name] unless path.include?(name)
|
|
203
|
+
|
|
204
|
+
cycle = [*path.drop_while { |entered| entered != name }, name]
|
|
205
|
+
raise Skyward::Core::BootError, "Can't read #{name}: it refers to itself through #{cycle.join(" -> ")}"
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# @rbs keys: Array[[Symbol, bool]]
|
|
209
|
+
# @rbs types: Array[Skyward::Core::Types::t]
|
|
210
|
+
# @rbs return: Array[Skyward::Core::Types::Field]
|
|
211
|
+
def fields(keys, types)
|
|
212
|
+
keys.each_with_index.map do |(name, required), index|
|
|
213
|
+
Skyward::Core::Types::Field.new(name:, type: types.fetch(index), required:)
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# @rbs result: Skyward::Core::Types::result
|
|
218
|
+
# @rbs at: String
|
|
219
|
+
# @rbs return: Skyward::Core::Types::result
|
|
220
|
+
def locate(result, at)
|
|
221
|
+
case result
|
|
222
|
+
when Skyward::Core::Types::Unreadable then result.at ? result : result.with(at:)
|
|
223
|
+
else result
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
# @rbs results: Array[Skyward::Core::Types::result]
|
|
228
|
+
# @rbs &: (Array[Skyward::Core::Types::t]) -> Skyward::Core::Types::result
|
|
229
|
+
# @rbs return: Skyward::Core::Types::result
|
|
230
|
+
def all_readable(results)
|
|
231
|
+
results.find { |result| result.is_a?(Skyward::Core::Types::Unreadable) } ||
|
|
232
|
+
yield(results.filter_map { |result| result.is_a?(Skyward::Core::Types::Unreadable) ? nil : result })
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
# @rbs type: RBS::Types::t
|
|
236
|
+
# @rbs instead: String
|
|
237
|
+
# @rbs return: Skyward::Core::Types::Unreadable
|
|
238
|
+
def unreadable(type, instead = "a record, or a class with public typed attr_readers")
|
|
239
|
+
Skyward::Core::Types::Unreadable.new(type: written(type), at: nil, instead:)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# @rbs (_ToS name) -> String
|
|
243
|
+
def written(name) = name.to_s.gsub(/(?<!\w)::/, "")
|
|
244
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::Types
|
|
4
|
+
# @rbs!
|
|
5
|
+
# type scalar = :integer | :float | :string | :bool | :date | :time | :untyped
|
|
6
|
+
# type literal = String | Integer | bool | nil
|
|
7
|
+
# type t = Scalar | Literal | Enum | Nullable | ArrayOf | HashOf | Record | Named | Union
|
|
8
|
+
# type result = t | Unreadable
|
|
9
|
+
|
|
10
|
+
Scalar = Data.define(
|
|
11
|
+
:name #: scalar
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
Literal = Data.define(
|
|
15
|
+
:value #: literal
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
Enum = Data.define(
|
|
19
|
+
:symbols #: Array[Symbol]
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
Nullable = Data.define(
|
|
23
|
+
:type #: t
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
ArrayOf = Data.define(
|
|
27
|
+
:type #: t
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
HashOf = Data.define(
|
|
31
|
+
:type #: t
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
Field = Data.define(
|
|
35
|
+
:name, #: Symbol
|
|
36
|
+
:type, #: t
|
|
37
|
+
:required #: bool
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
Record = Data.define(
|
|
41
|
+
:fields #: Array[Field]
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
Named = Data.define(
|
|
45
|
+
:name, #: String
|
|
46
|
+
:klass, #: Class
|
|
47
|
+
:fields #: Array[Field]
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
Union = Data.define(
|
|
51
|
+
:types #: Array[t]
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
Unreadable = Data.define(
|
|
55
|
+
:type, #: String
|
|
56
|
+
:at, #: String?
|
|
57
|
+
:instead #: String
|
|
58
|
+
)
|
|
59
|
+
end
|
data/lib/skyward/core/version.rb
CHANGED
data/lib/skyward/core.rb
CHANGED
|
@@ -6,4 +6,10 @@ require_relative "core/version"
|
|
|
6
6
|
# Skyward Core owns the Skyward namespace: its version.rb opens it, and every
|
|
7
7
|
# Skyward gem's loader, this one included, extends it.
|
|
8
8
|
loader = Zeitwerk::Loader.for_gem_extension(Skyward)
|
|
9
|
+
loader.inflector.inflect("cli" => "CLI")
|
|
10
|
+
# The skyward executable loads it, and it defines no constant.
|
|
11
|
+
loader.ignore("#{__dir__}/core/commands.rb")
|
|
9
12
|
loader.setup
|
|
13
|
+
|
|
14
|
+
dir = __dir__ #: String
|
|
15
|
+
Skyward::Core::Signatures.register(File.expand_path("../../sig", dir))
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Generated from lib/skyward/core/cli/executable.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::CLI::Executable
|
|
4
|
+
type capture = ^(Hash[String, String] env, Array[String] command, String chdir) -> [ String, bool ]
|
|
5
|
+
|
|
6
|
+
CAPTURE: capture
|
|
7
|
+
|
|
8
|
+
# Under Bundler, Gem.find_files and Gem.bin_path see only the bundle's gems,
|
|
9
|
+
# so a gem installed outside the app's bundle isn't found. Checking first
|
|
10
|
+
# spares rescuing the error bin_path raises for a missing gem.
|
|
11
|
+
# @rbs name: String
|
|
12
|
+
# @rbs feature: String
|
|
13
|
+
# @rbs return: String?
|
|
14
|
+
def find: (String name, ?feature: String) -> String?
|
|
15
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Generated from lib/skyward/core/cli/registry.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
class Skyward::Core::CLI::Registry
|
|
4
|
+
@commands: Hash[String, Command]
|
|
5
|
+
|
|
6
|
+
class Command < Data
|
|
7
|
+
attr_reader name(): String
|
|
8
|
+
|
|
9
|
+
attr_reader description(): String
|
|
10
|
+
|
|
11
|
+
attr_reader action(): ^(Array[String]) -> void
|
|
12
|
+
|
|
13
|
+
def self.new: (String name, String description, ^(Array[String]) -> void action) -> instance
|
|
14
|
+
| (name: String, description: String, action: ^(Array[String]) -> void) -> instance
|
|
15
|
+
|
|
16
|
+
def self.members: () -> [ :name, :description, :action ]
|
|
17
|
+
|
|
18
|
+
def members: () -> [ :name, :description, :action ]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @rbs return: void
|
|
22
|
+
def initialize: () -> void
|
|
23
|
+
|
|
24
|
+
# @rbs name: String
|
|
25
|
+
# @rbs description: String
|
|
26
|
+
# @rbs &action: (Array[String]) -> void
|
|
27
|
+
# @rbs return: void
|
|
28
|
+
def register: (String name, String description) { (Array[String]) -> void } -> void
|
|
29
|
+
|
|
30
|
+
# @rbs name: String
|
|
31
|
+
# @rbs return: Command?
|
|
32
|
+
def find: (String name) -> Command?
|
|
33
|
+
|
|
34
|
+
# @rbs return: Array[Command]
|
|
35
|
+
def commands: () -> Array[Command]
|
|
36
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Generated from lib/skyward/core/cli.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::CLI
|
|
4
|
+
REGISTRY: Registry
|
|
5
|
+
|
|
6
|
+
# @rbs name: String
|
|
7
|
+
# @rbs description: String
|
|
8
|
+
# @rbs &: (Array[String]) -> void
|
|
9
|
+
# @rbs return: void
|
|
10
|
+
def register: (String name, String description) { (Array[String]) -> void } -> void
|
|
11
|
+
|
|
12
|
+
# @rbs paths: Array[String]
|
|
13
|
+
# @rbs return: Array[String]
|
|
14
|
+
def first_per_gem: (Array[String] paths) -> Array[String]
|
|
15
|
+
|
|
16
|
+
# @rbs (Array[String] argv, registry: Registry, out: _Writer) -> Integer
|
|
17
|
+
def run: (Array[String] argv, registry: Registry, out: _Writer) -> Integer
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
# @rbs registry: Registry
|
|
22
|
+
# @rbs return: String
|
|
23
|
+
def help: (Registry registry) -> String
|
|
24
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Generated from lib/skyward/core/signatures/inline.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::Signatures::Inline
|
|
4
|
+
OUTPUT: String
|
|
5
|
+
|
|
6
|
+
# None holds the app's contract: its tests, its installed gems and scratch.
|
|
7
|
+
UNCHECKED: Array[String]
|
|
8
|
+
|
|
9
|
+
# rbs-inline writes to scratch, so a file it no longer generates can be
|
|
10
|
+
# removed, and only a file whose content changed is written: skyward serve
|
|
11
|
+
# reloads on every .rbs file written.
|
|
12
|
+
# @rbs directory: String
|
|
13
|
+
# @rbs rbs_inline: String?
|
|
14
|
+
# @rbs capture: Skyward::Core::CLI::Executable::capture
|
|
15
|
+
# @rbs return: String?
|
|
16
|
+
def generate: (String directory, rbs_inline: String?, capture: Skyward::Core::CLI::Executable::capture) -> String?
|
|
17
|
+
|
|
18
|
+
# @rbs directory: String
|
|
19
|
+
# @rbs rbs_inline: String
|
|
20
|
+
# @rbs capture: Skyward::Core::CLI::Executable::capture
|
|
21
|
+
# @rbs return: Hash[String, String] | String
|
|
22
|
+
def run: (String directory, rbs_inline: String, capture: Skyward::Core::CLI::Executable::capture) -> (Hash[String, String] | String)
|
|
23
|
+
|
|
24
|
+
# @rbs directory: String
|
|
25
|
+
# @rbs return: Array[String]
|
|
26
|
+
def sources: (String directory) -> Array[String]
|
|
27
|
+
|
|
28
|
+
# @rbs directory: String
|
|
29
|
+
# @rbs return: Hash[String, String]
|
|
30
|
+
def rbs_files: (String directory) -> Hash[String, String]
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
# @rbs generated: String
|
|
35
|
+
# @rbs files: Hash[String, String]
|
|
36
|
+
# @rbs return: void
|
|
37
|
+
def write: (String generated, Hash[String, String] files) -> void
|
|
38
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Generated from lib/skyward/core/signatures/loader.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
class Skyward::Core::Signatures::Loader
|
|
4
|
+
@gems: Array[String]
|
|
5
|
+
|
|
6
|
+
# @rbs return: void
|
|
7
|
+
def initialize: () -> void
|
|
8
|
+
|
|
9
|
+
# @rbs path: String
|
|
10
|
+
# @rbs return: void
|
|
11
|
+
def register: (String path) -> void
|
|
12
|
+
|
|
13
|
+
# @rbs directory: String
|
|
14
|
+
# @rbs return: RBS::DefinitionBuilder
|
|
15
|
+
def load: (String directory) -> RBS::DefinitionBuilder
|
|
16
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Generated from lib/skyward/core/signatures.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::Signatures
|
|
4
|
+
# One for the process, so the sig/ each Skyward gem registers when required
|
|
5
|
+
# is in every load the app boots from.
|
|
6
|
+
LOADER: Loader
|
|
7
|
+
|
|
8
|
+
# @rbs path: String
|
|
9
|
+
# @rbs return: void
|
|
10
|
+
def register: (String path) -> void
|
|
11
|
+
|
|
12
|
+
# @rbs directory: String
|
|
13
|
+
# @rbs return: RBS::DefinitionBuilder
|
|
14
|
+
def load: (String directory) -> RBS::DefinitionBuilder
|
|
15
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Generated from lib/skyward/core/types/reader.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
class Skyward::Core::Types::Reader
|
|
4
|
+
@builder: RBS::DefinitionBuilder
|
|
5
|
+
|
|
6
|
+
SCALARS: Hash[String, Skyward::Core::Types::scalar]
|
|
7
|
+
|
|
8
|
+
NIL_LITERAL: Skyward::Core::Types::Literal
|
|
9
|
+
|
|
10
|
+
# @rbs builder: RBS::DefinitionBuilder
|
|
11
|
+
# @rbs return: void
|
|
12
|
+
def initialize: (RBS::DefinitionBuilder builder) -> void
|
|
13
|
+
|
|
14
|
+
# @rbs type: RBS::Types::t
|
|
15
|
+
# @rbs return: Skyward::Core::Types::result
|
|
16
|
+
def read: (RBS::Types::t type) -> Skyward::Core::Types::result
|
|
17
|
+
|
|
18
|
+
# @rbs klass: Module
|
|
19
|
+
# @rbs return: RBS::TypeName?
|
|
20
|
+
def type_name: (Module klass) -> RBS::TypeName?
|
|
21
|
+
|
|
22
|
+
# @rbs type_name: RBS::TypeName
|
|
23
|
+
# @rbs method_name: Symbol
|
|
24
|
+
# @rbs return: RBS::MethodType?
|
|
25
|
+
def method_type: (RBS::TypeName type_name, Symbol method_name) -> RBS::MethodType?
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
# @rbs type: RBS::Types::t
|
|
30
|
+
# @rbs path: Array[String]
|
|
31
|
+
# @rbs return: Skyward::Core::Types::result
|
|
32
|
+
def read_within: (RBS::Types::t type, Array[String] path) -> Skyward::Core::Types::result
|
|
33
|
+
|
|
34
|
+
# @rbs value: RBS::Types::Literal::literal
|
|
35
|
+
# @rbs return: Skyward::Core::Types::t
|
|
36
|
+
def literal: (RBS::Types::Literal::literal value) -> Skyward::Core::Types::t
|
|
37
|
+
|
|
38
|
+
# @rbs types: Array[Skyward::Core::Types::t]
|
|
39
|
+
# @rbs return: Skyward::Core::Types::t
|
|
40
|
+
def union: (Array[Skyward::Core::Types::t] types) -> Skyward::Core::Types::t
|
|
41
|
+
|
|
42
|
+
# @rbs type: Skyward::Core::Types::t
|
|
43
|
+
# @rbs return: Array[Skyward::Core::Types::t]
|
|
44
|
+
def flatten: (Skyward::Core::Types::t type) -> Array[Skyward::Core::Types::t]
|
|
45
|
+
|
|
46
|
+
# @rbs type: RBS::Types::Alias
|
|
47
|
+
# @rbs path: Array[String]
|
|
48
|
+
# @rbs return: Skyward::Core::Types::result
|
|
49
|
+
def alias_type: (RBS::Types::Alias type, Array[String] path) -> Skyward::Core::Types::result
|
|
50
|
+
|
|
51
|
+
# @rbs type: RBS::Types::Record
|
|
52
|
+
# @rbs path: Array[String]
|
|
53
|
+
# @rbs return: Skyward::Core::Types::result
|
|
54
|
+
def record: (RBS::Types::Record type, Array[String] path) -> Skyward::Core::Types::result
|
|
55
|
+
|
|
56
|
+
# @rbs type: RBS::Types::ClassInstance
|
|
57
|
+
# @rbs path: Array[String]
|
|
58
|
+
# @rbs return: Skyward::Core::Types::result
|
|
59
|
+
def instance: (RBS::Types::ClassInstance type, Array[String] path) -> Skyward::Core::Types::result
|
|
60
|
+
|
|
61
|
+
# @rbs type: RBS::Types::ClassInstance
|
|
62
|
+
# @rbs path: Array[String]
|
|
63
|
+
# @rbs return: Skyward::Core::Types::result
|
|
64
|
+
def hash_of: (RBS::Types::ClassInstance type, Array[String] path) -> Skyward::Core::Types::result
|
|
65
|
+
|
|
66
|
+
# @rbs type: RBS::Types::ClassInstance
|
|
67
|
+
# @rbs path: Array[String]
|
|
68
|
+
# @rbs return: Skyward::Core::Types::result
|
|
69
|
+
def named: (RBS::Types::ClassInstance type, Array[String] path) -> Skyward::Core::Types::result
|
|
70
|
+
|
|
71
|
+
# @rbs type_name: RBS::TypeName
|
|
72
|
+
# @rbs return: Array[RBS::AST::Members::AttrReader]
|
|
73
|
+
def public_readers: (RBS::TypeName type_name) -> Array[RBS::AST::Members::AttrReader]
|
|
74
|
+
|
|
75
|
+
# @rbs decl: RBS::AST::Declarations::Class
|
|
76
|
+
# @rbs return: Array[RBS::AST::Members::AttrReader]
|
|
77
|
+
def declared_public_readers: (RBS::AST::Declarations::Class decl) -> Array[RBS::AST::Members::AttrReader]
|
|
78
|
+
|
|
79
|
+
# @rbs name: String
|
|
80
|
+
# @rbs return: Class
|
|
81
|
+
def ruby_class: (String name) -> Class
|
|
82
|
+
|
|
83
|
+
# @rbs name: String
|
|
84
|
+
# @rbs path: Array[String]
|
|
85
|
+
# @rbs return: Array[String]
|
|
86
|
+
def enter: (String name, Array[String] path) -> Array[String]
|
|
87
|
+
|
|
88
|
+
# @rbs keys: Array[[Symbol, bool]]
|
|
89
|
+
# @rbs types: Array[Skyward::Core::Types::t]
|
|
90
|
+
# @rbs return: Array[Skyward::Core::Types::Field]
|
|
91
|
+
def fields: (Array[[ Symbol, bool ]] keys, Array[Skyward::Core::Types::t] types) -> Array[Skyward::Core::Types::Field]
|
|
92
|
+
|
|
93
|
+
# @rbs result: Skyward::Core::Types::result
|
|
94
|
+
# @rbs at: String
|
|
95
|
+
# @rbs return: Skyward::Core::Types::result
|
|
96
|
+
def locate: (Skyward::Core::Types::result result, String at) -> Skyward::Core::Types::result
|
|
97
|
+
|
|
98
|
+
# @rbs results: Array[Skyward::Core::Types::result]
|
|
99
|
+
# @rbs &: (Array[Skyward::Core::Types::t]) -> Skyward::Core::Types::result
|
|
100
|
+
# @rbs return: Skyward::Core::Types::result
|
|
101
|
+
def all_readable: (Array[Skyward::Core::Types::result] results) { (Array[Skyward::Core::Types::t]) -> Skyward::Core::Types::result } -> Skyward::Core::Types::result
|
|
102
|
+
|
|
103
|
+
# @rbs type: RBS::Types::t
|
|
104
|
+
# @rbs instead: String
|
|
105
|
+
# @rbs return: Skyward::Core::Types::Unreadable
|
|
106
|
+
def unreadable: (RBS::Types::t type, ?String instead) -> Skyward::Core::Types::Unreadable
|
|
107
|
+
|
|
108
|
+
# @rbs (_ToS name) -> String
|
|
109
|
+
def written: (_ToS name) -> String
|
|
110
|
+
end
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Generated from lib/skyward/core/types.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::Types
|
|
4
|
+
type scalar = :integer | :float | :string | :bool | :date | :time | :untyped
|
|
5
|
+
|
|
6
|
+
type literal = String | Integer | bool | nil
|
|
7
|
+
|
|
8
|
+
type t = Scalar | Literal | Enum | Nullable | ArrayOf | HashOf | Record | Named | Union
|
|
9
|
+
|
|
10
|
+
type result = t | Unreadable
|
|
11
|
+
|
|
12
|
+
class Scalar < Data
|
|
13
|
+
attr_reader name(): scalar
|
|
14
|
+
|
|
15
|
+
def self.new: (scalar name) -> instance
|
|
16
|
+
| (name: scalar) -> instance
|
|
17
|
+
|
|
18
|
+
def self.members: () -> [ :name ]
|
|
19
|
+
|
|
20
|
+
def members: () -> [ :name ]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class Literal < Data
|
|
24
|
+
attr_reader value(): literal
|
|
25
|
+
|
|
26
|
+
def self.new: (literal value) -> instance
|
|
27
|
+
| (value: literal) -> instance
|
|
28
|
+
|
|
29
|
+
def self.members: () -> [ :value ]
|
|
30
|
+
|
|
31
|
+
def members: () -> [ :value ]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class Enum < Data
|
|
35
|
+
attr_reader symbols(): Array[Symbol]
|
|
36
|
+
|
|
37
|
+
def self.new: (Array[Symbol] symbols) -> instance
|
|
38
|
+
| (symbols: Array[Symbol]) -> instance
|
|
39
|
+
|
|
40
|
+
def self.members: () -> [ :symbols ]
|
|
41
|
+
|
|
42
|
+
def members: () -> [ :symbols ]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
class Nullable < Data
|
|
46
|
+
attr_reader type(): t
|
|
47
|
+
|
|
48
|
+
def self.new: (t type) -> instance
|
|
49
|
+
| (type: t) -> instance
|
|
50
|
+
|
|
51
|
+
def self.members: () -> [ :type ]
|
|
52
|
+
|
|
53
|
+
def members: () -> [ :type ]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
class ArrayOf < Data
|
|
57
|
+
attr_reader type(): t
|
|
58
|
+
|
|
59
|
+
def self.new: (t type) -> instance
|
|
60
|
+
| (type: t) -> instance
|
|
61
|
+
|
|
62
|
+
def self.members: () -> [ :type ]
|
|
63
|
+
|
|
64
|
+
def members: () -> [ :type ]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
class HashOf < Data
|
|
68
|
+
attr_reader type(): t
|
|
69
|
+
|
|
70
|
+
def self.new: (t type) -> instance
|
|
71
|
+
| (type: t) -> instance
|
|
72
|
+
|
|
73
|
+
def self.members: () -> [ :type ]
|
|
74
|
+
|
|
75
|
+
def members: () -> [ :type ]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
class Field < Data
|
|
79
|
+
attr_reader name(): Symbol
|
|
80
|
+
|
|
81
|
+
attr_reader type(): t
|
|
82
|
+
|
|
83
|
+
attr_reader required(): bool
|
|
84
|
+
|
|
85
|
+
def self.new: (Symbol name, t type, bool required) -> instance
|
|
86
|
+
| (name: Symbol, type: t, required: bool) -> instance
|
|
87
|
+
|
|
88
|
+
def self.members: () -> [ :name, :type, :required ]
|
|
89
|
+
|
|
90
|
+
def members: () -> [ :name, :type, :required ]
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
class Record < Data
|
|
94
|
+
attr_reader fields(): Array[Field]
|
|
95
|
+
|
|
96
|
+
def self.new: (Array[Field] fields) -> instance
|
|
97
|
+
| (fields: Array[Field]) -> instance
|
|
98
|
+
|
|
99
|
+
def self.members: () -> [ :fields ]
|
|
100
|
+
|
|
101
|
+
def members: () -> [ :fields ]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
class Named < Data
|
|
105
|
+
attr_reader name(): String
|
|
106
|
+
|
|
107
|
+
attr_reader klass(): Class
|
|
108
|
+
|
|
109
|
+
attr_reader fields(): Array[Field]
|
|
110
|
+
|
|
111
|
+
def self.new: (String name, Class klass, Array[Field] fields) -> instance
|
|
112
|
+
| (name: String, klass: Class, fields: Array[Field]) -> instance
|
|
113
|
+
|
|
114
|
+
def self.members: () -> [ :name, :klass, :fields ]
|
|
115
|
+
|
|
116
|
+
def members: () -> [ :name, :klass, :fields ]
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
class Union < Data
|
|
120
|
+
attr_reader types(): Array[t]
|
|
121
|
+
|
|
122
|
+
def self.new: (Array[t] types) -> instance
|
|
123
|
+
| (types: Array[t]) -> instance
|
|
124
|
+
|
|
125
|
+
def self.members: () -> [ :types ]
|
|
126
|
+
|
|
127
|
+
def members: () -> [ :types ]
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
class Unreadable < Data
|
|
131
|
+
attr_reader type(): String
|
|
132
|
+
|
|
133
|
+
attr_reader at(): String?
|
|
134
|
+
|
|
135
|
+
attr_reader instead(): String
|
|
136
|
+
|
|
137
|
+
def self.new: (String type, String? at, String instead) -> instance
|
|
138
|
+
| (type: String, at: String?, instead: String) -> instance
|
|
139
|
+
|
|
140
|
+
def self.members: () -> [ :type, :at, :instead ]
|
|
141
|
+
|
|
142
|
+
def members: () -> [ :type, :at, :instead ]
|
|
143
|
+
end
|
|
144
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: skyward-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jake Bottrall
|
|
8
|
-
bindir:
|
|
8
|
+
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rbs
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '4.2'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '4.2'
|
|
12
26
|
- !ruby/object:Gem::Dependency
|
|
13
27
|
name: zeitwerk
|
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -25,15 +39,39 @@ dependencies:
|
|
|
25
39
|
version: '2.8'
|
|
26
40
|
email:
|
|
27
41
|
- jakebottrall@gmail.com
|
|
28
|
-
executables:
|
|
42
|
+
executables:
|
|
43
|
+
- skyward
|
|
29
44
|
extensions: []
|
|
30
45
|
extra_rdoc_files: []
|
|
31
46
|
files:
|
|
32
47
|
- README.md
|
|
48
|
+
- exe/skyward
|
|
33
49
|
- lib/skyward/core.rb
|
|
50
|
+
- lib/skyward/core/boot_error.rb
|
|
51
|
+
- lib/skyward/core/cli.rb
|
|
52
|
+
- lib/skyward/core/cli/executable.rb
|
|
53
|
+
- lib/skyward/core/cli/registry.rb
|
|
54
|
+
- lib/skyward/core/signatures.rb
|
|
55
|
+
- lib/skyward/core/signatures/inline.rb
|
|
56
|
+
- lib/skyward/core/signatures/loader.rb
|
|
57
|
+
- lib/skyward/core/types.rb
|
|
58
|
+
- lib/skyward/core/types/reader.rb
|
|
34
59
|
- lib/skyward/core/version.rb
|
|
35
60
|
- sig/generated/skyward/core.rbs
|
|
61
|
+
- sig/generated/skyward/core/boot_error.rbs
|
|
62
|
+
- sig/generated/skyward/core/cli.rbs
|
|
63
|
+
- sig/generated/skyward/core/cli/executable.rbs
|
|
64
|
+
- sig/generated/skyward/core/cli/registry.rbs
|
|
65
|
+
- sig/generated/skyward/core/signatures.rbs
|
|
66
|
+
- sig/generated/skyward/core/signatures/inline.rbs
|
|
67
|
+
- sig/generated/skyward/core/signatures/loader.rbs
|
|
68
|
+
- sig/generated/skyward/core/types.rbs
|
|
69
|
+
- sig/generated/skyward/core/types/reader.rbs
|
|
36
70
|
- sig/generated/skyward/core/version.rbs
|
|
71
|
+
- sig/manual/skyward/core/cli.rbs
|
|
72
|
+
- sig/manual/skyward/core/cli/executable.rbs
|
|
73
|
+
- sig/manual/skyward/core/signatures.rbs
|
|
74
|
+
- sig/manual/skyward/core/signatures/inline.rbs
|
|
37
75
|
homepage: https://github.com/bottrall/skyward
|
|
38
76
|
licenses:
|
|
39
77
|
- MIT
|