Sha256: 5213fe91cb486a91a857bdb72ab15c9156a394a6042d32f6f5f64b37231c42fe

Contents?: true

Size: 594 Bytes

Versions: 6

Compression:

Stored size: 594 Bytes

Contents

require_relative '../exceptions'

module Attributor
  class Regexp
    include Type

    def self.native_type
      return ::Regexp
    end

    def self.load(value, context=Attributor::DEFAULT_ROOT_CONTEXT, **options)
      unless value.kind_of?(::String) || value.nil?
        raise IncompatibleTypeError,  context: context, value_type: value.class, type: self
      end

      value && ::Regexp.new(value)
    rescue
      super
    end

    def self.example(context=nil, options:{})
      ::Regexp.new(/^pattern\d{0,3}$/).to_s
    end

    def self.family
      'string'
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
attributor-5.0.2 lib/attributor/types/regexp.rb
attributor-5.0.1 lib/attributor/types/regexp.rb
attributor-5.0 lib/attributor/types/regexp.rb
attributor-4.2.0 lib/attributor/types/regexp.rb
attributor-4.1.0 lib/attributor/types/regexp.rb
attributor-4.0.1 lib/attributor/types/regexp.rb