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.



16
17
18
19
# File 'lib/generators/hyperdrive/sync_runner.rb', line 16

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

Instance Method Details

#discover_artifacts(skip: false) ⇒ Object



33
34
35
36
37
# File 'lib/generators/hyperdrive/sync_runner.rb', line 33

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

#install(mode:) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/hyperdrive/sync_runner.rb', line 39

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

#summary_linesObject



51
52
53
# File 'lib/generators/hyperdrive/sync_runner.rb', line 51

def summary_lines
  InstallSummary.lines(lock_entries)
end

#verify_environment!Object



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

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