Class: Strapper::Brew

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version = nil) ⇒ Brew

Returns a new instance of Brew.



6
7
8
9
# File 'lib/strapper/brew.rb', line 6

def initialize(name, version=nil)
  @name = name
  @version = version
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/strapper/brew.rb', line 4

def name
  @name
end

Instance Method Details

#formula_versionObject



39
40
41
42
43
# File 'lib/strapper/brew.rb', line 39

def formula_version
  formula_version = `brew info #{@name}`
  puts formula_version
  formula_version.split($/).first.match(/#{@name}: stable ([^\s,]+)/)[1]
end

#installObject



20
21
22
23
24
25
26
27
# File 'lib/strapper/brew.rb', line 20

def install
  brewable = `brew info #{@name}`
  if brewable[0..4] != 'Error'
    system "brew install #{@name}"
  else
    puts "Error: No available formula for #{@name}"
  end
end

#installed?Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/strapper/brew.rb', line 29

def installed?
  installed_version = `brew list --versions #{@name}`.chomp
  !installed_version.empty?
end

#installed_versionObject



34
35
36
37
# File 'lib/strapper/brew.rb', line 34

def installed_version
  installed_version = `brew list --versions #{@name}`.chomp
  installed_version.match(/#{@name} ([^\s]+)/)[1]
end

#runObject



11
12
13
14
15
16
17
18
# File 'lib/strapper/brew.rb', line 11

def run
  if installed?
    puts "Using #{name} (#{installed_version})"
  else
    puts "Installing #{name} (#{formula_version})"
    install
  end
end