Class: Hbc::Cask

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Metadata
Defined in:
Library/Homebrew/cask/lib/hbc/cask.rb

Constant Summary

Constants included from Metadata

Metadata::METADATA_SUBDIR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Metadata

#metadata_master_container_path, #metadata_subdir, #metadata_timestamped_path, #metadata_versioned_path

Constructor Details

#initialize(token, sourcefile_path: nil, tap: nil, config: Config.global, &block) ⇒ Cask

Returns a new instance of Cask



16
17
18
19
20
21
22
23
24
25
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 16

def initialize(token, sourcefile_path: nil, tap: nil, config: Config.global, &block)
  @token = token
  @sourcefile_path = sourcefile_path
  @tap = tap
  @config = config
  @dsl = DSL.new(self)
  return unless block_given?
  @dsl.instance_eval(&block)
  @dsl.language_eval
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config



9
10
11
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 9

def config
  @config
end

#sourcefile_pathObject (readonly)

Returns the value of attribute sourcefile_path



9
10
11
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 9

def sourcefile_path
  @sourcefile_path
end

#tokenObject (readonly)

Returns the value of attribute token



9
10
11
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 9

def token
  @token
end

Instance Method Details

#dumpcaskObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 99

def dumpcask
  odebug "Cask instance dumps in YAML:"
  odebug "Cask instance toplevel:", to_yaml
  [
    :name,
    :homepage,
    :url,
    :appcast,
    :version,
    :sha256,
    :artifacts,
    :caveats,
    :depends_on,
    :conflicts_with,
    :container,
    :gpg,
    :accessibility_access,
    :auto_updates,
  ].each do |method|
    odebug "Cask instance method '#{method}':", send(method).to_yaml
  end
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


94
95
96
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 94

def eql?(other)
  token == other.token
end

#full_nameObject



45
46
47
48
49
50
51
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 45

def full_name
  if @tap.nil? || @tap == Hbc.default_tap
    token
  else
    "#{@tap}/#{token}"
  end
end

#hashObject



90
91
92
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 90

def hash
  token.hash
end

#installed?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 53

def installed?
  !versions.empty?
end

#installed_caskfileObject



57
58
59
60
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 57

def installed_caskfile
  installed_version = timestamped_versions.last
  .join(*installed_version, "Casks", "#{token}.rb")
end

#outdated?(greedy = false) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 62

def outdated?(greedy = false)
  !outdated_versions(greedy).empty?
end

#outdated_versions(greedy = false) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 66

def outdated_versions(greedy = false)
  # special case: tap version is not available
  return [] if version.nil?

  if greedy
    return versions if version.latest?
  elsif auto_updates
    return []
  end

  installed = versions
  current   = installed.last

  # not outdated unless there is a different version on tap
  return [] if current == version

  # collect all installed versions that are different than tap version and return them
  installed.reject { |v| v == version }
end

#tapObject



11
12
13
14
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 11

def tap
  return super if block_given? # Object#tap
  @tap
end

#timestamped_versionsObject



31
32
33
34
35
36
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 31

def timestamped_versions
  Pathname.glob((version: "*", timestamp: "*"))
          .map { |p| p.relative_path_from(p.parent.parent) }
          .sort_by(&:basename) # sort by timestamp
          .map { |p| p.split.map(&:to_s) }
end

#to_sObject



86
87
88
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 86

def to_s
  @token
end

#versionsObject



38
39
40
41
42
43
# File 'Library/Homebrew/cask/lib/hbc/cask.rb', line 38

def versions
  timestamped_versions.map(&:first)
                      .reverse
                      .uniq
                      .reverse
end