Class: FormulaInfo

Inherits:
Object
  • Object
show all
Defined in:
brew/Library/Homebrew/formula_info.rb

Overview

Formula info 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

Returns a new instance of FormulaInfo



9
10
11
# File 'brew/Library/Homebrew/formula_info.rb', line 9

def initialize(info)
  @info = info
end

Instance Attribute Details

#infoObject

The whole info structure parsed from the JSON



7
8
9
# File 'brew/Library/Homebrew/formula_info.rb', line 7

def info
  @info
end

Class Method Details

.force_utf8!(str) ⇒ Object



63
64
65
# File 'brew/Library/Homebrew/formula_info.rb', line 63

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

.lookup(name) ⇒ Object

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



15
16
17
18
19
20
21
22
# File 'brew/Library/Homebrew/formula_info.rb', line 15

def self.lookup(name)
  json = Utils.popen_read(HOMEBREW_BREW_FILE, "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



44
45
46
47
48
# File 'brew/Library/Homebrew/formula_info.rb', line 44

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



30
31
32
33
34
35
36
37
38
# File 'brew/Library/Homebrew/formula_info.rb', line 30

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



40
41
42
# File 'brew/Library/Homebrew/formula_info.rb', line 40

def bottle_info_any
  bottle_info(any_bottle_tag)
end

#bottle_tagsObject



24
25
26
27
28
# File 'brew/Library/Homebrew/formula_info.rb', line 24

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

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

#pkg_version(spec_type = :stable) ⇒ Object



55
56
57
# File 'brew/Library/Homebrew/formula_info.rb', line 55

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

#revisionObject



59
60
61
# File 'brew/Library/Homebrew/formula_info.rb', line 59

def revision
  info["revision"]
end

#version(spec_type) ⇒ Object



50
51
52
53
# File 'brew/Library/Homebrew/formula_info.rb', line 50

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