spinel_kit 0.2.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a45aac9b6f91813e7d837ea8878d4dcee1731b5582f4a42e5fae4f73e9f764ce
4
- data.tar.gz: f201acc7e5c64ba8f5666e4c9c454440c7d1cc6835a30dd8adfb07442b1b42e8
3
+ metadata.gz: 84664f6fb19c07c1e9d4db180b7f9eb34a0499e6210de5acc764708b923aed72
4
+ data.tar.gz: 4a7894dca8991b6daf713423d04b33e35ef48678de58ea53112267a9cd7d679a
5
5
  SHA512:
6
- metadata.gz: 5a6f770a93f9975455637ed2fb2ffd8874dcc69d1e6fdf8547b7120c13ea341f2154a0427f2bf317851d0cb86072232649f6e1b011354c8ab68760f120a4bc2e
7
- data.tar.gz: 45d722737fce1cce7d606765af43f405fa6f34c96fa8a0167c8794262dee1ffebaa034600d865399577aaf9e826491059f338a8e688502bfd52b00c1071157b3
6
+ metadata.gz: e0599c94cabe3f168c4b1262e70dc66ef71eb2b9fc4a986e258a0040f1951c1e0ce59441f5d9eb881d251e16de7774ef0eb6a5f9b4b50c05969ccce9c2b6ebb9
7
+ data.tar.gz: 66a6080818ef6dd1d0ed4e9f19567ba903c4109cec84427971d7264cb3d316953db200c1fba64bab840f366a369f53b4bed789b253a43f788c2383092d6bce9d
data/CHANGELOG.md CHANGED
@@ -2,6 +2,51 @@
2
2
 
3
3
  All notable changes to SpinelKit are documented here.
4
4
 
