Class: TSJSON::Union
Instance Attribute Summary
Attributes inherited from Merge
#is_normal, #types
Instance Method Summary
collapse
Methods inherited from Merge
#initialize
Methods inherited from Base
#index, #property, #valid?
Constructor Details
This class inherits a constructor from TSJSON::Merge
Instance Method Details
#compile ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/types/union.rb', line 47
def compile
return if @compiled
@compiled = true
return normal_form.compile unless @is_normal
discriminator_map
end
|
#intersect_normal(other) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/types/union.rb', line 20
def intersect_normal(other)
@types.reduce(Union.new) do |u, t|
u.union_normal(t.intersect_normal(other))
end
end
|
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/types/union.rb', line 6
def normal_form
unless @normalized
@normalized =
@types.reduce(Union.new) do |buffer, type|
if type.is_a?(Merge)
buffer.union_normal(type.normal_form)
else
buffer.union_normal(type)
end
end
end
@normalized
end
|
#to_s ⇒ Object
43
44
45
|
# File 'lib/types/union.rb', line 43
def to_s
@types.map(&:to_s).join(' | ')
end
|
#union_normal(other) ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/types/union.rb', line 27
def union_normal(other)
if other.is_a?(Union)
Union.new(@types.dup.concat(other.types), true)
else
Union.new(@types.dup.push(other), true)
end
end
|
#validate(object) ⇒ Object
37
38
39
40
41
|
# File 'lib/types/union.rb', line 37
def validate(object)
return normal_form.validate(object) unless @is_normal
discriminator_map.validate(object)
end
|