Class: FormulaInfo Private

Inherits:
Object
  • Object
show all
Defined in:
formula_info.rb

Overview

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

Formula information drawn from an external brew info --json call.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ FormulaInfo

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 new instance of FormulaInfo.



11
12
13
# File 'formula_info.rb', line 11

def initialize(info)
  @info = info
end

Instance Attribute Details

#infoObject

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.

The whole info structure parsed from the JSON.



9
10
11
# File 'formula_info.rb', line 9

def info
  @info
end

Class Method Details

.force_utf8!(str) ⇒ Object

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.



71
72
73
# File 'formula_info.rb', line 71

def self.force_utf8!(str)
  str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
end

.lookup(name) ⇒ Object

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.

Looks up formula on disk and reads its info. Returns nil if formula is absent or if there was an error reading it.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'formula_info.rb', line 17

def self.lookup(name)
  json = Utils.popen_read(
    *HOMEBREW_RUBY_EXEC_ARGS,
    HOMEBREW_LIBRARY_PATH/"brew.rb",
    "info",
    "--json=v1",
    name,
  )

  return unless $CHILD_STATUS.success?

  force_utf8!(json)
  FormulaInfo.new(JSON.parse(json)[0])
end

Instance Method Details

#any_bottle_tagObject

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.



52
53
54
55
56
# File 'formula_info.rb', line 52

def any_bottle_tag
  tag = Utils::Bottles.tag.to_s
  # Prefer native bottles as a convenience for download caching
  bottle_tags.include?(tag) ? tag : bottle_tags.first
end

#bottle_info(my_bottle_tag = Utils::Bottles.tag) ⇒ Object

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.



38
39
40
41
42
43
44
45
46
# File 'formula_info.rb', line 38

def bottle_info(my_bottle_tag = Utils::Bottles.tag)
  tag_s = my_bottle_tag.to_s
  return unless info["bottle"]["stable"]

  btl_info = info["bottle"]["stable"]["files"][tag_s]
  return unless btl_info

  { "url" => btl_info["url"], "sha256" => btl_info["sha256"] }
end

#bottle_info_anyObject

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.



48
49
50
# File 'formula_info.rb', line 48

def bottle_info_any
  bottle_info(any_bottle_tag)
end

#bottle_tagsObject

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.



32
33
34
35
36
# File 'formula_info.rb', line 32

def bottle_tags
  return [] unless info["bottle"]["stable"]

  info["bottle"]["stable"]["files"].keys
end

#pkg_version(spec_type = :stable) ⇒ Object

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.



63
64
65
# File 'formula_info.rb', line 63

def pkg_version(spec_type = :stable)
  PkgVersion.new(version(spec_type), revision)
end

#revisionObject

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.



67
68
69
# File 'formula_info.rb', line 67

def revision
  info["revision"]
end

#version(spec_type) ⇒ Object

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.



58
59
60
61
# File 'formula_info.rb', line 58

def version(spec_type)
  version_str = info["versions"][spec_type.to_s]
  version_str && Version.create(version_str)
end