Class: ExternalPatch

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
brew/Library/Homebrew/patch.rb

Direct Known Subclasses

LegacyPatch

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strip, &block) ⇒ ExternalPatch

Returns a new instance of ExternalPatch



123
124
125
126
# File 'brew/Library/Homebrew/patch.rb', line 123

def initialize(strip, &block)
  @strip    = strip
  @resource = Resource::PatchResource.new(&block)
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource



117
118
119
# File 'brew/Library/Homebrew/patch.rb', line 117

def resource
  @resource
end

#stripObject (readonly)

Returns the value of attribute strip



117
118
119
# File 'brew/Library/Homebrew/patch.rb', line 117

def strip
  @strip
end

Instance Method Details

#applyObject



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'brew/Library/Homebrew/patch.rb', line 137

def apply
  dir = Pathname.pwd
  resource.unpack do
    patch_dir = Pathname.pwd
    if patch_files.empty?
      children = patch_dir.children
      if children.length != 1 || !children.first.file?
        raise MissingApplyError, <<~EOS
          There should be exactly one patch file in the staging directory unless
          the "apply" method was used one or more times in the patch-do block.
        EOS
      end

      patch_files << children.first.basename
    end
    dir.cd do
      patch_files.each do |patch_file|
        ohai "Applying #{patch_file}"
        patch_file = patch_dir/patch_file
        safe_system "patch", "-g", "0", "-f", "-#{strip}", "-i", patch_file
      end
    end
  end
end

#external?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'brew/Library/Homebrew/patch.rb', line 128

def external?
  true
end

#inspectObject



162
163
164
# File 'brew/Library/Homebrew/patch.rb', line 162

def inspect
  "#<#{self.class.name}: #{strip.inspect} #{url.inspect}>"
end

#owner=(owner) ⇒ Object



132
133
134
135
# File 'brew/Library/Homebrew/patch.rb', line 132

def owner=(owner)
  resource.owner   = owner
  resource.version = resource.checksum || ERB::Util.url_encode(resource.url)
end