Class: NxtSchema::Validators::Query
- Defined in:
- lib/nxt_schema/validators/query.rb
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
-
#build ⇒ Object
Query a boolean method on you value => node(:test, :String).validate(:query, :good_enough?) => Would be valid if value.good_enough? is truthy.
-
#initialize(method) ⇒ Query
constructor
A new instance of Query.
Methods inherited from Validator
Constructor Details
#initialize(method) ⇒ Query
Returns a new instance of Query.
4 5 6 |
# File 'lib/nxt_schema/validators/query.rb', line 4 def initialize(method) @method = method end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
9 10 11 |
# File 'lib/nxt_schema/validators/query.rb', line 9 def method @method end |
Instance Method Details
#build ⇒ Object
Query a boolean method on you value => node(:test, :String).validate(:query, :good_enough?)
> Would be valid if value.good_enough? is truthy
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/nxt_schema/validators/query.rb', line 14 def build lambda do |node, value| raise ArgumentError, "#{value} does not respond to query: #{method}" unless value.respond_to?(method) if value.send(method) true else = translate_error(node.locale, value: value, actual: value.send(method), query: method) node.add_error() end end end |