Class: BrewCaskTools::Cask
- Inherits:
-
Thor::Shell::Basic
- Object
- Thor::Shell::Basic
- BrewCaskTools::Cask
- Defined in:
- lib/bct/cask.rb
Overview
Cask control class. Implements operations on a single cask.
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #can_cleanup? ⇒ Boolean
- #candidate ⇒ Object
- #cleanup {|_self, old| ... } ⇒ Object
- #current ⇒ Object
- #deprecated? ⇒ Boolean
- #exec ⇒ Object
-
#initialize(name) ⇒ Cask
constructor
A new instance of Cask.
- #latest? ⇒ Boolean
- #metadata ⇒ Object
- #old ⇒ Object
- #outdated? ⇒ Boolean
- #upgrade ⇒ Object
- #versions ⇒ Object
Constructor Details
#initialize(name) ⇒ Cask
Returns a new instance of Cask.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bct/cask.rb', line 16 def initialize(name) super() @name = name if deprecated? info = [] @name = name.delete(' (!)') else info = `brew cask info #{name}`.split("\n") end @info = Casks::Info.new(info) @dir = File.join(CASKROOM, @name) @versions = Casks::Versions.new(@dir, @info.short_name.sub("#{@name}: ", '')) end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
14 15 16 |
# File 'lib/bct/cask.rb', line 14 def dir @dir end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
14 15 16 |
# File 'lib/bct/cask.rb', line 14 def info @info end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/bct/cask.rb', line 14 def name @name end |
Instance Method Details
#can_cleanup? ⇒ Boolean
61 62 63 |
# File 'lib/bct/cask.rb', line 61 def can_cleanup? versions.length > 1 || .length > 1 end |
#candidate ⇒ Object
37 38 39 |
# File 'lib/bct/cask.rb', line 37 def candidate @versions.candidate end |
#cleanup {|_self, old| ... } ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/bct/cask.rb', line 94 def cleanup return unless can_cleanup? if deprecated? yield self, versions # Delete the whole cask ::FileUtils.rm_rf(@dir, secure: true, verbose: true) return end yield self, old @versions.rm_old end |
#current ⇒ Object
33 34 35 |
# File 'lib/bct/cask.rb', line 33 def current @versions.current end |
#deprecated? ⇒ Boolean
57 58 59 |
# File 'lib/bct/cask.rb', line 57 def deprecated? @deprecated ||= @name.include?('(!)') end |
#exec ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/bct/cask.rb', line 70 def exec Open3.popen2e("brew cask install #{@name} --force") do |_stdin, stdout_err, _wait_thr| line = '' while line line = stdout_err.gets puts line end end end |
#latest? ⇒ Boolean
53 54 55 |
# File 'lib/bct/cask.rb', line 53 def latest? @versions.latest? end |
#metadata ⇒ Object
49 50 51 |
# File 'lib/bct/cask.rb', line 49 def @versions. end |
#old ⇒ Object
45 46 47 |
# File 'lib/bct/cask.rb', line 45 def old @versions.old_installed end |
#outdated? ⇒ Boolean
65 66 67 68 |
# File 'lib/bct/cask.rb', line 65 def outdated? return false if latest? candidate > current end |
#upgrade ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/bct/cask.rb', line 80 def upgrade return say "#{@name} uses the `latest` convention. " \ 'Homebrew cask does not upgrade casks marked as ' \ '`latest`. Use another method of determining if ' \ 'this application has an upgrade', :green if latest? return say "You have the most recent version of #{@name}. " \ 'It cannot be upgraded', :green unless outdated? say "Installing #{@name} (#{candidate})", :cyan exec say "Upgraded #{@name} to version #{candidate}", :green end |
#versions ⇒ Object
41 42 43 |
# File 'lib/bct/cask.rb', line 41 def versions @versions.installed end |