Class: Homebrew::FormulaInfoFromJson

Inherits:
Object
  • Object
show all
Defined in:
Library/Homebrew/dev-cmd/pull.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) ⇒ FormulaInfoFromJson

Returns a new instance of FormulaInfoFromJson



477
478
479
# File 'Library/Homebrew/dev-cmd/pull.rb', line 477

def initialize(info)
  @info = info
end

Instance Attribute Details

#infoObject

The whole info structure parsed from the JSON



475
476
477
# File 'Library/Homebrew/dev-cmd/pull.rb', line 475

def info
  @info
end

Class Method Details

.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



483
484
485
486
487
488
489
490
# File 'Library/Homebrew/dev-cmd/pull.rb', line 483

def self.lookup(name)
  json = Utils.popen_read(HOMEBREW_BREW_FILE, "info", "--json=v1", name)

  return nil unless $CHILD_STATUS.success?

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

Instance Method Details

#any_bottle_tagObject



509
510
511
512
513
# File 'Library/Homebrew/dev-cmd/pull.rb', line 509

def any_bottle_tag
  tag = Utils::Bottles.tag
  # 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



497
498
499
500
501
502
503
# File 'Library/Homebrew/dev-cmd/pull.rb', line 497

def bottle_info(my_bottle_tag = Utils::Bottles.tag)
  tag_s = my_bottle_tag.to_s
  return nil unless info["bottle"]["stable"]
  btl_info = info["bottle"]["stable"]["files"][tag_s]
  return nil unless btl_info
  BottleInfo.new(btl_info["url"], btl_info["sha256"])
end

#bottle_info_anyObject



505
506
507
# File 'Library/Homebrew/dev-cmd/pull.rb', line 505

def bottle_info_any
  bottle_info(any_bottle_tag)
end

#bottle_tagsObject



492
493
494
495
# File 'Library/Homebrew/dev-cmd/pull.rb', line 492

def bottle_tags
  return [] unless info["bottle"]["stable"]
  info["bottle"]["stable"]["files"].keys
end

#pkg_version(spec_type = :stable) ⇒ Object



520
521
522
# File 'Library/Homebrew/dev-cmd/pull.rb', line 520

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

#revisionObject



524
525
526
# File 'Library/Homebrew/dev-cmd/pull.rb', line 524

def revision
  info["revision"]
end

#version(spec_type) ⇒ Object



515
516
517
518
# File 'Library/Homebrew/dev-cmd/pull.rb', line 515

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