Class: RSchema::Schemas::Enum
- Inherits:
-
Object
- Object
- RSchema::Schemas::Enum
- Defined in:
- lib/rschema/schemas/enum.rb
Overview
A schema that matches a values in a given set.
Instance Attribute Summary collapse
-
#members ⇒ Object
readonly
Returns the value of attribute members.
-
#subschema ⇒ Object
readonly
Returns the value of attribute subschema.
Instance Method Summary collapse
- #call(value, options) ⇒ Object
-
#initialize(members, subschema) ⇒ Enum
constructor
A new instance of Enum.
- #with_wrapped_subschemas(wrapper) ⇒ Object
Constructor Details
#initialize(members, subschema) ⇒ Enum
Returns a new instance of Enum.
17 18 19 20 |
# File 'lib/rschema/schemas/enum.rb', line 17 def initialize(members, subschema) @members = members @subschema = subschema end |
Instance Attribute Details
#members ⇒ Object (readonly)
Returns the value of attribute members.
15 16 17 |
# File 'lib/rschema/schemas/enum.rb', line 15 def members @members end |
#subschema ⇒ Object (readonly)
Returns the value of attribute subschema.
15 16 17 |
# File 'lib/rschema/schemas/enum.rb', line 15 def subschema @subschema end |
Instance Method Details
#call(value, options) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rschema/schemas/enum.rb', line 22 def call(value, ) subresult = subschema.call(value, ) if subresult.invalid? subresult elsif members.include?(subresult.value) subresult else Result.failure(error(subresult.value)) end end |
#with_wrapped_subschemas(wrapper) ⇒ Object
33 34 35 |
# File 'lib/rschema/schemas/enum.rb', line 33 def with_wrapped_subschemas(wrapper) self.class.new(members, wrapper.wrap(subschema)) end |