Class: Formulary::FromPathLoader Private

Inherits:
FormulaLoader show all
Defined in:
formulary.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.

Loads formulae from disk using a path.

Instance Attribute Summary

Attributes inherited from FormulaLoader

#alias_path, #name, #path, #tap

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FormulaLoader

#get_formula, #klass

Methods included from Utils::Output::Mixin

#odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

Constructor Details

#initialize(path, alias_path: nil, tap: nil) ⇒ 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:



646
647
648
649
650
651
652
653
654
655
# File 'formulary.rb', line 646

def initialize(path, alias_path: nil, tap: nil)
  path = Pathname(path).expand_path
  name = path.basename(".rb").to_s
  alias_path = alias_path&.expand_path
  alias_dir = alias_path&.dirname

  alias_path = nil if alias_dir != tap&.alias_dir

  super(name, path, alias_path:, tap:)
end

Class Method Details

.try_new(ref, from: nil, warn: false) ⇒ 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.

Parameters:

  • ref (String, Pathname, URI::Generic)
  • from (Symbol, nil) (defaults to: nil)
  • warn (Boolean) (defaults to: false)

Returns:

  • (T.attached_class, nil)


605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
# File 'formulary.rb', line 605

def self.try_new(ref, from: nil, warn: false)
  path = case ref
  when String
    Pathname(ref)
  when Pathname
    ref
  else
    return
  end

  return unless path.expand_path.exist?
  return unless ::Utils::Path.loadable_package_path?(path, :formula)

  if Homebrew::EnvConfig.use_internal_api?
    # If the path is for an installed keg, use FromKegLoader instead
    begin
      keg = Keg.for(path)
      loader = FromKegLoader.try_new(keg.name, from:, warn:)
      return T.cast(loader, T.attached_class)
    rescue NotAKegError
      # Not a keg path, continue
    end
  end

  if (tap = Tap.from_path(path))
    # Only treat symlinks in taps as aliases.
    if path.symlink?
      alias_path = path
      path = alias_path.resolved_path
    end
  else
    # Don't treat cache symlinks as aliases.
    tap = Homebrew::API.tap_from_source_download(path)
  end

  return if path.extname != ".rb"

  new(path, alias_path:, tap:)
end