diff options
| author | Xu Cheng | 2015-09-02 16:25:46 +0800 |
|---|---|---|
| committer | Xu Cheng | 2015-09-06 20:47:04 +0800 |
| commit | 61c8f69c25223cc696003dbf83888a6b8377d446 (patch) | |
| tree | f965dbdbd5bb10df442b9ec988bc8b26cac3d476 /Library | |
| parent | ff0f6598ce6057a36c222e2ec374d4ae37e2258a (diff) | |
| download | brew-61c8f69c25223cc696003dbf83888a6b8377d446.tar.bz2 | |
add Formulary.from_contents
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/formulary.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index e0a44c4ef..57daf236f 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? |
