Class: RakeCommandFilter::CommandDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/command_definition.rb

Overview

Base class for commands that get executed, and their output filtered rubocop:disable ClassLength

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ CommandDefinition

if a line doesn’t match any of the patterns, then

Parameters:

  • name

    a name used to identify the command in ouput



11
12
13
14
15
16
# File 'lib/command_definition.rb', line 11

def initialize(name)
  @name = name
  @default_line_handling = LINE_HANDLING_HIDE_UNTIL_ERROR
  @filters = []
  @parameters = []
end

Instance Attribute Details

#default_line_handlingObject

Returns the value of attribute default_line_handling.



6
7
8
# File 'lib/command_definition.rb', line 6

def default_line_handling
  @default_line_handling
end

#filterObject

Returns the value of attribute filter.



7
8
9
# File 'lib/command_definition.rb', line 7

def filter
  @filter
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/command_definition.rb', line 5

def name
  @name
end

Class Method Details

.find_worst_result(results) ⇒ Object

Returns the most severe result from an array of results.

Returns:

  • the most severe result from an array of results



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/command_definition.rb', line 39

def self.find_worst_result(results)
  worst = []
  results.each do |result|
    if worst.empty? || worst.first.severity < result.severity
      worst = [result]
    elsif worst.first.severity == result.severity
      worst << result
    end
  end
  return worst
end

Instance Method Details

#add_filter(id, pattern) { ... } ⇒ Object

add a new filter for output from this command

Parameters:

  • id (Symbol)

    an identifier for the filter within the command

  • pattern (RegEx)

    a regular expression which matches a pattern in a line

Yields:

  • yields back an array of matches from the pattern. The block should return a CommmandDefinition#result_… variant



23
24
25
26
# File 'lib/command_definition.rb', line 23

def add_filter(id, pattern, &block)
  filter = LineFilter.new(id, pattern, block)
  @filters << filter
end

#add_parameter(param) ⇒ Object

add a parameter to be passed to the command when executed



29
30
31
# File 'lib/command_definition.rb', line 29

def add_parameter(param)
  @parameters << param
end

#executeObject

override this method



34
35
36
# File 'lib/command_definition.rb', line 34

def execute
  return execute_system(@name)
end