Class: CaTissue::StorageType
- Inherits:
-
Object
- Object
- CaTissue::StorageType
- Includes:
- HashCode, StorageTypeHolder, Jinx::PartialOrder
- Defined in:
- lib/catissue/domain/storage_type.rb,
lib/catissue/migration/unique.rb
Overview
The StorageType domain class.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Returns -1, 0, or 1 if self is contained in, contains or the same as the other StorageType, resp.
-
#==(other) ⇒ Boolean
(also: #eql?)
Whether this StorageType has a non-nil name equal to the other name or is
equal?
to this StorageType. -
#can_hold_child?(storable) ⇒ Boolean
Whether this StorageType can hold a child of the given Storable storable type.
-
#closure ⇒ <ContainerType>
The closure of types held by this type, including self.
-
#container_class ⇒ Object
StorageContainer.
-
#path_to(storable) ⇒ <StorageType>?
The array consisting of types from this type to a descendant type which can hold the given storable, or nil if no such path exists.
- #uniquify ⇒ Object
Methods included from StorageTypeHolder
#add_child_type, #child_container_types, #child_specimen_array_types, #child_specimen_classes, #child_storage_types, #child_types
Methods included from HashCode
Instance Method Details
#<=>(other) ⇒ Integer
Returns -1, 0, or 1 if self is contained in, contains or the same as the other StorageType, resp.
69 70 71 72 73 74 |
# File 'lib/catissue/domain/storage_type.rb', line 69 def <=>(other) raise TypeError.new("Can't compare #{qp} to #{other}") unless StorageType === self return 0 if eql?(other) return 1 if holds_storage_types.detect { |child| child >= other } -1 if other > self end |
#==(other) ⇒ Boolean Also known as: eql?
Returns whether this StorageType has a non-nil name equal to the other name or is equal?
to this StorageType.
58 59 60 |
# File 'lib/catissue/domain/storage_type.rb', line 58 def ==(other) equal?(other) or (StorageType === other and name and name == other.name) end |
#can_hold_child?(storable) ⇒ Boolean
Returns whether this StorageType can hold a child of the given Storable storable type.
34 35 36 |
# File 'lib/catissue/domain/storage_type.rb', line 34 def can_hold_child?(storable) child_types.include?(storable.storable_type) end |
#closure ⇒ <ContainerType>
Returns the closure of types held by this type, including self.
47 48 49 50 51 |
# File 'lib/catissue/domain/storage_type.rb', line 47 def closure cts = [self] child_types.each { |ct| cts.concat(ct.closure) if StorageType === ct } cts end |
#container_class ⇒ Object
Returns StorageContainer.
23 24 25 |
# File 'lib/catissue/domain/storage_type.rb', line 23 def container_class CaTissue::StorageContainer end |
#path_to(storable) ⇒ <StorageType>?
Returns the array consisting of types from this type to a descendant type which can hold the given storable, or nil if no such path exists.
40 41 42 43 44 |
# File 'lib/catissue/domain/storage_type.rb', line 40 def path_to(storable) return [self] if can_hold_child?(storable) path = holds_storage_types.detect_value { |child| child.path_to(storable) } return path.unshift(self) if path end |
#uniquify ⇒ Object
37 38 39 40 |
# File 'lib/catissue/migration/unique.rb', line 37 def uniquify super child_container_types.each { |subtype| subtype.uniquify } end |