class Kustomize::Transform::Json6902PatchTransform

Attributes

patches[R]
target[R]

Public Class Methods

create(kustomization_file, op_spec) click to toggle source
# File lib/kustomize/transform/json_6902_patch_transform.rb, line 13
def self.create(kustomization_file, op_spec)
  target = Kustomize::TargetSpec.create(op_spec['target'])

  patch_part =
    if op_spec['path']
      path = kustomization_file.source_directory / op_spec['path']
      YAML.load(file.read)
    elsif op_spec['patch']
      YAML.load(op_spec['patch'])
    elsif op_spec['ops']
      op_spec['ops']
    else
      []
    end

  patches = patch_part.map do |patch|
    Kustomize::Json6902Patch
    .const_get(patch['op'].capitalize + 'Op')
    .create(patch)
  end

  self.new(
    target: target,
    patches: patches
  )
end
new(target:, patches:) click to toggle source
# File lib/kustomize/transform/json_6902_patch_transform.rb, line 40
def initialize(target:, patches:)
  @target = target
  @patches = patches
end

Public Instance Methods

rewrite(resource_doc) click to toggle source
# File lib/kustomize/transform/json_6902_patch_transform.rb, line 48
def rewrite(resource_doc)
  if @target.match?(resource_doc)
    @patches.inject(resource_doc){ |doc, patch| patch.apply(doc) }
  else
    resource_doc
  end
end