Class: ExternalPatch

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
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



120
121
122
123
# File 'Library/Homebrew/patch.rb', line 120

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

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource



114
115
116
# File 'Library/Homebrew/patch.rb', line 114

def resource
  @resource
end

#stripObject (readonly)

Returns the value of attribute strip



114
115
116
# File 'Library/Homebrew/patch.rb', line 114

def strip
  @strip
end

Instance Method Details

#applyObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'Library/Homebrew/patch.rb', line 134

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)


125
126
127
# File 'Library/Homebrew/patch.rb', line 125

def external?
  true
end

#inspectObject



158
159
160
# File 'Library/Homebrew/patch.rb', line 158

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

#owner=(owner) ⇒ Object



129
130
131
132
# File 'Library/Homebrew/patch.rb', line 129

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