Module: Yes::Core::Commands::GroupPayloadNormalizer
- Defined in:
- lib/yes/core/commands/group_payload_normalizer.rb
Overview
Normalizes a flat or partially-nested input hash into the per-context / per-subject shape expected by a command group’s sub-commands.
Supports three input forms simultaneously:
* keys that match a command context are passed through verbatim,
* keys that match a subject of the own context are nested one level
under the own context,
* any other key is nested two levels under
<own_context>.<own_subject>.
This is the shared payload-shaping primitive for Group (legacy stateless flow) and CommandGroup (aggregate-DSL flow).
Class Method Summary collapse
-
.call(params, command_contexts:, own_context_subjects:, own_context:, own_subject:) ⇒ Hash
The normalized payload (reserved keys stripped).
Class Method Details
.call(params, command_contexts:, own_context_subjects:, own_context:, own_subject:) ⇒ Hash
Returns the normalized payload (reserved keys stripped).
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/yes/core/commands/group_payload_normalizer.rb', line 28 def self.call(params, command_contexts:, own_context_subjects:, own_context:, own_subject:) params.without(*Yes::Core::Command::RESERVED_KEYS).each_with_object({}) do |(key, value), out| if command_contexts.include?(key) out[key] = value elsif own_context_subjects.include?(key) out[own_context] ||= {} out[own_context][key] = value else out[own_context] ||= {} out[own_context][own_subject] ||= {} out[own_context][own_subject][key] = value end end end |