Class: Jrf::CLI::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/jrf/cli/runner.rb

Defined Under Namespace

Classes: ParallelFrameReader

Constant Summary collapse

DEFAULT_OUTPUT_BUFFER_LIMIT =
4096
PARALLEL_FRAME_HEADER_BYTES =
4

Instance Method Summary collapse

Constructor Details

#initialize(input: $stdin, out: $stdout, err: $stderr, lax: false, output_format: :json, atomic_write_bytes: DEFAULT_OUTPUT_BUFFER_LIMIT) ⇒ Runner

Returns a new instance of Runner.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/jrf/cli/runner.rb', line 62

def initialize(input: $stdin, out: $stdout, err: $stderr, lax: false, output_format: :json, atomic_write_bytes: DEFAULT_OUTPUT_BUFFER_LIMIT)
  if input.is_a?(Array)
    @file_paths = input
    @stdin = nil
  else
    @file_paths = []
    @stdin = input
  end
  @out = out
  @err = err
  @lax = lax
  @output_format = output_format
  @atomic_write_bytes = atomic_write_bytes
  @output_buffer = +""
  @input_errors = false
end

Instance Method Details

#input_errors?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/jrf/cli/runner.rb', line 79

def input_errors?
  @input_errors
end

#run(expression, parallel: 1, verbose: false) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/jrf/cli/runner.rb', line 83

def run(expression, parallel: 1, verbose: false)
  blocks = build_stage_blocks(expression, verbose: verbose)
  if @output_format == :tsv
    values = []
    process_values(blocks, parallel: parallel, verbose: verbose) do |value|
      values << value
    end
    emit_tsv(values)
  else
    process_values(blocks, parallel: parallel, verbose: verbose) do |value|
      emit_output(value)
    end
  end
ensure
  write_output(@output_buffer)
end