Class: Cask::Tab

Inherits:
AbstractTab show all
Defined in:
cask/tab.rb

Constant Summary

Constants inherited from AbstractTab

AbstractTab::FILENAME

Instance Attribute Summary collapse

Attributes inherited from AbstractTab

#arch, #built_on, #homebrew_version, #installed_as_dependency, #installed_on_request, #loaded_from_api, #runtime_dependencies, #source, #tabfile, #time

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractTab

from_file, from_file_content, #parsed_homebrew_version, #tap, #tap=, #write

Methods included from Cachable

#cache, #clear_cache

Constructor Details

#initialize(attributes = {}) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • attributes (Hash{String => T.untyped}) (defaults to: {})


15
16
17
18
19
20
# File 'cask/tab.rb', line 15

def initialize(attributes = {})
  @uninstall_flight_blocks = T.let(nil, T.nilable(T::Boolean))
  @uninstall_artifacts = T.let(nil, T.nilable(T::Array[T.untyped]))

  super
end

Instance Attribute Details

#uninstall_artifactsArray<T.untyped>?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Array<T.untyped>, nil)


12
13
14
# File 'cask/tab.rb', line 12

def uninstall_artifacts
  @uninstall_artifacts
end

#uninstall_flight_blocksBoolean?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean, nil)


9
10
11
# File 'cask/tab.rb', line 9

def uninstall_flight_blocks
  @uninstall_flight_blocks
end

Class Method Details

.create(formula_or_cask) ⇒ T.attached_class

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Instantiates a Cask::Tab for a new installation of a cask.

Parameters:

Returns:

  • (T.attached_class)


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'cask/tab.rb', line 24

def self.create(formula_or_cask)
  cask = T.cast(formula_or_cask, Cask)
  tab = super

  tab.tabfile = cask./FILENAME
  tab.uninstall_flight_blocks = cask.uninstall_flight_blocks?
  tab.runtime_dependencies = Tab.runtime_deps_hash(cask)
  tab.source["version"] = cask.version.to_s
  tab.source["path"] = cask.sourcefile_path.to_s
  tab.uninstall_artifacts = cask.artifacts_list(uninstall_only: true)

  tab
end

.emptyT.attached_class

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (T.attached_class)


59
60
61
62
63
64
65
66
# File 'cask/tab.rb', line 59

def self.empty
  tab = super
  tab.uninstall_flight_blocks = false
  tab.uninstall_artifacts = []
  tab.source["version"] = nil

  tab
end

.for_cask(cask) ⇒ T.attached_class

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns a Cask::Tab for an already installed cask, or a fake one if the cask is not installed.

Parameters:

Returns:

  • (T.attached_class)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'cask/tab.rb', line 41

def self.for_cask(cask)
  path = cask./FILENAME

  return from_file(path) if path.exist?

  tab = empty
  tab.source = {
    "path"         => cask.sourcefile_path.to_s,
    "tap"          => cask.tap&.name,
    "tap_git_head" => cask.tap_git_head,
    "version"      => cask.version.to_s,
  }
  tab.uninstall_artifacts = cask.artifacts_list(uninstall_only: true)

  tab
end

.runtime_deps_hash(cask) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'cask/tab.rb', line 68

def self.runtime_deps_hash(cask)
  cask_and_formula_dep_graph = ::Utils::TopologicalHash.graph_package_dependencies(cask)
  cask_deps, formula_deps = cask_and_formula_dep_graph.values.flatten.uniq.partition do |dep|
    dep.is_a?(Cask)
  end

  runtime_deps = {}

  if cask_deps.any?
    runtime_deps[:cask] = cask_deps.map do |dep|
      {
        "full_name"         => dep.full_name,
        "version"           => dep.version.to_s,
        "declared_directly" => cask.depends_on.cask.include?(dep.full_name),
      }
    end
  end

  if formula_deps.any?
    runtime_deps[:formula] = formula_deps.map do |dep|
      formula_to_dep_hash(dep, cask.depends_on.formula)
    end
  end

  runtime_deps
end

Instance Method Details

#to_json(*_args) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • _args (T.untyped)

Returns:



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'cask/tab.rb', line 101

def to_json(*_args)
  attributes = {
    "homebrew_version"        => homebrew_version,
    "loaded_from_api"         => loaded_from_api,
    "uninstall_flight_blocks" => uninstall_flight_blocks,
    "installed_as_dependency" => installed_as_dependency,
    "installed_on_request"    => installed_on_request,
    "time"                    => time,
    "runtime_dependencies"    => runtime_dependencies,
    "source"                  => source,
    "arch"                    => arch,
    "uninstall_artifacts"     => uninstall_artifacts,
    "built_on"                => built_on,
  }

  JSON.pretty_generate(attributes)
end

#versionString?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



96
97
98
# File 'cask/tab.rb', line 96

def version
  source["version"]
end