cybertrain 0.2.1 → 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.
@@ -2,7 +2,8 @@
2
2
  # `server`, `build` and `spin` call Toolchain.ensure! before their first
3
3
  # spin command: it uses a `spinel`/`spin` of the pinned release already on
4
4
  # PATH, or the copy it keeps under ~/.cybertrain, or builds that copy from
5
- # the release tag (git clone, make deps, make, make install), the same steps
5
+ # the release tag of Cybertrain::SPINEL_REPOSITORY (git clone, make deps,
6
+ # make, make install), the same steps
6
7
  # CI runs. `cybertrain setup` does it explicitly; `cybertrain doctor`
7
8
  # reports.
8
9
  #
@@ -10,11 +11,12 @@
10
11
  # (bin/cybertrain.rb), so it shells out with `system` and backticks and
11
12
  # reads files instead of using Open3, RbConfig or Etc.
12
13
  require "cybertrain/version"
14
+ require "cybertrain/shell"
13
15
 
14
16
  module Cybertrain
15
17
  module CLI
16
18
  module Toolchain
17
- SPINEL_GIT = "https://github.com/matz/spinel.git"
19
+ SPINEL_GIT = "#{Cybertrain::SPINEL_REPOSITORY}.git"
18
20
  LOCK_WAIT_SECONDS = 3600
19
21
 
20
22
  # ---- locations -----------------------------------------------------
@@ -57,25 +59,37 @@ module Cybertrain
57
59
  File.join(prefix, ".cybertrain-complete")
58
60
  end
59
61
 
62
+ # The interpolated name is made before `home` is called, here and in the
63
+ # two below: in one argument list, `home`'s result is held only by a C
64
+ # temporary while a later argument allocates, and a collection there
65
+ # frees it (spikes/NOTES.md rule 65).
60
66
  def self.src_dir
61
- File.join(home, "src", "spinel-#{tag}")
67
+ name = "spinel-#{tag}"
68
+ File.join(home, "src", name)
62
69
  end
63
70
 
64
71
  def self.log_path
65
- File.join(home, "log", "spinel-#{tag}-build.log")
72
+ name = "spinel-#{tag}-build.log"
73
+ File.join(home, "log", name)
66
74
  end
67
75
 
68
76
  def self.lock_dir
69
- File.join(home, "spinel", "#{tag}.lock")
77
+ name = "#{tag}.lock"
78
+ File.join(home, "spinel", name)
70
79
  end
71
80
 
72
81
  # ---- discovery -----------------------------------------------------
73
82
 
74
- # The release inside the parentheses of `spinel --version`, which come
75
- # before the compiler field: "spinel 112bae85c1a2 (2026.09.12) [cc
76
- # (Ubuntu 13.3.0) 13.3.0]" -> "2026.09.12". "" when there is none.
83
+ # The release `spinel --version` names, in either of its two shapes:
84
+ # "spinel 2026.10.26.7019 (80b2f9889) [cc ...]" (the release first, then
85
+ # the revision, from Spinel 2026.10 on) or "spinel 112bae85c1a2
86
+ # (2026.09.12) [cc ...]" (the revision first, then the release in
87
+ # parentheses, 2026.09 and before). "" when there is none.
77
88
  def self.release_of(version_line)
78
89
  head = version_line.split(" [")[0].to_s
90
+ words = head.split(" ")
91
+ return words[1].to_s if words.size >= 2 && words[0] == "spinel" && release_name?(words[1].to_s)
92
+
79
93
  open = head.index("(")
80
94
  close = head.index(")")
81
95
  return "" if open.nil? || close.nil? || close <= open
@@ -83,9 +97,18 @@ module Cybertrain
83
97
  head[open + 1, close - open - 1].to_s
84
98
  end
85
99
 
100
+ # A release name as Spinel's Makefile writes one: "unreleased", or a
101
+ # date tag ("2026.09.12", "2026.10.26.7019"), possibly with "+N" for N
102
+ # commits past it. A revision ("112bae85c1a2") has no dots.
103
+ def self.release_name?(word)
104
+ return true if word == "unreleased"
105
+
106
+ !word.match(/\A[0-9]{4}\.[0-9]{2}\.[0-9]{2}(\.[0-9]+)?(\+[0-9]+)?\z/).nil?
107
+ end
108
+
86
109
  # The release the spinel binary at `path` reports; "" when it cannot run.
