Module: Patch Private

Defined in:
patch.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Helper module for creating patches.

Class Method Summary collapse

Class Method Details

.create(strip, src, &block) ⇒ EmbeddedPatch, ExternalPatch

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'patch.rb', line 19

def self.create(strip, src, &block)
  case strip
  when :DATA
    DATAPatch.new(:p1)
  when String
    StringPatch.new(:p1, strip)
  when Symbol
    case src
    when :DATA
      DATAPatch.new(strip)
    when String
      StringPatch.new(strip, src)
    else
      external_patch = ExternalPatch.new(strip, &block)
      resource = external_patch.resource
      if (file = resource.file)
        raise ArgumentError, "Patch cannot have both `file` and `url`." if resource.url.present?
        raise ArgumentError, "Patch cannot use `sha256` with `file`." if resource.checksum
        raise ArgumentError, "Patch cannot use `directory` with `file`." if resource.directory.present?
        raise ArgumentError, "Patch cannot use `apply` with `file`." if resource.patch_files.present?

        LocalPatch.new(strip, file)
      else
        external_patch
      end
    end
  end
end