Class: LcpRuby::CLI::RunCommand

Inherits:
Object
  • Object
show all
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.

Constant Summary collapse

MINIMUM_RUBY_VERSION =
"3.1"
MINIMUM_RAILS_VERSION =
"8.1"

Instance Method Summary collapse

Constructor Details

#initialize(name, dir, options, shell) ⇒ RunCommand

Returns a new instance of RunCommand.



20
21
22
23
24
25
# File 'lib/lcp_ruby/cli/run_command.rb', line 20

def initialize(name, dir, options, shell)
  @name    = name.to_s.strip.empty? ? "showcase" : name.to_s.strip
  @dir     = dir
  @options = options || {}
  @shell   = shell
end

Instance Method Details

#runObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lcp_ruby/cli/run_command.rb', line 27

def run
  check_ruby_version!
  source = resolve_source!
  target = File.expand_path(@dir || "./#{@name}")
  refuse_non_empty!(target)

  say "Materializing example '#{@name}' into #{target} ...", :green
  LcpRuby::AssetCopier.copy(source, target)
  rewrite_gemfile!(target)
  remove_stale_lockfile!(target)

  warn_global_rails
  boot!(target)
end