Sha256: 7b725861ec06c13141a9acdba2c631c09013202a39c0c21531bd86943081ece1

Contents?: true

Size: 589 Bytes

Versions: 17

Compression:

Stored size: 589 Bytes

Contents

require_relative '../exceptions'

module Attributor
  class Regexp
    include Type

    def self.native_type
      ::Regexp
    end

    def self.load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options)
      unless value.is_a?(::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

17 entries across 17 versions & 1 rubygems

Version Path
attributor-8.0 lib/attributor/types/regexp.rb
attributor-7.1 lib/attributor/types/regexp.rb
attributor-7.0 lib/attributor/types/regexp.rb
attributor-6.5 lib/attributor/types/regexp.rb
attributor-6.4 lib/attributor/types/regexp.rb
attributor-6.3 lib/attributor/types/regexp.rb
attributor-6.2 lib/attributor/types/regexp.rb
attributor-6.1 lib/attributor/types/regexp.rb
attributor-6.0 lib/attributor/types/regexp.rb
attributor-5.7 lib/attributor/types/regexp.rb
attributor-5.6 lib/attributor/types/regexp.rb
attributor-5.5 lib/attributor/types/regexp.rb
attributor-5.4 lib/attributor/types/regexp.rb
attributor-5.3 lib/attributor/types/regexp.rb
attributor-5.2.1 lib/attributor/types/regexp.rb
attributor-5.2.0 lib/attributor/types/regexp.rb
attributor-5.1.0 lib/attributor/types/regexp.rb