Class: HomebrewAnalyzer

Inherits:
DepAnalyzer show all
Defined in:
lib/homebrew_analyzer.rb

Overview

:stopdoc:

Constant Summary collapse

SHH =
"2> /dev/null"

Instance Attribute Summary collapse

Attributes inherited from DepAnalyzer

#g

Instance Method Summary collapse

Methods inherited from DepAnalyzer

#decorate, #initialize, #run, #setup

Methods inherited from Cache

#cache, #initialize

Constructor Details

This class inherits a constructor from DepAnalyzer

Instance Attribute Details

#casksObject

Returns the value of attribute casks.



8
9
10
# File 'lib/homebrew_analyzer.rb', line 8

def casks
  @casks
end

Instance Method Details

#alldepsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/homebrew_analyzer.rb', line 28

def alldeps
  # there's YET ANOTHER bug in homebrew whereby `brew deps -1
  # --installed` output is painfully different from all other output:
  #
  # % brew deps -1 --for-each pango
  #   pango: cairo fontconfig freetype fribidi glib harfbuzz
  # % brew deps -1 --installed | grep pango
  #   pango: cairo

  @alldeps ||= begin
    full_names = `brew list --full-name`.split
    `brew deps -n1 --for-each #{full_names.join " "}`
      .lines
      .map { |l| k, *v = l.delete(":").split; [clean(k), v] }
      .to_h
  end
end

#clean(name) ⇒ Object



55
56
57
# File 'lib/homebrew_analyzer.rb', line 55

def clean name
  name.split("/").last
end

#deps(port) ⇒ Object



46
47
48
49
# File 'lib/homebrew_analyzer.rb', line 46

def deps port
  return [] if @casks.include? port
  alldeps[port] ||= `brew deps #{port}`.scan(/\S+/)
end

#installedObject



10
11
12
13
14
15
16
17
# File 'lib/homebrew_analyzer.rb', line 10

def installed
  # don't cache so it updates every delete
  puts "scanning installed ports"
  ports = normal `brew list #{SHH}`
  puts "scanning installed casks"
  self.casks = normal `brew list --cask #{SHH}`
  ports + casks
end

#normal(lines) ⇒ Object



51
52
53
# File 'lib/homebrew_analyzer.rb', line 51

def normal lines
  lines.split(/\n/).map { |s| clean s }
end

#outdatedObject



19
20
21
22
23
24
25
26
# File 'lib/homebrew_analyzer.rb', line 19

def outdated
  # don't cache so it updates every delete
  puts "scanning outdated ports"
  ports = normal `brew outdated #{SHH}`
  puts "scanning outdated casks"
  casks = normal `brew outdated --cask #{SHH}`
  ports + casks
end