Class: RSchema::Schemas::Set
- Inherits:
-
Object
- Object
- RSchema::Schemas::Set
- Defined in:
- lib/rschema/schemas/set.rb
Overview
A schema that matches ‘Set` objects (from the Ruby standard library)
Instance Attribute Summary collapse
-
#subschema ⇒ Object
readonly
Returns the value of attribute subschema.
Instance Method Summary collapse
- #call(value, options) ⇒ Object
-
#initialize(subschema) ⇒ Set
constructor
A new instance of Set.
- #with_wrapped_subschemas(wrapper) ⇒ Object
Constructor Details
#initialize(subschema) ⇒ Set
Returns a new instance of Set.
18 19 20 |
# File 'lib/rschema/schemas/set.rb', line 18 def initialize(subschema) @subschema = subschema end |
Instance Attribute Details
#subschema ⇒ Object (readonly)
Returns the value of attribute subschema.
16 17 18 |
# File 'lib/rschema/schemas/set.rb', line 16 def subschema @subschema end |
Instance Method Details
#call(value, options) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rschema/schemas/set.rb', line 22 def call(value, ) return not_a_set_result(value) unless value.is_a?(::Set) result_value = ::Set.new result_errors = {} value.each do |subvalue| subresult = subschema.call(subvalue, ) if subresult.valid? result_value << subresult.value else result_errors[subvalue] = subresult.error end break if .fail_fast? end if result_errors.empty? Result.success(result_value) else Result.failure(result_errors) end end |
#with_wrapped_subschemas(wrapper) ⇒ Object
46 47 48 49 |
# File 'lib/rschema/schemas/set.rb', line 46 def with_wrapped_subschemas(wrapper) wrapped_subschema = wrapper.wrap(subschema) self.class.new(wrapped_subschema) end |