Class: Rails::Generators::Hyperdrive::SyncRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/hyperdrive/sync_runner.rb

Overview

Owns the init/sync sequence. Each phase is an idempotent memoizer and install forces the ones it needs, so no call order can install with a half-built input set.

Instance Method Summary collapse

Constructor Details

#initialize(shell:, root: nil) ⇒ SyncRunner

Returns a new instance of SyncRunner.



14
15
16
17
# File 'lib/generators/hyperdrive/sync_runner.rb', line 14

def initialize(shell:, root: nil)
  @shell = shell
  @root = root&.to_s
end

Instance Method Details

#discover_artifacts(skip: false) ⇒ Object



31
32
33
# File 'lib/generators/hyperdrive/sync_runner.rb', line 31

def discover_artifacts(skip: false)
  @artifacts ||= skip ? [] : ::Rails::Hyperdrive::BundlerArtifactDiscovery.discover(warnings: warnings)
end

#install(mode:) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/hyperdrive/sync_runner.rb', line 35

def install(mode:)
  @pipeline = ::Rails::Hyperdrive::InstallPipeline.new(
    root: root,
    shell: @shell,
    artifacts: discover_artifacts,
    mode: mode,
    warnings: warnings
  )
  @pipeline.call
end

#summary_linesObject



46
47
48
# File 'lib/generators/hyperdrive/sync_runner.rb', line 46

def summary_lines
  InstallSummary.lines(lock_entries)
end

#verify_environment!Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/generators/hyperdrive/sync_runner.rb', line 19

def verify_environment!
  unless defined?(::Rails) && ::Rails.respond_to?(:root) && ::Rails.root
    @shell.say_status :error, "must be run inside a Rails app", :red
    raise Thor::Error, "hyperdrive: not in a Rails app"
  end
  unless ::Rails.respond_to?(:env) && ::Rails.env.development?
    env = ::Rails.respond_to?(:env) ? ::Rails.env.to_s : "unknown"
    warn "hyperdrive: must run with Rails.env=development (current: #{env})"
    raise Thor::Error, "hyperdrive: refuse to run outside development (Rails.env=#{env})"
  end
end