87
110
  def self.release_at(path)
88
- release_of(sh_read("#{shell_quote(path)} --version"))
111
+ release_of(sh_read("#{Shell.quote(path)} --version"))
89
112
  end
90
113
 
91
114
  # dir holds an executable spinel and spin, and that spinel is the pinned
@@ -220,11 +243,11 @@ module Cybertrain
220
243
  # when the directory or a link could not be written (the toolchain
221
244
  # itself still works: cybertrain puts bin_dir on PATH by itself).
222
245
  def self.link_stable_bin
223
- return false unless system("mkdir -p #{shell_quote(stable_bin_dir)} 2>/dev/null")
246
+ return false unless system("mkdir -p #{Shell.quote(stable_bin_dir)} 2>/dev/null")
224
247
 
225
248
  ok = true
226
249
  ["spinel", "spin"].each do |name|
227
- ok = false unless system("ln -sfn #{shell_quote(File.join(bin_dir, name))} #{shell_quote(File.join(stable_bin_dir, name))} 2>/dev/null")
250
+ ok = false unless system("ln -sfn #{Shell.quote(File.join(bin_dir, name))} #{Shell.quote(File.join(stable_bin_dir, name))} 2>/dev/null")
228
251
  end
229
252
  ok
230
253
  end
@@ -284,30 +307,30 @@ module Cybertrain
284
307
 
285
308
  puts "Installing Spinel #{tag} into #{prefix} (one-time; a few minutes)"
286
309
  puts " log: #{log_path}"
287
- system("mkdir -p #{shell_quote(File.dirname(log_path))} #{shell_quote(File.dirname(src_dir))} 2>/dev/null")
288
- system("rm -rf #{shell_quote(src_dir)}")
310
+ system("mkdir -p #{Shell.quote(File.dirname(log_path))} #{Shell.quote(File.dirname(src_dir))} 2>/dev/null")
311
+ system("rm -rf #{Shell.quote(src_dir)}")
289
312
  unless prepare_files
290
313
  puts "error: cannot write under #{home} (#{log_path}); set CYBERTRAIN_HOME to a writable directory"
291
314
  return false
292
315
  end
293
316
  steps = [
294
- ["clone", "git clone -q --depth 1 --branch #{tag} #{SPINEL_GIT} #{shell_quote(src_dir)}"],
295
- ["deps", "cd #{shell_quote(src_dir)} && make deps"],
296
- ["build", "cd #{shell_quote(src_dir)} && make -j#{jobs}"],
297
- ["install", "cd #{shell_quote(src_dir)} && make install PREFIX=#{shell_quote(prefix)}"]
317
+ ["clone", "git clone -q --depth 1 --branch #{tag} #{SPINEL_GIT} #{Shell.quote(src_dir)}"],
318
+ ["deps", "cd #{Shell.quote(src_dir)} && make deps"],
319
+ ["build", "cd #{Shell.quote(src_dir)} && make -j#{jobs}"],
320
+ ["install", "cd #{Shell.quote(src_dir)} && make install PREFIX=#{Shell.quote(prefix)}"]
298
321
  ]
299
322
  steps.each do |step|
300
323
  return false unless still_holding_lock
301
324
  puts " #{step[0]}: #{step[1]}"
302
- next if system("(#{step[1]}) >> #{shell_quote(log_path)} 2>&1")
325
+ next if system("(#{step[1]}) >> #{Shell.quote(log_path)} 2>&1")
303
326
 
304
327
  puts "error: Spinel #{step[0]} failed; the last lines of #{log_path}:"
305
328
  tail(log_path, 25).each { |line| puts " | #{line}" }
306
329
  return false
307
330
  end
308
331
  unless ENV["CYBERTRAIN_KEEP_SRC"].to_s == "1"
309
- system("rm -rf #{shell_quote(src_dir)}")
310
- system("rmdir #{shell_quote(File.dirname(src_dir))} 2>/dev/null")
332
+ system("rm -rf #{Shell.quote(src_dir)}")
333
+ system("rmdir #{Shell.quote(File.dirname(src_dir))} 2>/dev/null")
311
334
  end
312
335
  unless usable?(bin_dir)
313
336
  puts "error: the install finished but #{bin_dir} does not hold spinel #{tag} and spin (see #{log_path})"
@@ -352,7 +375,8 @@ module Cybertrain
352
375
 
