Class: Yoda::Model::Types::UnionType
- Defined in:
- lib/yoda/model/types/union_type.rb
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Class Method Summary collapse
Instance Method Summary collapse
- #change_root(paths) ⇒ self
- #eql?(another) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(types) ⇒ UnionType
constructor
A new instance of UnionType.
- #map(&block) ⇒ self
- #resolve(registry) ⇒ Array<Store::Objects::Base>
- #to_s ⇒ String
Methods inherited from Base
Constructor Details
#initialize(types) ⇒ UnionType
Returns a new instance of UnionType.
19 20 21 |
# File 'lib/yoda/model/types/union_type.rb', line 19 def initialize(types) @types = types end |
Instance Attribute Details
#types ⇒ Object (readonly)
Returns the value of attribute types.
7 8 9 |
# File 'lib/yoda/model/types/union_type.rb', line 7 def types @types end |
Class Method Details
.new(types) ⇒ Base
11 12 13 14 15 16 |
# File 'lib/yoda/model/types/union_type.rb', line 11 def self.new(types) reduced_types = types.reject { |type| type.is_a?(AnyType) || type.is_a?(UnknownType) }.uniq return (types.first || AnyType.new) if reduced_types.length == 0 return reduced_types.first if reduced_types.length == 1 super(reduced_types) end |
Instance Method Details
#change_root(paths) ⇒ self
34 35 36 |
# File 'lib/yoda/model/types/union_type.rb', line 34 def change_root(paths) self.class.new(types.map { |type| type.change_root(paths) }) end |
#eql?(another) ⇒ Boolean
23 24 25 26 |
# File 'lib/yoda/model/types/union_type.rb', line 23 def eql?(another) another.is_a?(UnionType) && Set.new(types) == Set.new(another.types) end |
#hash ⇒ Object
28 29 30 |
# File 'lib/yoda/model/types/union_type.rb', line 28 def hash [self.class.name, Set.new(types)].hash end |
#map(&block) ⇒ self
50 51 52 |
# File 'lib/yoda/model/types/union_type.rb', line 50 def map(&block) self.class.new(types.map(&block)) end |
#resolve(registry) ⇒ Array<Store::Objects::Base>
40 41 42 |
# File 'lib/yoda/model/types/union_type.rb', line 40 def resolve(registry) types.map { |type| type.resolve(registry) }.flatten.compact end |
#to_s ⇒ String
45 46 47 |
# File 'lib/yoda/model/types/union_type.rb', line 45 def to_s types.map(&:to_s).join(' | ') end |