Class: IS::Deep::ArrayStrategies::KeyBased
- Inherits:
-
Object
- Object
- IS::Deep::ArrayStrategies::KeyBased
- Defined in:
- lib/is-deep/strategies.rb
Overview
Key-based merge strategy for arrays of hashes.
Matches elements by specified or auto-detected key, then deep merges matching elements. Unmatched elements are appended.
Constant Summary collapse
- DEFAULT_KEY_CANDIDATES =
[:id, :name, :key, :env, :host].freeze
Instance Method Summary collapse
-
#call(base, other) ⇒ Array
Execute merge strategy.
-
#initialize(key = nil) ⇒ KeyBased
constructor
Initialize with optional explicit key.
Constructor Details
#initialize(key = nil) ⇒ KeyBased
Initialize with optional explicit key.
59 60 61 |
# File 'lib/is-deep/strategies.rb', line 59 def initialize key = nil @key = key end |
Instance Method Details
#call(base, other) ⇒ Array
Note:
Falls back to CONCAT behavior if key cannot be determined
Execute merge strategy.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/is-deep/strategies.rb', line 69 def call base, other effective_key = @key || detect_key(base) unless effective_key # Fallback к concat если не можем определить ключ return base + other end indexed = index_by_key(base, effective_key) merge_indexed base.dup, other, indexed, effective_key end |