Class: Massa::Analyzier

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verbose: false) ⇒ Analyzier

Returns a new instance of Analyzier.



18
19
20
# File 'lib/massa/analyzer.rb', line 18

def initialize(verbose: false)
  @verbose = verbose
end

Instance Attribute Details

#verboseObject (readonly) Also known as: verbose?

Returns the value of attribute verbose.



10
11
12
# File 'lib/massa/analyzer.rb', line 10

def verbose
  @verbose
end

Class Method Details

.run!(options) ⇒ Object



14
15
16
# File 'lib/massa/analyzer.rb', line 14

def self.run!(options)
  new(**options).run!
end

Instance Method Details

#execute(tool) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/massa/analyzer.rb', line 42

def execute(tool)
  command_output = ''

  if verbose?
    system(tool.command)
  else
    IO.popen(tool.command, err: %i[child out]) { |io| command_output = io.read }
  end

  return if $CHILD_STATUS.success?

  Massa::CLI.colorize :red, "¯\\_(ツ)_/¯ #{tool.description} failed:"
  Massa::CLI.colorize :yellow, "$ #{tool.command}"

  puts command_output if command_output.to_s != ''

  exit 1 if tool.required?
end

#gem_installed?(tool) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/massa/analyzer.rb', line 34

def gem_installed?(tool)
  return true if `gem query -i #{tool.name}`.chomp == 'true'

  Massa::CLI.colorize :yellow, "༼ つ ◕_◕ ༽つ '#{tool.name}' gem is not installed"

  tool.required? ? exit(1) : false
end

#run!Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/massa/analyzer.rb', line 22

def run!
  Massa::Tool.list.each do |tool|
    Massa::CLI.colorize :blue, "#{tool.description}"

    next if tool.gem? && !gem_installed?(tool)

    execute(tool)
  end

  Massa::CLI.colorize :green, '~(‾▿‾)~ All good!'
end