Sha256: 26006781c4688fa5f028819a7f239b166f0113f61e737b368d5c16dbfb08595b

Contents?: true

Size: 504 Bytes

Versions: 4

Compression:

Stored size: 504 Bytes

Contents

module NxtSchema
  module Validators
    class Pattern < Validator
      def initialize(pattern)
        @pattern = pattern
      end

      register_as :pattern, :format
      attr_reader :pattern

      def build
        lambda do |node, value|
          if value.match(pattern)
            true
          else
            message = translate_error(node.locale, value: value, pattern: pattern)
            node.add_error(message)
            false
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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