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/resource.rb | |
| parent | cf751fd0133113d59c2ed57b7797c7e9bd2fdd67 (diff) | |
| download | brew-d4cf3ef2128105097ee200de9f98c42a022d66da.tar.bz2 | |
Implement Resources
Closes Homebrew/homebrew#20212.
Diffstat (limited to 'Library/Homebrew/resource.rb')
| -rw-r--r-- | Library/Homebrew/resource.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Library/Homebrew/resource.rb b/Library/Homebrew/resource.rb new file mode 100644 index 000000000..1136af1c0 --- /dev/null +++ b/Library/Homebrew/resource.rb @@ -0,0 +1,57 @@ +# A Resource describes a tarball that a formula needs in addition +# to the formula's own download. +class Resource + include FileUtils + + # The mktmp mixin expects a name property + # This is the resource name + attr_reader :name + + # This is the associated formula name + attr_reader :owner_name + + def initialize name, spec + @name = name + @spec = spec + end + + # Formula name must be set after the DSL, as we have no access to the + # formula name before initialization of the formula + def set_owner owner + @owner = owner + @downloader = @spec.download_strategy.new("#{owner}--#{name}", @spec) + end + + # Download the resource + # If a target is given, unpack there; else unpack to a temp folder + # If block is given, yield to that block + # A target or a block must be given, but not both + def stage(target=nil) + fetched = fetch + verify_download_integrity(fetched) if fetched.file? + mktemp do + @downloader.stage + if block_given? + yield self + else + target.install Dir['*'] + end + end + end + + def cached_download + @downloader.cached_location + end + + # For brew-fetch and others. + def fetch + # Ensure the cache exists + HOMEBREW_CACHE.mkpath + @downloader.fetch + cached_download + end + + def verify_download_integrity fn + @spec.verify_download_integrity(fn) + end +end |
