diff options
| author | Adam Vandenberg | 2013-08-06 19:52:58 -0700 |
|---|---|---|
| committer | Adam Vandenberg | 2013-09-11 22:05:26 -0700 |
| commit | d4cf3ef2128105097ee200de9f98c42a022d66da (patch) | |
| tree | c1431e671e46cf7def1848daf280cf3f818f77f3 /Library/Homebrew/formula.rb | |
| parent | cf751fd0133113d59c2ed57b7797c7e9bd2fdd67 (diff) | |
| download | brew-d4cf3ef2128105097ee200de9f98c42a022d66da.tar.bz2 | |
Implement Resources
Closes Homebrew/homebrew#20212.
Diffstat (limited to 'Library/Homebrew/formula.rb')
| -rw-r--r-- | Library/Homebrew/formula.rb | 29 |
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 |
