lib/crossbeams_responses.rb
# Create a response object with validation errors.
# Returns:
#   - success: false.
#   - instance: a Hash of the object that failed validation.
#   - errors: the error messages.
#   - message: "Validation error".
#
# validation results must either be a Dry::Validation::Result or a Hash or OpenStruct.
# The Hash should have attributes for the object in error and a key `:messages`.
# `:messages` must be in the same format as Dry::Validation::Result.messages.
# i.e `messages: { field1: ['error', 'another error'], field2: ['an err'] }`
#
# @param validation_results [Hash, Dry::Validation::Result, OpenStruct] the validation object and messages.
# @return [OpenStruct] the response object.
Create a response object with validation errors.
Returns:
success: false.
instance: a Hash of the object that failed validation.
errors: the error messages.
message: "Validation error".

validation results must either be a Dry::Validation::Result or a Hash or OpenStruct.
The Hash should have attributes for the object in error and a key `:messages`.
Create a response object with validation errors . Returns : success : false . instance : a Hash of the object that failed validation . errors : the error messages . message : " Validation error " . validation results must either be a Dry :: Validation :: Result or a Hash or OpenStruct . The Hash should have attributes for the object in error and a key ` : messages ` .
def validation_failed_response(validation_results)
      from_dry = validation_results.respond_to?(:failure?)
      OpenStruct.new(success: false,
                     validation: true,
                     instance: from_dry ? validation_results.to_h : validation_results.to_h.reject { |k, _| k == :messages },
                     errors: from_dry ? validation_results.errors.to_h : validation_results[:messages],
                     message: 'Validation error')
    end
def validation_failed_response ( validation_results ) from_dry = validation_results . respond_to? ( :failure? ) OpenStruct . new ( success : false , validation : true , instance : from_dry ? validation_results . to_h : validation_results . to_h . reject { | k , _ | k == :messages } , errors : from_dry ? validation_results . errors . to_h : validation_results [ :messages ] , message : 'Validation error' ) end
Create a response object with validation errors.
Create a response object with validation errors .
# Dry::Schema::Result / Dry::Validation::Result # instance: validation_results.is_a?(Dry::Validation::Result) ? validation_results.to_h : validation_results.to_h.reject { |k, _| k == :messages }, # errors: validation_results.is_a?(Hash) ? validation_results[:messages] : validation_results.messages,
the response object.
the response object .
OpenStruct
validation_results
the validation object and messages.
the validation object and messages .