Class: TailCommandBuilder

Inherits:
GrepCommandBuilder show all
Defined in:
lib/clarity/commands/tail_command_builder.rb

Overview

Handles tailing of log files

Constant Summary

Constants inherited from GrepCommandBuilder

GrepCommandBuilder::FileParameter, GrepCommandBuilder::TermParameters

Instance Attribute Summary

Attributes inherited from GrepCommandBuilder

#filename, #options, #params, #terms

Instance Method Summary collapse

Methods inherited from GrepCommandBuilder

#bzip_tools, #exec_functions, #gzip_tools, #initialize

Constructor Details

This class inherits a constructor from GrepCommandBuilder

Instance Method Details

#commandObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/clarity/commands/tail_command_builder.rb', line 11

def command
  results = []
  exec_functions.each_with_index do |cmd, index|
    if index == 0
      results << cmd.gsub('filename', filename.to_s)
    else
      results << cmd.gsub('filename', filename.to_s).gsub('options', options.to_s).gsub('term', terms[index-1].to_s)
    end
  end
  %[sh -c '#{results.join(" | ")}']
end

#default_toolsObject



24
25
26
# File 'lib/clarity/commands/tail_command_builder.rb', line 24

def default_tools
  terms.empty? ? ['tail -n 250 -f filename'] : ['tail -n 250 -f filename'] + ['grep options -e term'] * (terms.size)
end

#valid?Boolean

Returns:

  • (Boolean)

Raises:



6
7
8
9
# File 'lib/clarity/commands/tail_command_builder.rb', line 6

def valid?
  raise InvalidParameterError, "Log file parameter not supplied or invalid log file" unless filename && !filename.empty? && File.extname(filename) == ".log"
  true
end