add Formulary.from_contents

This commit is contained in:
Xu Cheng 2015-09-02 16:25:46 +08:00
parent ff0f6598ce
commit 61c8f69c25

View File

@ -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?