Sha256: fda525e228e79b8730e3eac215e577a63425c6129efb50ff93917a8c7365afd9
Contents?: true
Size: 792 Bytes
Versions: 2
Compression:
Stored size: 792 Bytes
Contents
module NxtSchema module Validators class Query < Validator def initialize(method) @method = method end register_as :query attr_reader :method # Query a boolean method on you value => application(:test, :String).validate(:query, :good_enough?) # => Would be valid if value.good_enough? is truthy def build lambda do |application, value| raise ArgumentError, "#{value} does not respond to query: #{method}" unless value.respond_to?(method) if value.send(method) true else message = translate_error(application.locale, value: value, actual: value.send(method), query: method) application.add_error(message) end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nxt_schema-1.0.1 | lib/nxt_schema/validators/query.rb |
nxt_schema-1.0.0 | lib/nxt_schema/validators/query.rb |