diff options
| author | Xu Cheng | 2015-09-02 16:12:26 +0800 |
|---|---|---|
| committer | Xu Cheng | 2015-09-06 20:47:03 +0800 |
| commit | ff0f6598ce6057a36c222e2ec374d4ae37e2258a (patch) | |
| tree | beb50b92245343b943d30413b1804bf2983ca169 /Library | |
| parent | cbb91c5516ac6d2a673670edf5b7d509abe6df56 (diff) | |
| download | brew-ff0f6598ce6057a36c222e2ec374d4ae37e2258a.tar.bz2 | |
Formulary: allow loading formula from contents
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/formulary.rb | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 3198ebad2..e0a44c4ef 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -15,22 +15,26 @@ class Formulary FORMULAE.fetch(path) end - def self.load_formula(name, path) + def self.load_formula(name, path, contents, namespace) mod = Module.new - const_set("FormulaNamespace#{Digest::MD5.hexdigest(path.to_s)}", mod) - contents = path.open("r") { |f| set_encoding(f).read } + const_set(namespace, mod) mod.module_eval(contents, path) class_name = class_s(name) begin - klass = mod.const_get(class_name) + mod.const_get(class_name) rescue NameError => e raise FormulaUnavailableError, name, e.backtrace - else - FORMULAE[path] = klass end end + def self.load_formula_from_path(name, path) + contents = path.open("r") { |f| set_encoding(f).read } + namespace = "FormulaNamespace#{Digest::MD5.hexdigest(path.to_s)}" + klass = load_formula(name, path, contents, namespace) + FORMULAE[path] = klass + end + if IO.method_defined?(:set_encoding) def self.set_encoding(io) io.set_encoding(Encoding::UTF_8) @@ -76,7 +80,7 @@ class Formulary def load_file STDERR.puts "#{$0} (#{self.class.name}): loading #{path}" if ARGV.debug? raise FormulaUnavailableError.new(name) unless path.file? - Formulary.load_formula(name, path) + Formulary.load_formula_from_path(name, path) end end |
