Module: Ibex::CLIWatch

Defined in:
lib/ibex/cli/watch.rb,
sig/ibex/cli/watch.rbs

Overview

Long-running CLI generation over stable source snapshots.

Defined Under Namespace

Classes: Build

Instance Method Summary collapse

Instance Method Details

#prepare_watch_generation(path) ⇒ Build

RBS:

  • (String path) -> Build

Parameters:

  • path (String)

Returns:



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ibex/cli/watch.rb', line 57

def prepare_watch_generation(path)
  @defer_generation_publication = true
  status = process_grammar(path)
  raise Ibex::Error, "(watch):1:1: generation returned status #{status}" unless status.zero?

  Build.new(
    artifacts: generation_artifacts,
    statuses: @generation_statuses.dup,
    source_paths: @generation_sources.dup,
    attempted_paths: @last_resolver&.attempted_paths || [],
    source_records: @generation_inputs.dup
  )
ensure
  @defer_generation_publication = false
end

#publish_watch_generation(build, snapshot, continue) ⇒ void

This method returns an undefined value.

RBS:

  • (Build build, Watch::SourceSnapshot snapshot, ^() -> bool continue) -> void

Parameters:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ibex/cli/watch.rb', line 74

def publish_watch_generation(build, snapshot, continue)
  stable = lambda do
    continue.call && build.source_records.all?(&:current?) &&
      Watch::SourceSnapshot.new(snapshot.paths) == snapshot
  end
  GenerationTransaction.new(
    build.artifacts,
    warning: ->(message) { @stderr.puts("ibex: warning: #{message}") },
    stability_check: stable,
    source_records: build.source_records,
    lock_sleeper: @watch_sleeper
  ).commit
  build.statuses.each { |message| report_status(message) }
end

#run_watch(path) ⇒ Integer

RBS:

  • (String path) -> Integer

Parameters:

  • path (String)

Returns:

  • (Integer)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ibex/cli/watch.rb', line 39

def run_watch(path)
  raise Ibex::Error, "(cli):1:1: --watch requires a grammar file, not stdin" if path == "-"

  paths = [path]
  paths << @options[:messages] if @options[:messages]
  Watch::Runner.new(
    paths: paths,
    build: -> { prepare_watch_generation(path) },
    publish: ->(build, snapshot, continue) { publish_watch_generation(build, snapshot, continue) },
    failure_paths: -> { watch_failure_paths(path) },
    stderr: @stderr,
    clock: @watch_clock,
    sleeper: @watch_sleeper,
    iteration_hook: @watch_iteration_hook
  ).run
end

#watch_failure_paths(path) ⇒ Array[String]

RBS:

  • (String path) -> Array[String]

Parameters:

  • path (String)

Returns:

  • (Array[String])


90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/ibex/cli/watch.rb', line 90

def watch_failure_paths(path)
  paths = [path]
  paths << @options[:messages] if @options[:messages]
  paths.concat(@last_resolver.attempted_paths) if @last_resolver
  unless @generation_artifacts.nil?
    generation_artifacts.each do |artifact|
      paths << artifact.path
      paths << File.dirname(artifact.path)
    end
  end
  paths.compact
end