5
+ ## [0.3.1] - 2026-11-12
6
+
7
+ ### Fixed
8
+ - **`SpinelKit::Url.escape` dropped all but the first byte of a multi-byte
9
+ character.** It indexed with `String#[]` and encoded `c.getbyte(0)`, on the
10
+ documented premise that `[]` indexes bytes under Spinel. It does not —
11
+ `"café".length` is 4 there and `[3]` is a two-byte `"é"` — so `"café"`
12
+ escaped to `"caf%C3"` on both runtimes, and that does not unescape back.
13
+ It now walks `bytesize`/`getbyte`. ASCII input and the `.b` form that the
14
+ parity test used are unchanged; what changes is that a plain UTF-8 string
15
+ now answers the same as its binary form.
16
+
17
+ ## [0.3.0] - 2026-07-09
18
+
19
+ ### Changed
20
+ - **Converted to a spin package** (spin is Spinel's package system;
21
+ [#3](https://github.com/OriPekelman/spinelkit/issues/3)). The package root
22
+ is now the require root: `lib/spinel_kit{,.rb}` moved to the repo top level,
23
+ `spin.toml` carries the identity (`name = "spinel_kit"`), and the gem
24
+ mirrors the layout with `require_paths = ["."]` — one tree serves both
25
+ consumers. Tests split by oracle: `test/*.rb` are compiled `spin test`
26
+ snapshot programs with committed `.expected` files (verified byte-identical
27
+ under CRuby and under spinel master `f9a81b1d`, 4/4); the CRuby minitest
28
+ parity suite moved to `test/parity/`.
29
+
30
+ ### Removed
31
+ - **`SpinelKit::Json` and `SpinelKit::Json::Builder`** (`lib/spinel_kit/json.rb`,
32
+ `json_decoder.rb`, `json_builder.rb`, their `sig/` RBS and the parity test).
33
+ Spinel now bundles `json` as a require-gated stdlib package — a typed native
34
+ binding (`native_func :parse/:generate/:dump`) into the runtime's
35
+ `sp_json.c` — so the compiler provides the stdlib surface SpinelKit was
36
+ shimming ([#3](https://github.com/OriPekelman/spinelkit/issues/3)).
37
+ Verified on spinel master `f9a81b1d` with a tep-shaped consumer under
38
+ `SPINEL_REQUIRE_GATE=1`: byte-identical CRuby parity and **no
39
+ cross-degrade**; values from `JSON.parse` must be coerced at the boundary
40
+ (`.to_s`/`.to_i`/`.to_f`/`.map { |x| x.to_i }`) to stay fully typed —
41
+ without coercion, direct sinks widen to `untyped` (slow path, still
42
+ correct output).
43
+
44
+ **Migration:** `require "json"`; `JSON.parse(s)["k"].to_i` replaces
45
+ `SpinelKit::Json.get_int(s, "k")` (same shape for `get_str`/`get_float`/
46
+ `get_int_array`); `h.key?("k")` replaces `has_key?(s, "k")`;
47
+ `JSON.generate(hash)` replaces `encode_pair_*`/`from_*` and the Builder
48
+ (Ruby hashes are insertion-ordered; `native_obj_reflect` covers Structs).
49
+
5
50
  ## [0.2.0] - 2026-06-08
6
51
 
7
52
  ### Added
data/README.md CHANGED
@@ -6,18 +6,38 @@
6
6
  ![Ruby](https://img.shields.io/badge/ruby-%3E%3D%203.2-CC342D)
7
7
  ![Pure Ruby](https://img.shields.io/badge/native%20ext-none-brightgreen)
8
8
 
9
- **The Spinel stdlib-surface gem.** A pure-Ruby, Spinel-safe toolkit holding
10
- the generic "stdlib substitute" shims that every Spinel-compiled project would
11
- otherwise hand-roll.
12
-
13
- [Spinel](https://github.com/matz/spinel) is a Ruby→native AOT compiler. It
14
- cannot lower large chunks of the CRuby standard library — the `json` gem's
15
- C-extension fast path and its metaprogrammed pure-Ruby fallback, stdlib
16
- `Logger`, C-extension git bindings, and more. So every Spinel project re-derives
17
- the same shims. [toy](https://github.com/OriPekelman/toy) and
18
- [tep](https://github.com/OriPekelman/tep) grew theirs independently, and the
19
- JSON escape/quote/hex code came out *byte-identical*. SpinelKit is that code,
20
- consolidated once.
9
+ **The non-stdlib toolkit for Spinel-compiled apps.** A pure-Ruby, Spinel-safe
10
+ library holding the shims [Spinel](https://github.com/matz/spinel) (the
11
+ Ruby→native AOT compiler) does not provide and that every Spinel project
12
+ would otherwise hand-roll: **git provenance, URL percent-codec + query
13
+ parsing, a minimal levelled logger, and a hex codec**.
14
+ [toy](https://github.com/OriPekelman/toy) and
15
+ [tep](https://github.com/OriPekelman/tep) grew these independently — parts
16
+ came out *byte-identical* — and SpinelKit is that code, consolidated once.
17
+
18
+ ## Where JSON went
19
+
20
+ SpinelKit began as "the stdlib-surface gem," and its founding surface was a
21
+ JSON codec. Spinel now **bundles `json` as a require-gated stdlib package** —
22
+ a typed native binding straight into the runtime's `sp_json.c` — so the
23
+ compiler provides the stdlib surface itself and `SpinelKit::Json` was retired
24
+ in 0.3.0 ([#3](https://github.com/OriPekelman/spinelkit/issues/3)). Migration:
25
+
26
+ ```ruby
27
+ require "json" # bare stdlib require, no manifest entry
28
+
29
+ h = JSON.parse(body)
30
+ model = h["model"].to_s # coerce at the parse boundary and
31
+ max_tokens = h["max_tokens"].to_i # everything downstream stays fully
32
+ temp = h["temperature"].to_f # specialized under whole-program
33
+ ids = h["prompt"].map { |x| x.to_i } # inference
34
+
35
+ JSON.generate({ "ok" => true, "n" => max_tokens }) # replaces the Builder
36
+ ```
37
+
38
+ Coerce parsed values once at the boundary (`.to_s`/`.to_i`/`.to_f`/mapped
39
+ `.to_i`) — verified against spinel master: byte-identical CRuby parity, no
40
+ cross-degrade, and full re-typification with the coercions in place.
21
41
 
22
42
  ## Installation
23
43
 
@@ -38,20 +58,20 @@ cleanly into a Spinel build via [bundler-spinel](https://github.com/OriPekelman/
38
58
 
39
59
  The first thing we did was audit the
40
60
  [spinelgems](https://github.com/OriPekelman/spinelgems) compatibility catalog
41
- (verdict ladder: `verified > loaded > clean > risky > rejected`) for an existing
42
- gem to reuse — that would have been the biggest win. **There wasn't one.** These
43
- shims *are* the ecosystem's gaps:
61
+ (verdict ladder: `verified > loaded > clean > risky > rejected`) for existing
62
+ gems to reuse — that would have been the biggest win. **There weren't any.**
63
+ These shims *are* the ecosystem's gaps:
44
64
 
45
65
  | Surface | Catalog finding | Decision |
46
66
  |---------|-----------------|----------|
47
- | JSON | `json` **rejected** (C-ext + metaprogrammed fallback); `oj` **risky** (C-ext) | implement |
48
67
  | Log | `logger` **rejected** (unresolved calls) | implement |
49
68
  | Git | `rugged` **rejected** (C); `gitkite`/`git_manager` only **clean**, unmet `needs:` | implement (read `.git/HEAD`) |
69
+ | Url/Hex | `CGI`/`URI` stdlib not lowered; no verified gem | implement |
50
70
  | Path | `hike` **verified** at an older rev, only **loaded** now; overkill for basename/join | deferred |
51
71
  | Bytes | `unicode_utils`/`utf8-cleaner` **clean** only; toy's need is tokenizer-specific | deferred |
52
72
 
53
- See [`docs/gem-audit-first.md`](docs/gem-audit-first.md) for the full audit and
54
- the verification-request issues we filed on spinelgems.
73
+ See [`docs/gem-audit-first.md`](docs/gem-audit-first.md) for the full audit
74
+ (which also covers the since-retired JSON surface).
55
75
 
56
76
  ## What's in it
57
77
 
@@ -61,31 +81,8 @@ require "spinel_kit" # everything (CRuby / convenience)
61
81
 
62
82
  For a **Spinel-compiled** consumer, require only the surface you use — Spinel
63
83
  has no tree-shaking, so every loaded method is compiled (and an uncalled one
64
- can degrade). The Json surface is split into three files for exactly this
65
- reason: `spinel_kit/json` (encoders), `spinel_kit/json_decoder` (decoders), and
66
- `spinel_kit/json_builder` (the builder). e.g. tep requires `json` + `json_decoder`;
67
- toy requires `json_builder`.
68
-
69
- - **`SpinelKit::Json`** — a JSON-over-HTTP codec: encoders
70
- (`escape`/`quote`/`encode_pair_*`/`from_*`, in `spinel_kit/json`) and flat-key
71
- decoders (`get_str`/`get_int`/`get_float`/`get_int_array`/`has_key?`, in
72
- `spinel_kit/json_decoder`).
73
-
74
- ```ruby
75
- SpinelKit::Json.get_int('{"age":33}', "age") # => 33
76
- SpinelKit::Json.from_int_hash({"a" => 1, "b" => 2}) # => {"a":1,"b":2}
77
- ```
78
-
79
- - **`SpinelKit::Json::Builder`** — an incremental ordered-object builder
80
- (`add_str`/`add_num`/`add_bool`/`add_raw`/`add_obj`/`dump`), in its own file
81
- so a builder-only consumer never compiles the codec, and vice versa.
82
-
83
- ```ruby
84
- j = SpinelKit::Json::Builder.new
85
- j.add_str("kind", "run_start")
86
- j.add_num("t", 1715000000)
87
- j.dump # => {"kind":"run_start","t":1715000000}
88
- ```
84
+ can degrade): `spinel_kit/hex`, `spinel_kit/url` (pulls in hex),
85
+ `spinel_kit/git`, `spinel_kit/log`.
89
86
 
90
87
  - **`SpinelKit::Git`** — git provenance from `.git/HEAD`.
91
88
 
@@ -95,6 +92,15 @@ toy requires `json_builder`.
95
92
  g.branch # => "main"
96
93
  ```
97
94
 
95
+ - **`SpinelKit::Url`** — the `CGI`/`URI`-component surface:
96
+ `escape`/`unescape` (RFC 3986 percent-codec), `parse_query`
97
+ (form-urlencoded → Hash), `split_url` (scheme/host/port/path/query).
98
+
99
+ ```ruby
100
+ SpinelKit::Url.escape("a b&c") # => "a%20b%26c"
101
+ SpinelKit::Url.parse_query("x=1&y=z") # => {"x"=>"1", "y"=>"z"}
102
+ ```
103
+
98
104
  - **`SpinelKit::Log`** — a minimal levelled logger (CRuby `Logger` doesn't
99
105
  compile under Spinel).
100
106
 
@@ -104,6 +110,9 @@ toy requires `json_builder`.
104
110
  log.info("server up")
105
111
  ```
106
112
 
113
+ - **`SpinelKit::Hex`** — hex digit/byte encode + decode (`nibble`,
114
+ `nibble_char`, `byte2`, `to_int`); the shared surface `Url` builds on.
115
+
107
116
  ## Design constraints (read before editing)
108
117
 
109
118
  SpinelKit is **pure Ruby, no native extension** (`spinel-ext.json` is `[]`) and
@@ -111,24 +120,44 @@ has **no runtime dependencies**, so it vendors cleanly via `bundler-spinel`. The
111
120
  surface uses plain, standard names; the `j_`/`tj_`/`gi_` prefixes the donor
112
121
  copies carried were a workaround for a Spinel whole-program-inference bug that
113
122
  has since been fixed upstream (verified with toy's `gate-poly-degrade` on the
114
- current compiler). One numeric caveat remains for `add_num` — see
115
- [`docs/spinel-discipline.md`](docs/spinel-discipline.md).
123
+ current compiler). See [`docs/spinel-discipline.md`](docs/spinel-discipline.md).
124
+
125
+ ## Package formats: spin package + gem, one tree
126
+
127
+ This repo **is a [spin](https://github.com/matz/spin-index) package** (spin is
128
+ Spinel's package system): the package root is the require root
129
+ (`spinel_kit.rb` + `spinel_kit/` at top level), `spin.toml` carries the
130
+ identity, and the top-level `test/*.rb` programs are compiled snapshot tests
131
+ (`spin test` — each diffs against its committed `.expected`, byte-identical
132
+ under CRuby too). Spinel projects take it with:
133
+
134
+ ```sh
135
+ spin add spinel_kit # index form, once seeded — or:
136
+ spin add spinel_kit --git https://github.com/OriPekelman/spinelkit
137
+ ```
138
+
139
+ The same tree still ships as the `spinel_kit` **gem** for CRuby-side
140
+ consumers (`require_paths` is the package root), and vendors via
141
+ `bundler-spinel` as before.
116
142
 
117
143
  ## Status
118
144
 
119
- Pre-alpha (`0.1.0`). The shims are implemented, CRuby-verified, and the surface
120
- is the single canonical one (the donor prefixes and duplicated escapers are
121
- gone — the Spinel inference bug that motivated them is fixed). Consumer adoption
122
- is the next phase: because we author every repo in this set, tep and toy
123
- **migrate to `SpinelKit::*` directly and delete their donor modules** — we
124
- standardize and clean rather than leave compatibility aliases behind. See
125
- [`docs/adoption.md`](docs/adoption.md). Tracking issue:
126
- [OriPekelman/toy#44](https://github.com/OriPekelman/toy/issues/44).
145
+ Pre-alpha (`0.3.0` — the JSON retirement + spin package conversion). tep and
146
+ toy migrated to `SpinelKit::*` directly and deleted their donor modules (see
147
+ [`docs/adoption.md`](docs/adoption.md)); their JSON call sites migrate to the
148
+ bundled stdlib `json` next
149
+ ([tep#217](https://github.com/OriPekelman/tep/issues/217),
150
+ [tep#213](https://github.com/OriPekelman/tep/issues/213)), and their
151
+ dependency declarations move to `spin.toml`
152
+ ([tep#234](https://github.com/OriPekelman/tep/issues/234),
153
+ [toy#107](https://github.com/OriPekelman/toy/issues/107)). Repositioning
154
+ tracked in [#3](https://github.com/OriPekelman/spinelkit/issues/3).
127
155
 
128
156
  ## Development
129
157
 
130
158
  ```sh
131
- rake test # CRuby-side parity tests (never compiled)
159
+ rake test # CRuby-side parity tests, test/parity/ (never compiled)
160
+ spin test # compiled snapshot tests, test/*.rb vs .expected
132
161
  rake rbs:validate # syntax-check the advisory RBS in sig/
133
162
  gem build spinel_kit.gemspec
134
163
  ```
data/docs/adoption.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Adoption — standardize and clean (not shim-and-alias)
2
2
 
3
+ > **Historical note (2026-07-08).** This doc describes the 0.1–0.2 era
4
+ > migration of tep and toy onto `SpinelKit::*`, including the Json surface.
5
+ > `SpinelKit::Json`/`Builder` were **retired in 0.3.0** — Spinel now bundles
6
+ > `json` as a stdlib package, and the Json call sites below migrate again, to
7
+ > bare `require "json"` (see
8
+ > [#3](https://github.com/OriPekelman/spinelkit/issues/3) and the CHANGELOG
9
+ > migration note). The Git/Url/Log/Hex parts remain accurate.
10
+
3
11
  Bootstrap landed the gem and its three shims. Adoption by tep and toy is the
4
12
  next phase. **Because we author every repo in this set — toy, tep, spinelgems,
5
13
  and Spinel itself — the goal is to standardize and clean, not to bolt
@@ -2,7 +2,7 @@
2
2
 
3
3
  SpinelKit ships code that gets compiled into *other* programs by Spinel's
4
4
  whole-program AOT compiler. That changes the rules for how it must be written.
5
- This doc is the contract for anyone editing `lib/spinel_kit/*.rb`.
5
+ This doc is the contract for anyone editing `spinel_kit/*.rb`.
6
6
 
7
7
  ## 1. The name-keyed inference bug — FIXED, prefixes dropped
8
8
 
@@ -35,28 +35,24 @@ names (`escape`/`quote`/`add_str`/`sha`/`branch`/plain `value`).
35
35
  - **Split the surface so consumers don't compile dead code.** Spinel has no
36
36
  tree-shaking: every loaded method is compiled, and a *set* of uncalled
37
37
  methods can degrade each other's (and nearby live methods') param types. We
38
- saw this concretely — with the encoders and decoders in one class, an
39
- encode-only program left the 9 decoder walkers dead; their `s` params
40
- collapsed to `int` and dragged `escape`'s `s` to `int` too, silently
41
- emitting `""` keys from `from_*_hash`. The fix was structural: encoders
42
- (`json.rb`), decoders (`json_decoder.rb`), and builder (`json_builder.rb`)
43
- live in separate files, so a consumer loads only a coherent surface it
44
- actually exercises. Verified clean (0 emit-0, correct output) for the real
45
- consumer shapes — builder-only (toy) and encode+decode (tep) — on rev
46
- `57af7f9`. A consumer that loads a surface but leaves part of it uncalled can
47
- still trip the gate; that's expected, and the gate is what flags it.
48
- - **`escape`/`quote`/`hex2` are single canonical methods** — the builder
49
- carries its own byte-identical copies (so a builder-only compile pulls in no
50
- codec); there is no `tj_*` prefix any more.
51
- - **Keep `get_float` inlined** (it does NOT delegate to a `parse_float_value`
52
- helper). This is unrelated to the name bug — it's a value-walk *indirection*
53
- issue where Spinel mis-widened the string arg `s` to int through the helper
54
- call. Until that's separately confirmed fixed, leave it inlined.
38
+ saw this concretely in the retired Json surface — with the encoders and
39
+ decoders in one class, an encode-only program left the 9 decoder walkers
40
+ dead; their `s` params collapsed to `int` and dragged `escape`'s `s` to
41
+ `int` too, silently emitting `""` keys. The fix was structural: one
42
+ coherent surface per file (today: `hex.rb`, `url.rb`, `git.rb`, `log.rb`),
43
+ so a consumer loads only what it actually exercises. A consumer that loads
44
+ a surface but leaves part of it uncalled can still trip the gate; that's
45
+ expected, and the gate is what flags it.
55
46
  - **Never override `to_s`** — it merges across the whole program.
56
47
  - The stale cautionary comments in toy's `toy_json.rb`/`toy_git.rb` and the
57
48
  landmine memory note should be annotated "fixed upstream by `ac7720e`/
58
49
  `23ba632`, verified on `57af7f9`" when those repos are next touched.
59
50
 
51
+ (Historical, retired with the Json surface in 0.3.0: the three-file Json
52
+ split, the builder's byte-identical private escapers, and the keep-`get_float`
53
+ -inlined rule. The last known instance of the value-walk indirection issue was
54
+ verified fixed on master `b60fbd7`.)
55
+
60
56
  ## 2. The poly-degrade gate (how consumers verify SpinelKit is safe)
61
57
 
62
58
  Each consumer has a poly-degrade scan that compiles a canonical entrypoint and
@@ -101,6 +97,7 @@ destined for Spinel. SpinelKit's own decoders follow this rule.
101
97
  runs, but file output is the portable path.
102
98
  - `Time.now` exposes integer seconds only (no rich `strftime`) — `Log` formats
103
99
  with `Time.now.to_i`.
104
- - `Integer#chr` is not uniform for arbitrary bytes — `Json.byte_to_chr` uses a
105
- printable-ASCII table with a `"?"` fallback.
100
+ - `Integer#chr` is not uniform for arbitrary bytes — the retired Json surface
101
+ used a printable-ASCII table with a `"?"` fallback; apply the same pattern
102
+ if a surface ever needs byte→char again.
106
103
  - No C extensions — `spinel-ext.json` is `[]`.
data/spin.toml ADDED
@@ -0,0 +1,6 @@
1
+ # spin package manifest — SpinelKit as an ordinary spin package.
2
+ # The package NAME is the require string (`require "spinel_kit/git"` etc.);
3
+ # the repo keeps its historical name. See issue #3 for the repositioning.
4
+ [package]
5
+ name = "spinel_kit"
6
+ version = "0.3.1"
@@ -1,12 +1,8 @@
1
1
  # SpinelKit::Hex -- hex digit/byte encode + decode: the pieces every Spinel
2
2
  # project re-rolls. The decode nibble appeared BYTE-IDENTICAL in Tep::Url,
3
- # inside SpinelKit::Json's string decoder, and (as a multi-digit variant) in
4
- # Tep::Llm's chunked-transfer size parser. Pure string/byte ops, Spinel-safe.
5
- #
6
- # NOTE on the Json overlap: SpinelKit::Json keeps its OWN private `hex2`/
7
- # `hex_nibble` so a JSON-only consumer never compiles this file (Spinel has no
8
- # tree-shaking — see json.rb). Hex is the shared surface for everyone else,
9
- # e.g. SpinelKit::Url.
3
+ # in the retired SpinelKit::Json string decoder, and (as a multi-digit
4
+ # variant) in Tep::Llm's chunked-transfer size parser. Pure string/byte ops,
5
+ # Spinel-safe. Hex is the shared surface, e.g. for SpinelKit::Url.
10
6
  module SpinelKit
11
7
  class Hex
12
8
  # Hex digit char -> int 0..15, or -1 if not a hex digit (upper or lower).
@@ -42,20 +42,26 @@ module SpinelKit
42
42
  # (ALPHA / DIGIT / `-._~`); the rest becomes `%XX` with UPPERCASE hex.
43
43
  # (Space -> `%20`, not `+` -- this is the URI-component, not form, encoder.)
44
44
  #
45
- # Byte-oriented: under Spinel `String#[]` indexes BYTES, so a multi-byte
46
- # UTF-8 char is encoded byte-by-byte (correct %XX of each byte). Under CRuby,
47
- # pass a binary string for the same behaviour (else `[]` splits on chars).
45
+ # Byte-oriented, and it walks BYTES to be so: `bytesize`/`getbyte` mean
46
+ # a multi-byte UTF-8 character becomes the %XX of each of its bytes on
47
+ # both runtimes, with no binary-string dance at the call site.
48
+ #
49
+ # It used to index with `String#[]` and encode `c.getbyte(0)` -- the
50
+ # FIRST byte of the character -- on the premise that `[]` indexes bytes
51
+ # under Spinel. It does not: `"caf\u00e9".length` is 4 there and `[3]`
52
+ # is a two-byte "\u00e9", so every byte but the first was DROPPED and
53
+ # "caf\u00e9" escaped to "caf%C3", which does not unescape back.
48
54
  def self.escape(s)
49
55
  out = ""
50
56
  i = 0
51
- while i < s.length
52
- c = s[i]
53
- if (c >= "a" && c <= "z") || (c >= "A" && c <= "Z") ||
54
- (c >= "0" && c <= "9") || c == "-" || c == "." ||
55
- c == "_" || c == "~"
56
- out = out + c
57
+ n = s.bytesize
58
+ while i < n
59
+ b = s.getbyte(i)
60
+ if (b >= 0x61 && b <= 0x7A) || (b >= 0x41 && b <= 0x5A) ||
61
+ (b >= 0x30 && b <= 0x39) || b == 0x2D || b == 0x2E ||
62
+ b == 0x5F || b == 0x7E
63
+ out = out + b.chr
57
64
  else
58
- b = c.getbyte(0)
59
65
  out = out + "%" + Hex.nibble_char(b / 16) + Hex.nibble_char(b % 16)
60
66
  end
61
67
  i += 1
@@ -0,0 +1,6 @@
1
+ # SpinelKit version. Kept in its own file so the gemspec can read it
2
+ # without loading the rest of the library (the modules pull in no deps,
3
+ # but this matches the toy/tep convention exactly).
4
+ module SpinelKit
5
+ VERSION = "0.3.1"
6
+ end
data/spinel_kit.rb ADDED
@@ -0,0 +1,39 @@
1
+ # SpinelKit -- the non-stdlib toolkit for Spinel-compiled apps.
2
+ #
3
+ # A pure-Ruby, Spinel-safe toolkit holding the shims Spinel (the Ruby->native
4
+ # AOT compiler) does not provide and that every Spinel-compiled project would
5
+ # otherwise hand-roll:
6
+ #
7
+ # SpinelKit::Hex -- hex digit/byte encode + decode.
8
+ # SpinelKit::Url -- percent-encode/decode + form-query + URL split.
9
+ # SpinelKit::Git -- git provenance from .git/HEAD (was Toy::Git).
10
+ # SpinelKit::Log -- minimal levelled logger (was Tep::Logger).
11
+ #
12
+ # JSON is NOT here any more. Spinel bundles `json` as a require-gated stdlib
13
+ # package (a typed native binding into sp_json.c), so consumers write a bare
14
+ # `require "json"` and use JSON.parse / JSON.generate, coercing parsed values
15
+ # at the boundary (`.to_s` / `.to_i` / `.to_f` / `.map { |x| x.to_i }`) to
16
+ # keep inference fully typed. The old SpinelKit::Json codec + Builder were
17
+ # retired in 0.3.0 -- see CHANGELOG.md and issue #3.
18
+ #
19
+ # MINIMAL-SURFACE REQUIRING. This umbrella requires everything for
20
+ # convenience (and for CRuby use). But because Spinel compiles every loaded
21
+ # method with no tree-shaking, a Spinel-compiled consumer should require ONLY
22
+ # the file(s) it uses, to avoid compiling -- and degrading -- code it never
23
+ # calls:
24
+ #
25
+ # require "spinel_kit/hex" # hex digit/byte codec
26
+ # require "spinel_kit/url" # percent-codec + query (pulls in hex)
27
+ # require "spinel_kit/git"
28
+ # require "spinel_kit/log"
29
+ #
30
+ # No native extension (spinel-ext.json is []), no runtime dependencies. See
31
+ # docs/adoption.md and docs/spinel-discipline.md.
32
+ require_relative "spinel_kit/version"
33
+ require_relative "spinel_kit/hex"
34
+ require_relative "spinel_kit/url"
35
+ require_relative "spinel_kit/git"
36
+ require_relative "spinel_kit/log"
37
+
38
+ module SpinelKit
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spinel_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ori Pekelman
@@ -10,14 +10,14 @@ cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: |-
13
- SpinelKit consolidates the pure-Ruby "stdlib substitute" shims that every
14
- Spinel-compiled project would otherwise hand-roll. Spinel (the Ruby->native
15
- AOT compiler) cannot lower the json gem's C-ext fast path / metaprogrammed
16
- fallback, stdlib Logger, or C-ext git bindings -- and the spinelgems
17
- compatibility catalog confirms no verified gem exists to reuse. So this gem
18
- ships a JSON encoder+decoder+builder, .git/HEAD provenance, and a minimal
19
- levelled logger. Pure Ruby, no native extension, no runtime dependencies --
20
- it vendors cleanly via bundler-spinel. Pre-alpha.
13
+ SpinelKit consolidates the pure-Ruby shims that every Spinel-compiled
14
+ project would otherwise hand-roll and that Spinel (the Ruby->native AOT
15
+ compiler) does not provide: .git/HEAD provenance, URL percent-codec +
16
+ query parsing, a minimal levelled logger, and a hex digit/byte codec.
17
+ (JSON left in 0.3.0: Spinel now bundles `json` as a require-gated stdlib
18
+ package, so consumers use JSON.parse/JSON.generate directly.) Pure Ruby,
19
+ no native extension, no runtime dependencies -- it vendors cleanly via
20
+ bundler-spinel. Pre-alpha.
21
21
  email:
22
22
  - ori@pekelman.com
23
23
  executables: []
@@ -31,24 +31,19 @@ files:
31
31
  - docs/gem-audit-first.md
32
32
  - docs/spinel-discipline.md
33
33
  - docs/spinelgems-issues.md
34
- - lib/spinel_kit.rb
35
- - lib/spinel_kit/git.rb
36
- - lib/spinel_kit/hex.rb
37
- - lib/spinel_kit/json.rb
38
- - lib/spinel_kit/json_builder.rb
39
- - lib/spinel_kit/json_decoder.rb
40
- - lib/spinel_kit/log.rb
41
- - lib/spinel_kit/url.rb
42
- - lib/spinel_kit/version.rb
43
34
  - sig/spinel_kit/git.rbs
44
35
  - sig/spinel_kit/hex.rbs
45
- - sig/spinel_kit/json.rbs
46
- - sig/spinel_kit/json_builder.rbs
47
- - sig/spinel_kit/json_decoder.rbs
48
36
  - sig/spinel_kit/log.rbs
49
37
  - sig/spinel_kit/url.rbs
50
38
  - sig/spinel_kit/version.rbs
39
+ - spin.toml
51
40
  - spinel-ext.json
41
+ - spinel_kit.rb
42
+ - spinel_kit/git.rb
43
+ - spinel_kit/hex.rb
44
+ - spinel_kit/log.rb
45
+ - spinel_kit/url.rb
46
+ - spinel_kit/version.rb
52
47
  homepage: https://github.com/OriPekelman/spinelkit
53
48
  licenses:
54
49
  - MIT
@@ -60,7 +55,7 @@ metadata:
60
55
  rubygems_mfa_required: 'true'
61
56
  rdoc_options: []
62
57
  require_paths:
63
- - lib
58
+ - "."
64
59
  required_ruby_version: !ruby/object:Gem::Requirement
65
60
  requirements:
66
61
  - - ">="
@@ -74,6 +69,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
69
  requirements: []
75
70
  rubygems_version: 3.6.9
76
71
  specification_version: 4
77
- summary: 'The Spinel stdlib-surface gem: pure-Ruby JSON/Git/Log shims for AOT-compiled
78
- apps'
72
+ summary: Pure-Ruby Git/Url/Log/Hex shims for Spinel AOT-compiled apps
79
73
  test_files: []