Class: Attributor::String
- Inherits:
-
Object
- Object
- Attributor::String
- Includes:
- Type
- Defined in:
- lib/attributor/types/string.rb
Class Method Summary collapse
- .example(context = nil, options: {}) ⇒ 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
19 20 21 22 23 24 25 |
# File 'lib/attributor/types/string.rb', line 19 def self.example(context=nil, options:{}) if [:regexp] return [:regexp].gen else return /\w+/.gen end end |
.load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/attributor/types/string.rb', line 9 def self.load(value,context=Attributor::DEFAULT_ROOT_CONTEXT, **) if value.kind_of?(Enumerable) raise IncompatibleTypeError, context: context, value_type: value.class, type: self end value && String(value) rescue super end |
.native_type ⇒ Object
5 6 7 |
# File 'lib/attributor/types/string.rb', line 5 def self.native_type return ::String end |