Sha256: 9a0467ccfa8c1a65540a8392963c8c200ea654f550ddec929581d62b81d86321
Contents?: true
Size: 1019 Bytes
Versions: 6
Compression:
Stored size: 1019 Bytes
Contents
module Judge class Validation def initialize(params) @klass = params[:klass] @attribute = params[:attribute] @value = params[:value] @kind = params[:kind] validate! end def amv @amv ||= begin validators = @klass.validators_on(@attribute) validators.keep_if { |amv| amv.kind == @kind } validators.first end end def record @record ||= begin rec = @klass.new rec[@attribute] = @value rec end end def validate! record.errors.delete(@attribute) amv.validate_each(record, @attribute, @value) self end def as_json(options = {}) record.errors.get(@attribute) || [] end end class NullValidation def initialize(params) @params = params end def as_json(options = {}) ["Judge validation for #{@params[:klass]}##{@params[:attribute]} not allowed"] end def method_missing(*args) self end end end
Version data entries
6 entries across 6 versions & 1 rubygems