Sha256: e6465174bd1ea6e74bd6f1f28a96257d5e9da4bc3cf8140a3627648d53169c28
Contents?: true
Size: 1.04 KB
Versions: 5
Compression:
Stored size: 1.04 KB
Contents
require 'grape/validations' module Grape module Validators class Json < Grape::Validations::Base def validate_param!(field, params) begin JSON.parse( params[field] ) rescue StandardError raise Grape::Exceptions::Validation, params: [@scope.full_name(field)], message: 'must be valid JSON!' end end end class JsonArray < Grape::Validations::Base def validate_param!(field, params) begin raise unless JSON.parse( params[field] ).is_a? Array rescue StandardError raise Grape::Exceptions::Validation, params: [@scope.full_name(field)], message: 'must be a valid JSON array!' end end end class JsonHash < Grape::Validations::Base def validate_param!(field, params) begin raise unless JSON.parse( params[field] ).is_a? Hash rescue StandardError raise Grape::Exceptions::Validation, params: [@scope.full_name(field)], message: 'must be a valid JSON hash!' end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems