Class: RSchema::Schemas::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/rschema/schemas/set.rb

Overview

A schema that matches Set objects (from the Ruby standard library)

Examples:

A set of integers

require 'set'
schema = RSchema.define { set(_Integer) }
schema.valid?(Set[1, 2, 3]) #=> true
schema.valid?(Set[:a, :b, :c]) #=> false

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subschema) ⇒ Set


19
20
21
# File 'lib/rschema/schemas/set.rb', line 19

def initialize(subschema)
  @subschema = subschema
end

Instance Attribute Details

#subschemaObject (readonly)

Returns the value of attribute subschema


17
18
19
# File 'lib/rschema/schemas/set.rb', line 17

def subschema
  @subschema
end

Instance Method Details

#call(value, options) ⇒ Object


23
24
25
26
27
# File 'lib/rschema/schemas/set.rb', line 23

def call(value, options)
  return not_a_set_result(value) unless value.is_a?(::Set)

  accumulate_elements(value, options).to_result
end

#with_wrapped_subschemas(wrapper) ⇒ Object


29
30
31
32
# File 'lib/rschema/schemas/set.rb', line 29

def with_wrapped_subschemas(wrapper)
  wrapped_subschema = wrapper.wrap(subschema)
  self.class.new(wrapped_subschema)
end