Class: LcpRuby::CLI::RunCommand
- Inherits:
-
Object
- Object
- LcpRuby::CLI::RunCommand
- Defined in:
- lib/lcp_ruby/cli/run_command.rb
Overview
Backs ‘lcp run [NAME] [DIR]` — materialize a bundled example app into a writable dir and boot it. Bundled examples cannot run in place (their Gemfile pins `gem “lcp”, path: “../..”` against the checkout, and the installed gem dir is typically read-only), so this copies the source, rewrites the Gemfile to depend on the installed `lcp`, then bundles, prepares the DB, and starts the server. Rails-free at invocation.
Idempotent: the first run drops a MARKER dotfile in the target. A second ‘lcp run` on the same dir detects that marker and re-boots the existing app (skipping materialize + Gemfile rewrite, and using `db:prepare` so existing data survives) instead of aborting. A non-empty dir WITHOUT the marker is still refused — it’s likely the user’s own files, not our example.
Constant Summary collapse
- MINIMUM_RUBY_VERSION =
"3.1"- MINIMUM_RAILS_VERSION =
"8.1"- MARKER =
Dotfile written into a materialized app so a later ‘lcp run` recognizes it as ours and re-boots instead of refusing the non-empty dir. A dotfile so it never propagates via AssetCopier (its glob skips dotfiles).
".lcp-run"
Instance Method Summary collapse
-
#initialize(name, dir, options, shell) ⇒ RunCommand
constructor
A new instance of RunCommand.
- #run ⇒ Object
Constructor Details
#initialize(name, dir, options, shell) ⇒ RunCommand
Returns a new instance of RunCommand.
31 32 33 34 35 36 |
# File 'lib/lcp_ruby/cli/run_command.rb', line 31 def initialize(name, dir, , shell) @name = name.to_s.strip.empty? ? "showcase" : name.to_s.strip @dir = dir @options = || {} @shell = shell end |
Instance Method Details
#run ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lcp_ruby/cli/run_command.rb', line 38 def run check_ruby_version! target = File.(@dir || "./#{@name}") if materialized?(target) reuse!(target) else materialize!(target) end end |