class Sorta::Http::Web::ParamsValidator
Public Class Methods
build(&block)
click to toggle source
# File lib/sorta/http/web/params_validator.rb, line 9 def self.build(&block) obj = new obj.instance_exec(&block) obj end
new()
click to toggle source
# File lib/sorta/http/web/params_validator.rb, line 15 def initialize @rules = {} end
Public Instance Methods
call(params)
click to toggle source
# File lib/sorta/http/web/params_validator.rb, line 23 def call(params) errors = [] result = @rules.each_with_object({}) do |(key, klass), acc| acc[key] = Kernel.send(klass.name, params[key.to_s]) rescue => e errors << "#{e.message}" end raise ValidationError.new(errors.join("\n")) if errors.any? result end
param(name, type:)
click to toggle source
# File lib/sorta/http/web/params_validator.rb, line 19 def param(name, type:) @rules[name] = type end