Class: Dicey::CLI::Blender Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dicey/cli/blender.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Slice and dice everything in the Dicey module to produce a useful result. This is the entry point for the CLI.

Constant Summary collapse

OPTION_TRANSFORMATIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

How to transform option values from command-line arguments to internally significant objects.

{
  mode: lambda(&:to_sym),
  result: lambda(&:to_sym),
  format: {
    "list" => Formatters::ListFormatter.new,
    "gnuplot" => Formatters::GnuplotFormatter.new,
    "yaml" => Formatters::YAMLFormatter.new,
    "json" => Formatters::JSONFormatter.new,
    "null" => Formatters::NullFormatter.new,
  }.freeze,
}.freeze
RUNNERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

What to run for every mode. Every runner must respond to ‘call(arguments, **options)` and return true, false or a String.

{
  roll: Roller.new,
  distribution: CLI::CalculatorRunner.new,
  test: CLI::CalculatorTestRunner.new,
}.freeze

Instance Method Summary collapse

Instance Method Details

#call(argv = ARGV) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run the program, blending everything together.

Parameters:

  • argv (Array<String>) (defaults to: ARGV)

    arguments for the program

Returns:

  • (Boolean)

Raises:



46
47
48
49
50
51
52
# File 'lib/dicey/cli/blender.rb', line 46

def call(argv = ARGV)
  options, arguments = get_options_and_arguments(argv)
  require_optional_libraries(options)
  return_value = RUNNERS[options.delete(:mode)].call(arguments, **options)
  print return_value if return_value.is_a?(String)
  !!return_value
end