Class: Attributor::Regexp
- Inherits:
-
Object
- Object
- Attributor::Regexp
show all
- Includes:
- Type
- Defined in:
- lib/attributor/types/regexp.rb
Class Method Summary
collapse
Methods included from Type
get_memoized_collection_class, set_memoized_collection_class
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
|
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.is_a?(::String) || value.nil?
raise IncompatibleTypeError, context: context, value_type: value.class, type: self
end
value && ::Regexp.new(value)
rescue
super
end
|
.native_type ⇒ Object
7
8
9
|
# File 'lib/attributor/types/regexp.rb', line 7
def self.native_type
::Regexp
end
|