353
376
  def self.write_stamp
354
377
  begin
355
- File.write(stamp, "#{tag}\n")
378
+ stamp_text = "#{tag}\n" # made before `stamp` is called (rule 65)
379
+ File.write(stamp, stamp_text)
356
380
  rescue StandardError
357
381
  return false
358
382
  end
@@ -389,12 +413,12 @@ module Cybertrain
389
413
  # until someone removes the lock by hand, as the waiting message says.
390
414
  def self.take_lock
391
415
  parent = File.dirname(lock_dir)
392
- unless system("mkdir -p #{shell_quote(parent)} 2>/dev/null") && File.directory?(parent)
416
+ unless system("mkdir -p #{Shell.quote(parent)} 2>/dev/null") && File.directory?(parent)
393
417
  puts "error: cannot create #{parent}; set CYBERTRAIN_HOME to a writable directory"
394
418
  return false
395
419
  end
396
420
  staging = "#{lock_dir}.#{Process.pid}"
397
- system("rm -rf #{shell_quote(staging)}")
421
+ system("rm -rf #{Shell.quote(staging)}")
398
422
  begin
399
423
  Dir.mkdir(staging)
400
424
  File.write(File.join(staging, "pid"), Process.pid.to_s)
@@ -418,7 +442,7 @@ module Cybertrain
418
442
  puts waiting_message if waited == 0
419
443
  if waited >= LOCK_WAIT_SECONDS
420
444
  puts "error: gave up waiting; remove #{lock_dir} if no cybertrain is building Spinel"
421
- system("rm -rf #{shell_quote(staging)}")
445
+ system("rm -rf #{Shell.quote(staging)}")
422
446
  return false
423
447
  end
424
448
  sleep 5
@@ -472,13 +496,13 @@ module Cybertrain
472
496
  # Moves the (marked) lock aside and deletes it; true when it was there.
473
497
  def self.remove_lock
474
498
  aside = "#{lock_dir}.old.#{Process.pid}"
475
- system("rm -rf #{shell_quote(aside)}")
499
+ system("rm -rf #{Shell.quote(aside)}")
476
500
  begin
477
501
  File.rename(lock_dir, aside)
478
502
  rescue StandardError
479
503
  return false
480
504
  end
481
- system("rm -rf #{shell_quote(aside)}")
505
+ system("rm -rf #{Shell.quote(aside)}")
482
506
  true
483
507
  end
484
508
 
@@ -578,7 +602,7 @@ module Cybertrain
578
602
  end
579
603
 
580
604
  def self.have_command?(name)
581
- sh_read("command -v #{shell_quote(name)}") != ""
605
+ sh_read("command -v #{Shell.quote(name)}") != ""
582
606
  end
583
607
 
584
608
  # A C program using `include` and `link` compiles and links: the
@@ -589,8 +613,8 @@ module Cybertrain
589
613
 
590
614
  source = File.join(dir, "probe.c")
591
615
  File.write(source, "#include <#{include}>\nint main(void) { return #{body}; }\n")
592
- ok = system("#{cc} #{shell_quote(source)} -o #{shell_quote(File.join(dir, "probe"))} #{link} > /dev/null 2>&1") ? true : false
593
- system("rm -rf #{shell_quote(dir)}")
616
+ ok = system("#{cc} #{Shell.quote(source)} -o #{Shell.quote(File.join(dir, "probe"))} #{link} > /dev/null 2>&1") ? true : false
617
+ system("rm -rf #{Shell.quote(dir)}")
594
618
  ok
595
619
  end
596
620
 
@@ -598,6 +622,13 @@ module Cybertrain
598
622
  compiles?("sqlite3.h", "sqlite3_libversion_number() > 0 ? 0 : 1", "-lsqlite3")
599
623
  end
600
624
 
625
+ # zlib's header and library: Request#decoded_body inflates gzip request
626
+ # bodies through the system zlib (cybertrain/http/gzip_ffi.rb), so an
627
+ # application does not build without them.
628
+ def self.zlib_ok?
629
+ compiles?("zlib.h", "zlibVersion() != 0 ? 0 : 1", "-lz")
630
+ end
631
+
601
632
  # Spinel's own Makefile finds a Homebrew OpenSSL by itself; this probe
602
633
  # only decides whether to warn.
603
634
  def self.openssl_ok?
