Sha256: 52a890ad980f4b972f11c7c2f92c7d6b302996ee313bdd5091c17c54ae85a2d3
Contents?: true
Size: 1.02 KB
Versions: 40
Compression:
Stored size: 1.02 KB
Contents
module HaveAPI::Client module Validators ; end class Validator class << self def name(v) Validator.register(v, self) end def register(name, klass) @validators ||= {} @validators[name] = klass end def validate(validators, param, other_params) ret = [] validators.each do |name, desc| fail "unsupported validator '#{name}'" if @validators[name].nil? v = @validators[name].new(desc, param, other_params) ret.concat(v.errors) unless v.valid? end ret.empty? ? true : ret end end attr_reader :value, :params def initialize(opts, value, other_params) @opts = opts @value = value @params = other_params.params end def errors @errors || [opts[:message] % { value: value }] end def valid? raise NotImplementedError end protected def opts @opts end def error(e) @errors ||= [] @errors << e end end end
Version data entries
40 entries across 40 versions & 1 rubygems