Class: CaTissue::StorageType

Inherits:
Object
  • Object
show all
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

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

#hash

Instance Method Details

#<=>(other) ⇒ Integer

Returns -1, 0, or 1 if self is contained in, contains or the same as the other StorageType, resp.

Raises:

  • (TypeError)


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?



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



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>



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_classObject



23
24
25
# File 'lib/catissue/domain/storage_type.rb', line 23

def container_class
  CaTissue::StorageContainer
end

#path_to(storable) ⇒ <StorageType>?



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

#uniquifyObject



37
38
39
40
# File 'lib/catissue/migration/unique.rb', line 37

def uniquify
  super
  child_container_types.each { |subtype| subtype.uniquify } 
end