@@ -607,7 +638,7 @@ module Cybertrain
607
638
  return false if brew == ""
608
639
 
609
640
  compiles?("openssl/ssl.h", "TLS_client_method() != 0 ? 0 : 1",
610
- "-I#{shell_quote(File.join(brew, "include"))} -L#{shell_quote(File.join(brew, "lib"))} -lssl -lcrypto")
641
+ "-I#{Shell.quote(File.join(brew, "include"))} -L#{Shell.quote(File.join(brew, "lib"))} -lssl -lcrypto")
611
642
  end
612
643
 
613
644
  # What a Spinel build cannot do without, by name. OpenSSL is not in
@@ -622,10 +653,21 @@ module Cybertrain
622
653
  missing << "git" unless have_command?("git")
623
654
  missing << "make" unless have_command?("make")
624
655
  missing << "curl" unless have_command?("curl")
656
+ missing << PRISM_REQUIREMENT unless prism_ok?
625
657
  missing_app_requirements.each { |name| missing << name }
626
658
  missing
627
659
  end
628
660
 
661
+ PRISM_REQUIREMENT = "a Ruby that loads the prism gem (Ruby 3.3 or newer, or `gem install prism`)"
662
+
663
+ # Spinel's build runs tools/gen_respond_to_tables.rb, which requires
664
+ # the prism gem: bundled with Ruby 3.3 and newer, a `gem install` (with
665
+ # Ruby's development headers, for its extension) on 3.2. Only building
666
+ # Spinel needs it; applications never run on CRuby.
667
+ def self.prism_ok?
668
+ system("ruby -e 'require \"prism\"' > /dev/null 2>&1")
669
+ end
670
+
629
671
  # What building an application needs even once Spinel is installed.
630
672
  def self.missing_app_requirements
631
673
  missing = Array.new(0) { "" }
@@ -634,6 +676,7 @@ module Cybertrain
634
676
  return missing
635
677
  end
636
678
  missing << "the SQLite 3 headers and library" unless sqlite_ok?
679
+ missing << "the zlib headers and library" unless zlib_ok?
637
680
  missing
638
681
  end
639
682
 
@@ -656,22 +699,40 @@ module Cybertrain
656
699
 
657
700
  # The command that installs every requirement on this platform.
658
701
  def self.install_hints
702
+ hints = platform_install_hints
703
+ hints << prism_install_hint unless prism_ok?
704
+ hints
705
+ end
706
+
707
+ # Ruby 3.2's prism is a gem with a C extension: Ruby's development
708
+ # headers first (the package names below), then the gem.
709
+ def self.prism_install_hint
710
+ os = platform
711
+ headers = ""
712
+ headers = "sudo apt-get install -y ruby-dev && " if os == "debian"
713
+ headers = "sudo dnf install -y ruby-devel && " if os == "rhel"
714
+ headers = "sudo zypper install -y ruby-devel && " if os == "suse"
715
+ headers = "sudo apk add ruby-dev && " if os == "alpine"
716
+ "#{headers}gem install --user-install prism # or use Ruby 3.3 or newer, which has it"
717
+ end
718
+
719
+ def self.platform_install_hints
659
720
  case platform
660
721
  when "debian"
661
- ["sudo apt-get update && sudo apt-get install -y build-essential git curl libsqlite3-dev libssl-dev"]
722
+ ["sudo apt-get update && sudo apt-get install -y build-essential git curl libsqlite3-dev zlib1g-dev libssl-dev"]
662
723
  when "rhel"
663
- ["sudo dnf install -y gcc make git curl sqlite-devel openssl-devel"]
724
+ ["sudo dnf install -y gcc make git curl sqlite-devel zlib-devel openssl-devel"]
664
725
  when "arch"
665
- ["sudo pacman -S --needed base-devel git curl sqlite openssl"]
726
+ ["sudo pacman -S --needed base-devel git curl sqlite zlib openssl"]
666
727
  when "alpine"
667
- ["sudo apk add build-base git curl sqlite-dev openssl-dev"]
728
+ ["sudo apk add build-base git curl sqlite-dev zlib-dev openssl-dev"]
668
729
  when "suse"
669
- ["sudo zypper install -y gcc make git curl sqlite3-devel libopenssl-devel"]
730
+ ["sudo zypper install -y gcc make git curl sqlite3-devel zlib-devel libopenssl-devel"]
670
731
  when "darwin"
