Class: Ast::Merge::KeyPathPartialTemplateMergerBase
- Inherits:
-
Object
- Object
- Ast::Merge::KeyPathPartialTemplateMergerBase
- Defined in:
- lib/ast/merge/key_path_partial_template_merger_base.rb
Overview
Base class for merging a partial template into a specific key path of a structured destination document.
Unlike the navigable section-based PartialTemplateMergerBase, this base:
- Navigates a nested key path in a structured document
- Merges only the value located at that path
- Leaves the rest of the destination unchanged
Ownership boundary:
- this base owns the shared control flow for key-path navigation, missing-path insertion, and full-document wrapper construction
- concrete subclasses own parser-specific analysis, child traversal, serialization, and SmartMerger integration
Expected duck-type surface from analyses and entries:
- analysis responds to #valid?, #errors, and #statements
- entries respond to #key_name, #mapping?, #sequence?, and #scalar?
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#add_missing ⇒ Object
readonly
Returns the value of attribute add_missing.
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#key_path ⇒ Object
readonly
Returns the value of attribute key_path.
-
#preference ⇒ Object
readonly
Returns the value of attribute preference.
-
#recursive ⇒ Object
readonly
Returns the value of attribute recursive.
-
#remove_missing ⇒ Object
readonly
Returns the value of attribute remove_missing.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#when_missing ⇒ Object
readonly
Returns the value of attribute when_missing.
Instance Method Summary collapse
-
#initialize(template:, destination:, key_path:, preference: :destination, add_missing: true, remove_missing: false, when_missing: :skip, recursive: true) ⇒ KeyPathPartialTemplateMergerBase
constructor
A new instance of KeyPathPartialTemplateMergerBase.
-
#merge ⇒ Result
Merge template content into the configured key path.
Constructor Details
#initialize(template:, destination:, key_path:, preference: :destination, add_missing: true, remove_missing: false, when_missing: :skip, recursive: true) ⇒ KeyPathPartialTemplateMergerBase
Returns a new instance of KeyPathPartialTemplateMergerBase.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ast/merge/key_path_partial_template_merger_base.rb', line 43 def initialize( template:, destination:, key_path:, preference: :destination, add_missing: true, remove_missing: false, when_missing: :skip, recursive: true ) @template = template @destination = destination @key_path = Array(key_path) @preference = preference @add_missing = add_missing @remove_missing = remove_missing @when_missing = when_missing @recursive = recursive validate_key_path! end |
Instance Attribute Details
#add_missing ⇒ Object (readonly)
Returns the value of attribute add_missing.
40 41 42 |
# File 'lib/ast/merge/key_path_partial_template_merger_base.rb', line 40 def add_missing @add_missing end |
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
40 41 42 |
# File 'lib/ast/merge/key_path_partial_template_merger_base.rb', line 40 def destination @destination end |
#key_path ⇒ Object (readonly)
Returns the value of attribute key_path.
40 41 42 |
# File 'lib/ast/merge/key_path_partial_template_merger_base.rb', line 40 def key_path @key_path end |
#preference ⇒ Object (readonly)
Returns the value of attribute preference.
40 41 42 |
# File 'lib/ast/merge/key_path_partial_template_merger_base.rb', line 40 def preference @preference end |
#recursive ⇒ Object (readonly)
Returns the value of attribute recursive.
40 41 42 |
# File 'lib/ast/merge/key_path_partial_template_merger_base.rb', line 40 def recursive @recursive end |
#remove_missing ⇒ Object (readonly)
Returns the value of attribute remove_missing.
40 41 42 |
# File 'lib/ast/merge/key_path_partial_template_merger_base.rb', line 40 def remove_missing @remove_missing end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
40 41 42 |
# File 'lib/ast/merge/key_path_partial_template_merger_base.rb', line 40 def template @template end |
#when_missing ⇒ Object (readonly)
Returns the value of attribute when_missing.
40 41 42 |
# File 'lib/ast/merge/key_path_partial_template_merger_base.rb', line 40 def when_missing @when_missing end |
Instance Method Details
#merge ⇒ Result
Merge template content into the configured key path.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ast/merge/key_path_partial_template_merger_base.rb', line 68 def merge analysis = create_analysis(destination) unless analysis.valid? return Result.new( content: destination, has_key_path: false, changed: false, message: "Failed to parse destination: #{Array(analysis.errors).join(', ')}" ) end target_entry = find_key_path(analysis) return handle_missing_key_path if target_entry.nil? perform_merge_at_path(target_entry) end |