Class: TSJSON::ScalarUnion
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
-
#initialize(types = []) ⇒ ScalarUnion
constructor
A new instance of ScalarUnion.
- #validate(value) ⇒ Object
Methods inherited from Base
#compile, #index, #property, #valid?
Constructor Details
#initialize(types = []) ⇒ ScalarUnion
Returns a new instance of ScalarUnion.
5 6 7 8 9 10 11 12 13 |
# File 'lib/types/scalar_union.rb', line 5 def initialize(types = []) types.each do |t| unless t.is_a?(ScalarType) raise 'ScalarUnion may contain only Scalar types' end end @types = types end |
Instance Attribute Details
#types ⇒ Object (readonly)
Returns the value of attribute types.
3 4 5 |
# File 'lib/types/scalar_union.rb', line 3 def types @types end |
Instance Method Details
#validate(value) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/types/scalar_union.rb', line 15 def validate(value) @types.each { |type| return true if type.valid?(value) } raise ScalarUnionValidationError.new( expected_types: @types.map(&:name), received_type: value.class.name, received_value: value ) end |