Class: Yes::Command::Api::Commands::ParamsValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/yes/command/api/commands/params_validator.rb

Overview

Validates the structure of command parameter hashes before deserialization. Ensures each command hash contains the required keys.

Constant Summary collapse

CommandParamsInvalid =
Class.new(Yes::Core::Error)
REQUIRED_KEYS =
%i[command data context subject].freeze

Class Method Summary collapse

Class Method Details

.call(params) ⇒ void

This method returns an undefined value.

Validates command params.

Parameters:

  • params (Array<Hash>)

    Array of command params

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/yes/command/api/commands/params_validator.rb', line 20

def call(params)
  invalid = []
  raise CommandParamsInvalid, 'Commands must be an array' unless params.is_a? Array

  params.each do |command|
    missing_keys = missing_keys?(command)
    next unless missing_keys.any?

    invalid << {
      command:,
      error: missing_keys_message(missing_keys)
    }
  end

  raise CommandParamsInvalid.new(required_keys_message, extra: invalid) if invalid.any?
end