Class: Strapper::Brew
- Inherits:
-
Object
- Object
- Strapper::Brew
- Defined in:
- lib/strapper/brew.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #formula_version ⇒ Object
-
#initialize(name, version = nil) ⇒ Brew
constructor
A new instance of Brew.
- #install ⇒ Object
- #installed? ⇒ Boolean
- #installed_version ⇒ Object
- #run ⇒ Object
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
#name ⇒ Object (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_version ⇒ Object
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 |
#install ⇒ Object
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
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_version ⇒ Object
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 |
#run ⇒ Object
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 |