Class: NxtSchema::Validators::OptionalNode
- Defined in:
- lib/nxt_schema/validators/optional_node.rb
Instance Attribute Summary collapse
-
#conditional ⇒ Object
readonly
Returns the value of attribute conditional.
-
#missing_key ⇒ Object
readonly
Returns the value of attribute missing_key.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(conditional, missing_key) ⇒ OptionalNode
constructor
A new instance of OptionalNode.
Methods inherited from Validator
Constructor Details
#initialize(conditional, missing_key) ⇒ OptionalNode
Returns a new instance of OptionalNode.
4 5 6 7 |
# File 'lib/nxt_schema/validators/optional_node.rb', line 4 def initialize(conditional, missing_key) @conditional = conditional @missing_key = missing_key end |
Instance Attribute Details
#conditional ⇒ Object (readonly)
Returns the value of attribute conditional.
10 11 12 |
# File 'lib/nxt_schema/validators/optional_node.rb', line 10 def conditional @conditional end |
#missing_key ⇒ Object (readonly)
Returns the value of attribute missing_key.
10 11 12 |
# File 'lib/nxt_schema/validators/optional_node.rb', line 10 def missing_key @missing_key end |
Instance Method Details
#build ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nxt_schema/validators/optional_node.rb', line 12 def build lambda do |node, value| args = [node, value] return if conditional.call(*args.take(conditional.arity)) return if node.send(:keys).include?(missing_key.to_sym) = ErrorMessages.resolve( node.locale, :required_key_missing, key: missing_key, target: node.input ) node.add_error() end end |