Class: R10K::Action::CriRunner Private

Inherits:
Object
  • Object
show all
Defined in:
lib/r10k/action/cri_runner.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.

Adapt the Cri runner interface to the R10K::Action::Runner interface

This class provides the necessary glue to translate behavior specific to Cri and the CLI component in general to the interface agnostic runner class.

Direct Known Subclasses

Puppetfile::CriRunner

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ CriRunner

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.

Returns a new instance of CriRunner.



19
20
21
# File 'lib/r10k/action/cri_runner.rb', line 19

def initialize(klass)
  @klass = klass
end

Class Method Details

.wrap(klass) ⇒ Object

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.



15
16
17
# File 'lib/r10k/action/cri_runner.rb', line 15

def self.wrap(klass)
  new(klass)
end

Instance Method Details

#callObject

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.

Invoke the wrapped behavior, determine if it succeeded, and exit with the resulting exit code.



66
67
68
69
# File 'lib/r10k/action/cri_runner.rb', line 66

def call
  rv = @runner.call
  exit(rv ? 0 : 1)
end

#handle_argv(argv) ⇒ Array

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.

Returns The adapted arguments for the runner.

Returns:

  • (Array)

    The adapted arguments for the runner



60
61
62
# File 'lib/r10k/action/cri_runner.rb', line 60

def handle_argv(argv)
  @argv = argv
end

#handle_opts(opts) ⇒ Hash

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.

Returns The adapted options for the runner.

Returns:

  • (Hash)

    The adapted options for the runner



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/r10k/action/cri_runner.rb', line 43

def handle_opts(opts)
  if opts[:verbose]
    # Translate from the Cri verbose logging option to the internal logging setting.
    opts[:loglevel] = opts.delete(:verbose)
  end

  # Colored logging is only appropriate for CLI interactions, so we
  # handle this while we're still in CLI specific code.
  use_color = opts.delete(:color)
  if use_color
    R10K::Logging.use_color = use_color
  end

  @opts = opts
end

#new(opts, argv, _cmd = nil) ⇒ self

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.

Intercept any instatiations of klass

Defining #new allows this object to proxy method calls on the wrapped runner and decorate various methods. Doing so allows this class to manage CLI specific behaviors and isolate the underlying code from having to deal with those particularities

Parameters:

  • opts (Hash)
  • argv (Array<String>)
  • _cmd (Cri::Command) (defaults to: nil)

    The command that was invoked. This value is not used and is only present to adapt the Cri interface to r10k.

Returns:

  • (self)


35
36
37
38
39
40
# File 'lib/r10k/action/cri_runner.rb', line 35

def new(opts, argv, _cmd = nil)
  handle_opts(opts)
  handle_argv(argv)
  @runner = R10K::Action::Runner.new(@opts, @argv, @klass)
  self
end