671
- ["xcode-select --install # cc, make, git, curl and the SQLite headers",
732
+ ["xcode-select --install # cc, make, git, curl, the SQLite and zlib headers",
672
733
  "brew install openssl@3 # optional: Spinel's openssl package"]
673
734
  else
674
- ["install git, make, curl, a C compiler and the SQLite 3 development headers with your package manager"]
735
+ ["install git, make, curl, a C compiler and the SQLite 3 and zlib development headers with your package manager"]
675
736
  end
676
737
  end
677
738
 
@@ -687,9 +748,11 @@ module Cybertrain
687
748
  report("git", have_command?("git"), sh_read("command -v git"))
688
749
  report("make", have_command?("make"), sh_read("command -v make"))
689
750
  report("curl", have_command?("curl"), sh_read("command -v curl"))
751
+ report("prism", prism_ok?, prism_ok? ? "the prism gem loads (building Spinel needs it)" : "ruby cannot load the prism gem (building Spinel needs it)")
690
752
  report("cc", have_command?(cc_program), sh_read("#{cc} --version 2>/dev/null | head -n 1"))
691
753
  if have_command?(cc_program)
692
754
  report("sqlite3", sqlite_ok?, sqlite_ok? ? "headers and library found" : "sqlite3.h or -lsqlite3 missing")
755
+ report("zlib", zlib_ok?, zlib_ok? ? "headers and library found" : "zlib.h or -lz missing")
693
756
  if openssl_ok?
694
757
  report("openssl", true, "headers and library found")
695
758
  else
@@ -778,10 +841,6 @@ module Cybertrain
778
841
  from = lines.size > count ? lines.size - count : 0
779
842
  lines[from, lines.size - from]
780
843
  end
781
-
782
- def self.shell_quote(text)
783
- "'#{text.gsub("'", "'\\\\''")}'"
784
- end
785
844
  end
786
845
  end
787
846
  end
data/cybertrain/cli.rb CHANGED
@@ -2,7 +2,9 @@
2
2
  # bin/cybertrain.rb built by spin (`spin install` from a checkout).
3
3
  #
4
4
  # cybertrain new NAME [--path DIR | --version V | --git URL [--ref R]] [--skip-spin]
5
- # cybertrain generate scaffold NAME field:type ... [parent:references]
5
+ # cybertrain generate scaffold NAME field:type ... [parent:references] [--any]
6
+ # cybertrain generate attachment MODEL FIELD [--any]
7
+ # cybertrain generate authentication [--invite-only]
6
8
  # cybertrain db migrate | db COMMAND... | server [PORT] | build | spin ARGS...
7
9
  # cybertrain setup [--force] | doctor | version | help
8
10
  #
@@ -12,6 +14,8 @@ require "cybertrain/version"
12
14
  require "cybertrain/cli/templates"
13
15
  require "cybertrain/cli/new_app"
14
16
  require "cybertrain/cli/scaffold"
17
+ require "cybertrain/cli/authentication"
18
+ require "cybertrain/cli/attachment"
15
19
  require "cybertrain/cli/build"
16
20
  require "cybertrain/cli/toolchain"
17
21
 
@@ -28,9 +32,30 @@ module Cybertrain
28
32
  current directory; written as an absolute path).
29
33
  --version V: the index version constraint V.
30
34
  --git URL [--ref R]: the framework at URL, at branch or tag R.
31
- cybertrain generate scaffold NAME field:type ... [parent:references]
35
+ cybertrain generate scaffold NAME field:type ... [parent:references] [--any]
32
36
  Add a resource to the application in the current directory.
33
37
  Types: #{Field::TYPES.join(", ")} (default string).
38
+ A field of type attachment (cover:attachment) is an uploaded file:
39
+ see `generate attachment`; --any applies to it.
40
+ cybertrain generate attachment MODEL FIELD [--any]
41
+ Attach an uploaded file to a model of the application in the
42
+ current directory (`generate attachment post cover`): five
43
+ columns in a migration, cover_* methods and callbacks in the model,
44
+ a download action and route, the file input in the scaffold's
45
+ form, and a test. The bytes are kept in storage/uploads/ (back it
46
+ up with the SQLite file). Only PNG, JPEG, GIF and WebP images are
47
+ accepted, unless --any allows any file; the stored type is always
48
+ the one detected from the bytes.
49
+ cybertrain generate authentication [--invite-only]
50
+ Add email-and-password sign-in to the application in the current
51
+ directory: users and sessions tables, User and Session models,
52
+ SessionsController and RegistrationsController with their views,
53
+ the routes, a before_action in ApplicationController and a test.
54
+ --invite-only: no sign-up page. Users are created with
55
+ `./NAME user EMAIL` (password from stdin), and the first one
56
+ also at /setup, which answers only to this machine, only with the
57
+ one-time token the server's boot warning prints, and only while
58
+ no user exists (NAME_SETUP_OPEN=1 lifts the address check).
34
59
  cybertrain db migrate
