diff options
| author | Andrew Janke | 2016-04-22 16:54:09 -0400 |
|---|---|---|
| committer | Andrew Janke | 2016-04-22 21:49:00 -0400 |
| commit | 258a764f678b0d0d1c5bc0dee4a31d6ad79a8471 (patch) | |
| tree | 0af196427f927865bcc586dcbce8ae70929b7b4c | |
| parent | 2921795668970f9b5598037fc55940d29ba941d6 (diff) | |
| download | brew-258a764f678b0d0d1c5bc0dee4a31d6ad79a8471.tar.bz2 | |
stage: fix block signature back-compatibility under Ruby 1.8.7
The new stage() signature introduced by #66 breaks back-compatibility
under Ruby 1.8.7. This fixes it by switching back to a one-argument
block signature and using a new class to wrap both the Resource and
Mktemp info for the staging context, in a signature-back-compatible
way.
Addresses homebrew/homebrew-core#529.
Closes #135.
Signed-off-by: Andrew Janke <andrew@apjanke.net>
| -rw-r--r-- | Library/Homebrew/extend/fileutils.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/formula.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/resource.rb | 31 |
3 files changed, 30 insertions, 5 deletions
diff --git a/Library/Homebrew/extend/fileutils.rb b/Library/Homebrew/extend/fileutils.rb index af17d4eff..188b0ccbf 100644 --- a/Library/Homebrew/extend/fileutils.rb +++ b/Library/Homebrew/extend/fileutils.rb @@ -179,7 +179,7 @@ end unless File.respond_to?(:write) class File def self.write(filename, contents) - File.open(filename, 'w') do |file| + File.open(filename, "w") do |file| file.write contents end end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 4f5c56634..a6bc2cbe0 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1548,7 +1548,7 @@ class Formula end def stage - active_spec.stage do |_resource, staging| + active_spec.stage do |staging| @source_modified_time = active_spec.source_modified_time @buildpath = Pathname.pwd env_home = buildpath/".brew_home" diff --git a/Library/Homebrew/resource.rb b/Library/Homebrew/resource.rb index 5077ac149..3fcdf46bd 100644 --- a/Library/Homebrew/resource.rb +++ b/Library/Homebrew/resource.rb @@ -1,6 +1,7 @@ require "download_strategy" require "checksum" require "version" +require "forwardable" # Resource is the fundamental representation of an external resource. The # primary formula download, along with other declared resources, are instances @@ -86,15 +87,15 @@ class Resource end # If a target is given, unpack there; else unpack to a temp folder. - # If block is given, yield to that block with |self, staging|, where staging - # is a staging context that responds to retain!(). + # If block is given, yield to that block with |stage|, where stage + # is a ResourceStagingContext. # A target or a block must be given, but not both. def unpack(target = nil) mktemp(download_name) do |staging| downloader.stage @source_modified_time = downloader.source_modified_time if block_given? - yield self, staging + yield ResourceStageContext.new(self, staging) elsif target target = Pathname.new(target) unless target.is_a? Pathname target.install Dir["*"] @@ -186,3 +187,27 @@ class Resource end end end + +# The context in which a Resource.stage() occurs. Supports access to both +# the Resource and associated Mktemp in a single block argument. The interface +# is back-compatible with Resource itself as used in that context. +class ResourceStageContext + extend Forwardable + + # The Resource that is being staged + attr_reader :resource + # The Mktemp in which @resource is staged + attr_reader :staging + + def_delegators :@resource, :version, :url, :mirrors, :specs, :using, :source_modified_time + def_delegators :@staging, :retain! + + def initialize(resource, staging) + @resource = resource + @staging = staging + end + + def to_s + "<#{self.class}: resource=#{resource} staging=#{staging}>" + end +end |
