Class: Vanagon::Patch

Inherits:
Object
  • Object
show all
Includes:
HashableAttributes
Defined in:
lib/vanagon/patch.rb,
lib/vanagon/extensions/hashable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashableAttributes

#to_hash, #to_json

Constructor Details

#initialize(origin_path, component, options) ⇒ Patch

rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vanagon/patch.rb', line 34

def initialize(origin_path, component, options) # rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity
  valid_keys = %i[namespace destination strip fuzz after]
  bad_keys = options.each_key.reject { |k| valid_keys.include? k }

  unless bad_keys.empty?
    raise Vanagon::Error, "Bad options in patch initialization: #{bad_keys}."
  end

  @origin_path = origin_path
  @namespace = options[:namespace] || component.name
  @assembly_path = "patches/#{@namespace}/#{File.basename(@origin_path)}"
  @strip = options[:strip] || 1
  @fuzz = options[:fuzz] || 0
  @after = options[:after] || 'unpack'
  unless ['unpack', 'install'].include?(@after)
    raise Vanagon::Error, 'Only "unpack" or "install" permitted for "after" option.'
  end
  @destination = options[:destination] || component.dirname
end

Instance Attribute Details

#afterObject (readonly)

Returns the value of attribute after.



32
33
34
# File 'lib/vanagon/patch.rb', line 32

def after
  @after
end

#assembly_pathObject (readonly)

Returns the value of attribute assembly_path.



15
16
17
# File 'lib/vanagon/patch.rb', line 15

def assembly_path
  @assembly_path
end

#destinationObject (readonly)

Returns the value of attribute destination.



20
21
22
# File 'lib/vanagon/patch.rb', line 20

def destination
  @destination
end

#fuzzObject (readonly)

Returns the value of attribute fuzz.



28
29
30
# File 'lib/vanagon/patch.rb', line 28

def fuzz
  @fuzz
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



11
12
13
# File 'lib/vanagon/patch.rb', line 11

def namespace
  @namespace
end

#origin_pathObject (readonly)

Returns the value of attribute origin_path.



7
8
9
# File 'lib/vanagon/patch.rb', line 7

def origin_path
  @origin_path
end

#stripObject (readonly)

Returns the value of attribute strip.



24
25
26
# File 'lib/vanagon/patch.rb', line 24

def strip
  @strip
end

Instance Method Details

#cmd(platform) ⇒ Object



54
55
56
# File 'lib/vanagon/patch.rb', line 54

def cmd(platform)
  return "#{platform.patch} --strip=#{@strip} --fuzz=#{@fuzz} --ignore-whitespace --no-backup-if-mismatch < $(workdir)/#{@assembly_path}"
end