# Class: Cri::CommandRunner

Inherits:
  Object
  - Object
  - Cri::CommandRunner
  show all

Defined in:
  lib/cri/command_runner.rb

## Overview

A command runner is responsible for the execution of a command. Using it is optional, but it is useful for commands whose execution block is large.

## Instance Attribute Summary collapse

- #arguments ⇒ Array readonly

  The list of arguments.

- #command ⇒ Command readonly

  The command.

- #options ⇒ Hash readonly

  A hash contain the options and their values.

## Instance Method Summary collapse

- #call ⇒ void

  Runs the command.

- #initialize(options, arguments, command) ⇒ CommandRunner constructor

  Creates a command runner from the given options, arguments and command.

- #run ⇒ void abstract

  Performs the actual execution of the command.

## Constructor Details

### #initialize(options, arguments, command) ⇒ `CommandRunner`

Creates a command runner from the given options, arguments and command.

Parameters:

- options (`Hash`) —

  A hash contain the options and their values

- arguments (`Array`) —

  The list of arguments

- command (`Cri::Command`) —

  The Cri command

    21
    22
    23
    24
    25

    # File 'lib/cri/command_runner.rb', line 21

    def initialize(options, arguments, command)
      @options   = options
      @arguments = arguments
      @command   = command
    end

## Instance Attribute Details

### #arguments ⇒ `Array` (readonly)

Returns The list of arguments

Returns:

- (`Array`) —

  The list of arguments

    9
    10
    11

    # File 'lib/cri/command_runner.rb', line 9

    def arguments
      @arguments
    end

### #command ⇒ `Command` (readonly)

Returns The command

Returns:

- (`Command`) —

  The command

    12
    13
    14

    # File 'lib/cri/command_runner.rb', line 12

    def command
      @command
    end

### #options ⇒ `Hash` (readonly)

Returns A hash contain the options and their values

Returns:

- (`Hash`) —

  A hash contain the options and their values

    6
    7
    8

    # File 'lib/cri/command_runner.rb', line 6

    def options
      @options
    end

## Instance Method Details

### #call ⇒ `void`

This method returns an undefined value.

Runs the command. By default, this simply does the actual execution, but subclasses may choose to add error handling around the actual execution.

    31
    32
    33

    # File 'lib/cri/command_runner.rb', line 31

    def call
      run
    end

### #run ⇒ `void`

This method is abstract.

This method returns an undefined value.

Performs the actual execution of the command.

Raises:

- (`NotImplementedError`)

    40
    41
    42

    # File 'lib/cri/command_runner.rb', line 40

    def run
      raise NotImplementedError, 'Cri::CommandRunner subclasses must implement #run'
    end