35
60
  Generate, apply pending migrations, generate again
36
61
  (spin run gen; spin run db -- migrate; spin run gen).
@@ -236,12 +261,53 @@ module Cybertrain
236
261
  run_spin(Build.server_commands(name, port))
237
262
  end
238
263
 
264
+ # `args` without the (every) `flag` option.
265
+ def self.without_flag(args, flag)
266
+ kept = Array.new(0) { "" }
267
+ args.each { |arg| kept << arg unless arg == flag }
268
+ kept
269
+ end
270
+
239
271
  def self.run_generate(argv)
240
272
  kind = argv.size > 1 ? argv[1] : ""
241
- raise InvalidArgument, "only `generate scaffold` is supported" unless kind == "scaffold"
242
- raise InvalidArgument, "usage: cybertrain generate scaffold NAME field:type ..." if argv.size < 3
273
+ case kind
274
+ when "scaffold"
275
+ raise InvalidArgument, "usage: cybertrain generate scaffold NAME field:type ... [--any]" if argv.size < 3
276
+
277
+ args = without_flag(argv[2, argv.size - 2], "--any")
278
+ raise InvalidArgument, "usage: cybertrain generate scaffold NAME field:type ... [--any]" if args.empty?
279
+
280
+ Scaffold.generate(".", args[0], args[1, args.size - 1], argv.include?("--any"))
281
+ when "attachment"
282
+ args = without_flag(argv[2, argv.size - 2], "--any")
283
+ raise InvalidArgument, "usage: cybertrain generate attachment MODEL FIELD [--any]" unless args.size == 2
243
284
 
244
- Scaffold.generate(".", argv[2], argv[3, argv.size - 3])
285
+ Attachment.generate(".", args[0], args[1], argv.include?("--any"))
286
+ puts Attachment::BACKUP_NOTE
287
+ puts ""
288
+ puts "next:"
289
+ puts " cybertrain db migrate"
290
+ puts " cybertrain server"
291
+ puts " cybertrain spin test # test/attachment_*.rb; snapshot it from the binary (README, \"Testing an app\")"
292
+ when "authentication"
293
+ args = without_flag(argv[2, argv.size - 2], "--invite-only")
294
+ raise InvalidArgument, "usage: cybertrain generate authentication [--invite-only]" unless args.empty?
295
+
296
+ invite_only = argv.include?("--invite-only")
297
+ Authentication.generate(".", invite_only)
298
+ puts ""
299
+ puts "next:"
300
+ puts " cybertrain db migrate"
301
+ if invite_only
302
+ app = Build.app_name(".")
303
+ puts " cybertrain server # then open the /setup?token=... link it prints, on this machine (or: spin run #{app} -- user EMAIL)"
304
+ else
305
+ puts " cybertrain server # then open /sign_up"
306
+ end
307
+ puts " cybertrain spin test # test/authentication.rb; snapshot it from the binary (README, \"Testing an app\")"
308
+ else
309
+ raise InvalidArgument, "only `generate scaffold`, `generate attachment` and `generate authentication` are supported"
310
+ end
245
311
  0
246
312
  end
247
313
  end
@@ -59,16 +59,37 @@ module Cybertrain
59
59
  # collection inside `chars` frees an unnamed gsub result it is
60
60
  # splitting ("Post" comes back as "").
61
61
  path = camel_cased_word.gsub("::", "/")
62
- chars = path.chars
62
+ # Bytes, copied in runs between the places a "_" goes in: a view asks
63
+ # for a model's and a controller's key on every request, and one
64
+ # String per character (chars, then << each) was most of a page's
65
+ # allocations here. The rules only look at ASCII letters, digits and
66
+ # "-"; any byte of a multibyte character is none of those, as the
67
+ # character itself was none of them, so the result is the same.
68
+ s = "#{path}"
69
+ n = s.bytesize
63
70
  out = +""
