aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/formulary.rb18
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