Class: Pronto::GolangTools::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/pronto/golang/tools/base.rb

Direct Known Subclasses

GolangCiLint, Golint, Gosec, Govet, Staticcheck

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Base

Returns a new instance of Base.



12
13
14
# File 'lib/pronto/golang/tools/base.rb', line 12

def initialize(config)
  @config = config
end

Class Method Details

.base_commandObject



4
5
6
# File 'lib/pronto/golang/tools/base.rb', line 4

def self.base_command
  raise 'base_command needs to be overwritten in inheritance'
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/pronto/golang/tools/base.rb', line 24

def available?
  installed? && enabled?
end

#base_commandObject



8
9
10
# File 'lib/pronto/golang/tools/base.rb', line 8

def base_command
  self.class.base_command
end

#command(file_path) ⇒ Object



16
17
18
# File 'lib/pronto/golang/tools/base.rb', line 16

def command(file_path)
  "#{base_command} #{parameters} #{file_path}"
end

#enabled?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/pronto/golang/tools/base.rb', line 32

def enabled?
  @config.fetch('enabled', true) # Default to true if the key is not configured
end

#installed?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/pronto/golang/tools/base.rb', line 28

def installed?
  `which #{base_command}` != ""
end

#parametersObject



20
21
22
# File 'lib/pronto/golang/tools/base.rb', line 20

def parameters
  @config.fetch('parameters', '') # Default to '' if the key is not configured
end

#parse_line(line) ⇒ Object



36
37
38
39
40
# File 'lib/pronto/golang/tools/base.rb', line 36

def parse_line(line)
  file_path, line_number, _, message = line.split(':', 4)

  return file_path, line_number, :warning, message.to_s.strip
end