Class: Fresco::App
- Inherits:
-
Object
- Object
- Fresco::App
- Defined in:
- lib/fresco/runtime/runtime.rb
Overview
Boot class for the user’s application. Generated apps subclass this in config/app.rb (e.g. ‘class App::Base < Fresco::App`) and call `App::Base.new.run` from app.rb. Subclasses can override defaults by reassigning @port / @workers in their own initialize.
‘run` dispatches between two modes:
[serve] [-p PORT] [-w N] → HTTP listener (run_server). `serve` is
the default when no subcommand is given,
so `./build/app` and `./build/app -p 3030`
both boot the server.
METHOD PATH [BODY] → one-shot CLI dispatch (kept for smoke tests)
ARGV is referenced directly rather than passed through as a method parameter — Spinel infers ‘ARGV` as its dedicated `sp_Argv` type only at global-read sites; routing it through a Ruby parameter collapses the type to `mrb_int` and the indexing/length lowering fails. Keep all ARGV access inside these methods.
Instance Attribute Summary collapse
-
#port ⇒ Object
Returns the value of attribute port.
-
#workers ⇒ Object
Returns the value of attribute workers.
Class Method Summary collapse
-
.run ⇒ Object
Class-level convenience so app.rb is ‘App::Base.run` rather than `App::Base.new.run`.
Instance Method Summary collapse
-
#initialize ⇒ App
constructor
A new instance of App.
- #parse_serve_args ⇒ Object
- #run ⇒ Object
- #run_cli ⇒ Object
Constructor Details
#initialize ⇒ App
Returns a new instance of App.
454 455 456 457 |
# File 'lib/fresco/runtime/runtime.rb', line 454 def initialize @port = 3030 @workers = 1 end |
Instance Attribute Details
#port ⇒ Object
Returns the value of attribute port.
452 453 454 |
# File 'lib/fresco/runtime/runtime.rb', line 452 def port @port end |
#workers ⇒ Object
Returns the value of attribute workers.
452 453 454 |
# File 'lib/fresco/runtime/runtime.rb', line 452 def workers @workers end |
Class Method Details
.run ⇒ Object
Class-level convenience so app.rb is ‘App::Base.run` rather than `App::Base.new.run`. The instance carries config state; the class method exists purely to spare the caller the `.new`.
462 463 464 |
# File 'lib/fresco/runtime/runtime.rb', line 462 def self.run new.run end |
Instance Method Details
#parse_serve_args ⇒ Object
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'lib/fresco/runtime/runtime.rb', line 486 def parse_serve_args i = ARGV[0] == "serve" ? 1 : 0 while i < ARGV.length a = ARGV[i] if a == "-p" @port = ARGV[i + 1].to_i i += 2 elsif a == "-w" @workers = ARGV[i + 1].to_i i += 2 else i += 1 end end end |
#run ⇒ Object
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
# File 'lib/fresco/runtime/runtime.rb', line 466 def run # Eager-open the DB connection at startup so a misconfigured DSN # fails fast on the binary's first command rather than the first # request. Spinel-shape note: Fresco::Db.boot! is defined by the # generated db_adapter.rb when an adapter is configured; the # `respond_to?` guard keeps no-DB apps working. Fresco::Db.boot! if Fresco::Db.respond_to?(:boot!) if ARGV[0] == "db:migrate" Fresco::DbMigrations.migrate! elsif ARGV[0] == "db:rollback" Fresco::DbMigrations.rollback! elsif ARGV.length == 0 || ARGV[0] == "serve" || ARGV[0].start_with?("-") parse_serve_args run_server(port: @port, workers: @workers) else run_cli end end |