Class: Homebrew::FormulaInfoFromJson

Inherits:
Object
  • Object
show all
Defined in:
brew/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 'brew/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 'brew/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 'brew/Library/Homebrew/dev-cmd/pull.rb', line 483

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

  return unless $CHILD_STATUS.success?

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

Instance Method Details

#any_bottle_tagObject



512
513
514
515
516
# File 'brew/Library/Homebrew/dev-cmd/pull.rb', line 512

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



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

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

  BottleInfo.new(btl_info["url"], btl_info["sha256"])
end

#bottle_info_anyObject



508
509
510
# File 'brew/Library/Homebrew/dev-cmd/pull.rb', line 508

def bottle_info_any
  bottle_info(any_bottle_tag)
end

#bottle_tagsObject



492
493
494
495
496
# File 'brew/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



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

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

#revisionObject



527
528
529
# File 'brew/Library/Homebrew/dev-cmd/pull.rb', line 527

def revision
  info["revision"]
end

#version(spec_type) ⇒ Object



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

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