Class: RSchema::Schemas::Type
- Inherits:
-
Object
- Object
- RSchema::Schemas::Type
- Defined in:
- lib/rschema/schemas/type.rb
Overview
A schema that matches values of a given type (i.e. ‘value.is_a?(type)`)
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #call(value, _options) ⇒ Object
-
#initialize(type) ⇒ Type
constructor
A new instance of Type.
- #with_wrapped_subschemas(_wrapper) ⇒ Object
Constructor Details
#initialize(type) ⇒ Type
Returns a new instance of Type.
24 25 26 |
# File 'lib/rschema/schemas/type.rb', line 24 def initialize(type) @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
22 23 24 |
# File 'lib/rschema/schemas/type.rb', line 22 def type @type end |
Instance Method Details
#call(value, _options) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/rschema/schemas/type.rb', line 28 def call(value, ) if value.is_a?(@type) Result.success(value) else Result.failure(error(value)) end end |
#with_wrapped_subschemas(_wrapper) ⇒ Object
36 37 38 |
# File 'lib/rschema/schemas/type.rb', line 36 def with_wrapped_subschemas(_wrapper) self end |