Class: Attributor::Regexp

Inherits:
Object
  • Object
show all
Includes:
Type
Defined in:
lib/attributor/types/regexp.rb

Class Method Summary collapse

Methods included from Type

included

Class Method Details

.example(context = nil, options: {}) ⇒ Object


21
22
23
# File 'lib/attributor/types/regexp.rb', line 21

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

.familyObject


25
26
27
# File 'lib/attributor/types/regexp.rb', line 25

def self.family
  'string'
end

.load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options) ⇒ Object


11
12
13
14
15
16
17
18
19
# File 'lib/attributor/types/regexp.rb', line 11

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

.native_typeObject


7
8
9
# File 'lib/attributor/types/regexp.rb', line 7

def self.native_type
  return ::Regexp
end