Sha256: 1c98e8710f481a54e26c0506fab5c4db5dd1f8e17d0e8b5bc1c72c6609298b44

Contents?: true

Size: 660 Bytes

Versions: 3

Compression:

Stored size: 660 Bytes

Contents

module NxtSchema
  module Validators
    class OptionalNode < Validator
      def initialize(conditional, missing_key)
        @conditional = conditional
        @missing_key = missing_key
      end

      register_as :optional_node
      attr_reader :conditional, :missing_key

      def build
        lambda do |node, value|
          args = [node, value]

          if conditional.call(*args.take(conditional.arity))
            true
          else
            message = ErrorMessages.resolve(node.locale, :required_key_missing, key: missing_key, target: node.value)
            node.add_error(message)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nxt_schema-0.1.2 lib/nxt_schema/validators/optional_node.rb
nxt_schema-0.1.1 lib/nxt_schema/validators/optional_node.rb
nxt_schema-0.1.0 lib/nxt_schema/validators/optional_node.rb