Class: Yes::Command::Api::Commands::ParamsValidator
- Inherits:
-
Object
- Object
- Yes::Command::Api::Commands::ParamsValidator
- 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
-
.call(params) ⇒ void
Validates command params.
Class Method Details
.call(params) ⇒ void
This method returns an undefined value.
Validates command params.
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) } end raise CommandParamsInvalid.new(, extra: invalid) if invalid.any? end |