Class: RVGP::Base::Command::ReconcilerTarget

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

Overview

This is an implementation of Target, that matches Reconcilers.

This class allows any of the current project’s reconcilers to match a target. And, such targets can be selected by way of a:

  • full reconciler path

  • reconciler file basename (without the full path)

  • the reconciler’s from field

  • the reconciler’s label field

  • the reconciler’s input file

  • the reconciler’s output file

Any class that operates by way of a reconciler-defined target, can use this implementation, in lieu of re-implementing the wheel.

Instance Attribute Summary

Attributes inherited from Target

#name, #status_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Target

from_s

Constructor Details

#initialize(reconciler) ⇒ ReconcilerTarget

Create a new ReconcilerTarget

Parameters:



89
90
91
92
# File 'lib/rvgp/base/command.rb', line 89

def initialize(reconciler)
  super reconciler.as_taskname, reconciler.label
  @reconciler = reconciler
end

Class Method Details

.allArray<RVGP::Base::Command::ReconcilerTarget>

All possible Reconciler Targets that the project has defined.

Returns:



106
107
108
# File 'lib/rvgp/base/command.rb', line 106

def self.all
  RVGP.app.reconcilers.map { |reconciler| new reconciler }
end

.commandSymbol

Returns which command this class is defined for. See the note in #for_command.

Returns:

  • (Symbol)

    The command this target is relevant for.



122
123
124
# File 'lib/rvgp/base/command.rb', line 122

def self.command
  @for_command
end

.for_command(underscorized_command_name) ⇒ Object

This is a little goofy. But, it exists as a hack to support dispatching this target via the command method. You can see an example of this at work in the reconcile.rb file.

Parameters:

  • underscorized_command_name (Symbol)

    The command to return, when command is called.



115
116
117
# File 'lib/rvgp/base/command.rb', line 115

def self.for_command(underscorized_command_name)
  @for_command = underscorized_command_name
end

Instance Method Details

#descriptionObject

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



100
101
102
# File 'lib/rvgp/base/command.rb', line 100

def description
  I18n.t format('commands.%s.target_description', self.class.command), input_file: @reconciler.input_file
end

#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



95
96
97
# File 'lib/rvgp/base/command.rb', line 95

def matches?(identifier)
  @reconciler.matches_argument? identifier
end