Class: NxtSchema::Validators::Equality
- Defined in:
- lib/nxt_schema/validators/equal_to.rb
Instance Attribute Summary collapse
-
#expectation ⇒ Object
readonly
Returns the value of attribute expectation.
Instance Method Summary collapse
-
#build ⇒ Object
Query for equality validator(:equality, 3) Query for equality validator(:eql, -> { 3 * 3 * 60 }).
-
#initialize(expectation) ⇒ Equality
constructor
A new instance of Equality.
Methods inherited from Validator
Constructor Details
#initialize(expectation) ⇒ Equality
Returns a new instance of Equality.
4 5 6 |
# File 'lib/nxt_schema/validators/equal_to.rb', line 4 def initialize(expectation) @expectation = expectation end |
Instance Attribute Details
#expectation ⇒ Object (readonly)
Returns the value of attribute expectation.
9 10 11 |
# File 'lib/nxt_schema/validators/equal_to.rb', line 9 def expectation @expectation end |
Instance Method Details
#build ⇒ Object
Query for equality validator(:equality, 3) Query for equality validator(:eql, -> { 3 * 3 * 60 })
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/nxt_schema/validators/equal_to.rb', line 14 def build lambda do |node, value| expected_value = Callable.new(expectation, nil, value).call if value == expected_value true else node.add_error( translate_error( node.locale, actual: value, expected: expected_value ) ) end end end |