add Formulary.from_contents
This commit is contained in:
parent
ff0f6598ce
commit
61c8f69c25
@ -170,6 +170,23 @@ class Formulary
|
|||||||
end
|
end
|
||||||
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.
|
# Return a Formula instance for the given reference.
|
||||||
# `ref` is string containing:
|
# `ref` is string containing:
|
||||||
# * a formula name
|
# * a formula name
|
||||||
@ -199,6 +216,11 @@ class Formulary
|
|||||||
end
|
end
|
||||||
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)
|
def self.to_rack(ref)
|
||||||
# First, check whether the rack with the given name exists.
|
# First, check whether the rack with the given name exists.
|
||||||
if (rack = HOMEBREW_CELLAR/File.basename(ref, ".rb")).directory?
|
if (rack = HOMEBREW_CELLAR/File.basename(ref, ".rb")).directory?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user