Class: TapDance::Brew
- Inherits:
-
Object
- Object
- TapDance::Brew
- Defined in:
- lib/tap_dance/brew.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#tap ⇒ Object
Returns the value of attribute tap.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#brewable? ⇒ Boolean
Does the formula exist?.
- #canonical ⇒ Object
- #formula_version ⇒ Object
- #formula_versions ⇒ Object
-
#initialize(name, version = nil, opts = {}) ⇒ Brew
constructor
A new instance of Brew.
- #install ⇒ Object
-
#installed? ⇒ Boolean
Is a version installed?.
- #installed_versions ⇒ Object
- #latest_version ⇒ Object
- #to_s ⇒ Object
- #upgrade ⇒ Object
Constructor Details
#initialize(name, version = nil, opts = {}) ⇒ Brew
Returns a new instance of Brew.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tap_dance/brew.rb', line 10 def initialize(name, version=nil, opts={}) @opts = opts.dup @name = name.to_s @version = version @tap = @opts[:tap] @flags = @opts[:flags] || [] # Get actual tap object unless @tap.nil? case @tap when String, Symbol @tap = @opts[:definition].tap_named @tap.to_s when TapDance::Tap # Good to go! end @opts[:tap] = @tap end end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/tap_dance/brew.rb', line 6 def name @name end |
#tap ⇒ Object
Returns the value of attribute tap.
8 9 10 |
# File 'lib/tap_dance/brew.rb', line 8 def tap @tap end |
#version ⇒ Object
Returns the value of attribute version.
7 8 9 |
# File 'lib/tap_dance/brew.rb', line 7 def version @version end |
Instance Method Details
#brewable? ⇒ Boolean
Does the formula exist?
57 58 59 |
# File 'lib/tap_dance/brew.rb', line 57 def brewable? BrewCLI.formula_info(canonical).okay? end |
#canonical ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/tap_dance/brew.rb', line 48 def canonical unless @tap.nil? "#{@tap.url}/#{@name}" else @name end end |
#formula_version ⇒ Object
61 62 63 64 65 66 |
# File 'lib/tap_dance/brew.rb', line 61 def formula_version res = BrewCLI.formula_info(canonical) return nil unless res.okay? res.out.split($/).first.match(/#{name}: stable ([^\s,]+)/)[1] end |
#formula_versions ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/tap_dance/brew.rb', line 68 def formula_versions # Takes a long time to get; cache return if @formula_versions.nil? @formula_versions = BrewCLI.formula_versions(canonical). out.chomp.split($/).map do |v| s = v.split(/\s+/) version = s[0] commit = s[3] path = s[4] [ version, commit, path ] end else return @formula_versions end end |
#install ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/tap_dance/brew.rb', line 30 def install if brewable? # Do magic here BrewCLI.install canonical, @flags else TapDance.ui.error "No available formula for \"#{canonical}\"" end end |
#installed? ⇒ Boolean
Is a version installed?
95 96 97 |
# File 'lib/tap_dance/brew.rb', line 95 def installed? !installed_versions.empty? end |
#installed_versions ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/tap_dance/brew.rb', line 84 def installed_versions # Would love to use StringScanner...but we don't need to! versions = BrewCLI.list_versions(canonical).out.strip.split(/\s+/) unless versions.empty? return versions[1..-1] else return [] end end |
#latest_version ⇒ Object
99 100 101 102 103 |
# File 'lib/tap_dance/brew.rb', line 99 def latest_version # Works unless the versions have # strings in them, like alpha/beta installed_versions.sort.last if installed? end |
#to_s ⇒ Object
105 106 107 |
# File 'lib/tap_dance/brew.rb', line 105 def to_s return canonical end |