Class: Attributor::Regexp
- Inherits:
-
Object
- Object
- Attributor::Regexp
- Includes:
- Type
- Defined in:
- lib/attributor/types/regexp.rb
Class Method Summary collapse
- .example(_context = nil, options: {}) ⇒ Object
- .family ⇒ Object
- .load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options) ⇒ Object
- .native_type ⇒ Object
Methods included from Type
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 |
.family ⇒ Object
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, **) 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 |