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 Context

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

Constructor Details

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



689
690
691
692
693
694
695
696
697
698
699
700
701
# File 'formulary.rb', line 689

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

  options = {
    alias_path: (alias_path if alias_dir == tap&.alias_dir),
    tap:,
  }.compact

  super(name, path, **options)
end

Class Method Details

.try_new(ref, from: T.unsafe(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) (defaults to: T.unsafe(nil))
  • warn (Boolean) (defaults to: false)

Returns:

  • (T.attached_class, nil)


647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
# File 'formulary.rb', line 647

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

  return unless path.expand_path.exist?

  options = if (tap = Tap.from_path(path))
    # Only treat symlinks in taps as aliases.
    if path.symlink?
      alias_path = path
      path = alias_path.resolved_path

      {
        alias_path:,
        tap:,
      }
    else
      {
        tap:,
      }
    end
  elsif (tap = Homebrew::API.tap_from_source_download(path))
    # Don't treat cache symlinks as aliases.
    {
      tap:,
    }
  else
    {}
  end

  return if path.extname != ".rb"

  new(path, **options)
end