diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index e0a44c4efe..57daf236ff 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -170,6 +170,23 @@ class Formulary end end + # Load formulae directly from their contents + class FormulaContentsLoader < FormulaLoader + # The formula's contents + attr_reader :contents + + def initialize(name, path, contents) + @contents = contents + super name, path + end + + def klass + STDERR.puts "#{$0} (#{self.class.name}): loading #{path}" if ARGV.debug? + namespace = "FormulaNamespace#{Digest::MD5.hexdigest(contents)}" + Formulary.load_formula(name, path, contents, namespace) + end + end + # Return a Formula instance for the given reference. # `ref` is string containing: # * a formula name @@ -199,6 +216,11 @@ class Formulary end end + # Return a Formula instance directly from contents + def self.from_contents(name, path, contents, spec = :stable) + FormulaContentsLoader.new(name, path, contents).get_formula(spec) + end + def self.to_rack(ref) # First, check whether the rack with the given name exists. if (rack = HOMEBREW_CELLAR/File.basename(ref, ".rb")).directory?