aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/formula.rb
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/formula.rb')
-rw-r--r--Library/Homebrew/formula.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 15561b100..0ccf9292c 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -1,3 +1,4 @@
+require 'resource'
require 'download_strategy'
require 'dependency_collector'
require 'formula_support'
@@ -56,6 +57,11 @@ class Formula
end
@pin = FormulaPin.new(self)
+
+ @resources = self.class.resources
+ @resources.each_value do |r|
+ r.set_owner name
+ end
end
def set_spec(name)
@@ -91,6 +97,16 @@ class Formula
def version; active_spec.version; end
def mirrors; active_spec.mirrors; end
+ def resource(name)
+ res = @resources[name]
+ raise ResourceMissingError.new(@name, name) if res.nil?
+ res
+ end
+
+ def resources
+ @resources.values
+ end
+
# if the dir is there, but it's empty we consider it not installed
def installed?
(dir = installed_prefix).directory? && dir.children.length > 0
@@ -694,6 +710,19 @@ class Formula
@stable.mirror(val)
end
+ # Hold any resources defined by this formula
+ def resources
+ @resources ||= Hash.new
+ end
+
+ # Define a named resource using a SoftwareSpec style block
+ def resource res_name, &block
+ raise DuplicateResourceError.new(res_name) if resources.has_key?(res_name)
+ spec = SoftwareSpec.new
+ spec.instance_eval(&block)
+ resources[res_name] = Resource.new(res_name, spec)
+ end
+
def dependencies
@dependencies ||= DependencyCollector.new
end