64
- chars.each_with_index do |ch, i|
65
- if i > 0 && upper?(ch)
66
- prev = chars[i - 1]
67
- nxt = i + 1 < chars.size ? chars[i + 1] : ""
68
- out << "_" if lower_or_digit?(prev) || (upper?(prev) && lower?(nxt))
71
+ start = 0
72
+ i = 0
73
+ while i < n
74
+ b = s.getbyte(i)
75
+ if b == 45
76
+ out << s.byteslice(start, i - start) if i > start
77
+ out << "_"
78
+ start = i + 1
79
+ elsif i > 0 && b >= 65 && b <= 90
80
+ prev = s.getbyte(i - 1)
81
+ nxt = i + 1 < n ? s.getbyte(i + 1) : 0
82
+ prev_lower_or_digit = (prev >= 97 && prev <= 122) || (prev >= 48 && prev <= 57)
83
+ prev_upper = prev >= 65 && prev <= 90
84
+ if prev_lower_or_digit || (prev_upper && nxt >= 97 && nxt <= 122)
85
+ out << s.byteslice(start, i - start) if i > start
86
+ out << "_"
87
+ start = i
88
+ end
69
89
  end
70
- out << (ch == "-" ? "_" : ch)
90
+ i += 1
71
91
  end
92
+ out << s.byteslice(start, n - start) if n > start
72
93
  out.downcase
73
94
  end
74
95
 
@@ -0,0 +1,15 @@
1
+ module Cybertrain
2
+ # The one definition of how a value is quoted for sh: the CLI (Build, for
3
+ # `cybertrain db`/`server`/`build` and the commands `cybertrain new` runs;
4
+ # Toolchain, building and probing Spinel) and the development rebuilder
5
+ # (Dev::Rebuilder#command) all shell out with paths and names they did not
6
+ # choose. A leaf file with no requires: the CLI (CRuby) and the framework
7
+ # (Spinel) both load it.
8
+ module Shell
9
+ # text single-quoted, each embedded ' closed, escaped and reopened, so sh
10
+ # reads it back as exactly text whatever it contains.
11
+ def self.quote(text)
12
+ "'#{text.gsub("'", "'\\\\''")}'"
13
+ end
14
+ end
15
+ end
@@ -1,12 +1,16 @@
1
1
  module Cybertrain
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
 
4
4
  # Where `cybertrain new` points an app's spin.toml by default: the git tag
5
5
  # "v#{VERSION}" of this repository. Kept here because the gem (CRuby) and
6
6
  # the spin-built CLI read the same file.
7
7
  REPOSITORY = "https://github.com/saeki-mototsune/cybertrain"
8
8
 
9
- # The Spinel release cybertrain is written and tested against: the tag
10
- # `cybertrain setup` builds and CI's SPINEL_TAG.
11
- SPINEL_TAG = "2026.09.12"
9
+ # The Spinel release cybertrain is written and tested against: the tag of
10
+ # SPINEL_REPOSITORY that `cybertrain setup` builds, and CI's SPINEL_TAG.
11
+ SPINEL_TAG = "2026.10.26.7019"
12
+
13
+ # Where that tag lives: the saeki-mototsune fork of matz/spinel, which
14
+ # carries the fixes cybertrain needs ahead of an upstream release.
15
+ SPINEL_REPOSITORY = "https://github.com/saeki-mototsune/spinel"
12
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cybertrain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saeki Mototsune
@@ -24,6 +24,8 @@ files:
24
24
  - README.md
25
25
  - cybertrain/app_name.rb
26
26
  - cybertrain/cli.rb
27
+ - cybertrain/cli/attachment.rb
28
+ - cybertrain/cli/authentication.rb
27
29
  - cybertrain/cli/build.rb
28
30
  - cybertrain/cli/new_app.rb
29
31
  - cybertrain/cli/scaffold.rb
@@ -31,6 +33,7 @@ files:
31
33
  - cybertrain/cli/toolchain.rb
32
34
  - cybertrain/generator/inflector.rb
33
35
  - cybertrain/ident.rb
36
+ - cybertrain/shell.rb
34
37
  - cybertrain/version.rb
35
38
  - exe/cybertrain
36
39
  homepage: https://github.com/saeki-mototsune/cybertrain