diff --git a/Library/Homebrew/extend/fileutils.rb b/Library/Homebrew/extend/fileutils.rb index af17d4effc..188b0ccbfa 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 4f5c56634a..a6bc2cbe0b 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 5077ac149c..3fcdf46bdb 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