Class: Kustomize::Transform::Json6902PatchTransform
- Inherits:
-
Kustomize::Transform
- Object
- Kustomize::Transform
- Kustomize::Transform::Json6902PatchTransform
- Defined in:
- lib/kustomize/transform/json_6902_patch_transform.rb
Instance Attribute Summary collapse
-
#patches ⇒ Object
readonly
Returns the value of attribute patches.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(target:, patches:) ⇒ Json6902PatchTransform
constructor
A new instance of Json6902PatchTransform.
- #rewrite(resource_doc) ⇒ Object
Methods inherited from Kustomize::Transform
Constructor Details
#initialize(target:, patches:) ⇒ Json6902PatchTransform
Returns a new instance of Json6902PatchTransform.
40 41 42 43 |
# File 'lib/kustomize/transform/json_6902_patch_transform.rb', line 40 def initialize(target:, patches:) @target = target @patches = patches end |
Instance Attribute Details
#patches ⇒ Object (readonly)
Returns the value of attribute patches.
46 47 48 |
# File 'lib/kustomize/transform/json_6902_patch_transform.rb', line 46 def patches @patches end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
45 46 47 |
# File 'lib/kustomize/transform/json_6902_patch_transform.rb', line 45 def target @target end |
Class Method Details
.create(kustomization_file, op_spec) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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 |
Instance Method Details
#rewrite(resource_doc) ⇒ Object
48 49 50 51 52 53 54 |
# 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 |