Class: RVGP::Base::Command::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/rvgp/base/command.rb

Overview

Targets are, as the name would imply, a command line argument, that isn’t prefixed with one or more dashes. Whereas some arguments are program options, targets are typically a specific subject or destination, which the command is applied to.

This base class offers common functions for navigating targets, and identifying targets on the command line. This is a base class, which would generally find an inheritor inside a specific command’s implementation.

Direct Known Subclasses

PlotTarget, ReconcilerTarget

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, status_name = nil) ⇒ Target

Create a new Target

Parameters:



51
52
53
54
# File 'lib/rvgp/base/command.rb', line 51

def initialize(name, status_name = nil)
  @name = name
  @status_name = status_name
end

Instance Attribute Details

#descriptionString (readonly)

A description of this target. Mostly this is used by rake, to describe this target in the ‘rake -T’ output.

Returns:

  • (String)

    the current value of description



45
46
47
# File 'lib/rvgp/base/command.rb', line 45

def description
  @description
end

#nameString (readonly)

The target name, as it would be expected to be found on the CLI

Returns:

  • (String)

    the current value of name



45
46
47
# File 'lib/rvgp/base/command.rb', line 45

def name
  @name
end

#status_nameString (readonly)

The target name, as it would be expected to appear in the status output, which is generally displayed during the processing of this target during the rake process and/or during an rvgp-triggered process.

Returns:

  • (String)

    the current value of status_name



45
46
47
# File 'lib/rvgp/base/command.rb', line 45

def status_name
  @status_name
end

Class Method Details

.from_s(str) ⇒ Target

Find the target that matches the provided string

Parameters:

  • str (String)

    A string which expresses which needle, we want to find, in this haystack.

Returns:

  • (Target)

    The target we matched this string against.



66
67
68
# File 'lib/rvgp/base/command.rb', line 66

def self.from_s(str)
  all.find_all { |target| target.matches? str }
end

Instance Method Details

#matches?(identifier) ⇒ TrueClass, FalseClass

Returns true, if the provided identifier matches this target

Parameters:

  • identifier (String)

    A target that was encountered on the CLI

Returns:

  • (TrueClass, FalseClass)

    whether we’re the target specified



59
60
61
# File 'lib/rvgp/base/command.rb', line 59

def matches?(identifier)
  File.fnmatch? identifier, name
end