Class: BrewCaskTools::Cask

Inherits:
Thor::Shell::Basic
  • Object
show all
Defined in:
lib/bct/cask.rb

Overview

Cask control class. Implements operations on a single cask.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dirObject (readonly)

Returns the value of attribute dir.



14
15
16
# File 'lib/bct/cask.rb', line 14

def dir
  @dir
end

#infoObject (readonly)

Returns the value of attribute info.



14
15
16
# File 'lib/bct/cask.rb', line 14

def info
  @info
end

#nameObject (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

Returns:

  • (Boolean)


61
62
63
# File 'lib/bct/cask.rb', line 61

def can_cleanup?
  versions.length > 1 || .length > 1
end

#candidateObject



37
38
39
# File 'lib/bct/cask.rb', line 37

def candidate
  @versions.candidate
end

#cleanup {|_self, old| ... } ⇒ Object

Yields:

Yield Parameters:



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

#currentObject



33
34
35
# File 'lib/bct/cask.rb', line 33

def current
  @versions.current
end

#deprecated?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/bct/cask.rb', line 57

def deprecated?
  @deprecated ||= @name.include?('(!)')
end

#execObject



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

Returns:

  • (Boolean)


53
54
55
# File 'lib/bct/cask.rb', line 53

def latest?
  @versions.latest?
end

#metadataObject



49
50
51
# File 'lib/bct/cask.rb', line 49

def 
  @versions.
end

#oldObject



45
46
47
# File 'lib/bct/cask.rb', line 45

def old
  @versions.old_installed
end

#outdated?Boolean

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/bct/cask.rb', line 65

def outdated?
  return false if latest?
  candidate > current
end

#upgradeObject



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

#versionsObject



41
42
43
# File 'lib/bct/cask.rb', line 41

def versions
  @versions.installed
end