Class: Csvtool::Interface::CLI::Workflows::RunRowRandomizationWorkflow

Inherits:
Object
  • Object
show all
Defined in:
lib/csvtool/interface/cli/workflows/run_row_randomization_workflow.rb

Instance Method Summary collapse

Constructor Details

#initialize(stdin:, stdout:, stderr: stdout, use_case: Application::UseCases::RunRowRandomization.new) ⇒ RunRowRandomizationWorkflow

Returns a new instance of RunRowRandomizationWorkflow.



23
24
25
26
27
28
29
30
31
32
# File 'lib/csvtool/interface/cli/workflows/run_row_randomization_workflow.rb', line 23

def initialize(stdin:, stdout:, stderr: stdout, use_case: Application::UseCases::RunRowRandomization.new)
  @stdin = stdin
  @stdout = stdout
  @stderr = stderr
  @use_case = use_case
  @errors = Interface::CLI::Errors::Presenter.new(stdout: @stderr)
  @session_builder = Builders::RowRandomizationSessionBuilder.new
  @output_destination_mapper = Support::OutputDestinationMapper.new
  @result_error_handler = Support::ResultErrorHandler.new(errors: @errors)
end

Instance Method Details

#callObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/csvtool/interface/cli/workflows/run_row_randomization_workflow.rb', line 34

def call
  context = {
    use_case: @use_case,
    session_builder: @session_builder,
    output_destination_mapper: @output_destination_mapper,
    presenter_factory: ->(headers:, col_sep:) { Presenters::RowRandomizationPresenter.new(stdout: @stdout, headers: headers, col_sep: col_sep) },
    handle_error: method(:handle_error)
  }

  pipeline = Steps::WorkflowStepPipeline.new(steps: [
    Steps::RowRandomization::CollectInputsStep.new(
      file_path_prompt: Interface::CLI::Prompts::FilePathPrompt.new(stdin: @stdin, stdout: @stderr),
      separator_prompt: Interface::CLI::Prompts::SeparatorPrompt.new(stdin: @stdin, stdout: @stderr, errors: @errors),
      headers_present_prompt: Interface::CLI::Prompts::HeadersPresentPrompt.new(stdin: @stdin, stdout: @stderr),
      seed_prompt: Interface::CLI::Prompts::SeedPrompt.new(stdin: @stdin, stdout: @stderr, errors: @errors)
    ),
    Steps::RowRandomization::CollectDestinationStep.new(
      output_destination_prompt: Interface::CLI::Prompts::OutputDestinationPrompt.new(
        stdin: @stdin,
        stdout: @stderr,
        errors: @errors
      )
    ),
    Steps::RowRandomization::ExecuteStep.new
  ])
  pipeline.call(context)
rescue ArgumentError => e
  return @errors.empty_output_path if e.message == "file output path cannot be empty"

  raise e
end