Class: CaTissue::ContainerType
- Inherits:
-
Object
- Object
- CaTissue::ContainerType
- Includes:
- Resource
- Defined in:
- lib/catissue/domain/container_type.rb
Overview
The caTissue ContainerType domain class wrapper. Each ContainerType subclass is required to implement the container_class method.
caTissue alert - the ContainerType and Container class hierarchy is a confusing olio of entangled relationships. The canonical use case is as follows:
-
A Specimen is contained in a box, vial or specimen array.
-
A vial or specimen array can also be placed in a box.
-
A frozen specimen container is placed on a rack in a freezer.
This conceptual model is implemented in caTissue as follows:
-
The specimen collection container type, e.g. Citrate Vacutainer, is captured as a CaTissue::CollectionEventParameters#container String. There is no separate collection container instance or container type instance.
-
A tissue specimen storage box is captured as a StorageContainer instance constrained to a StorageType instance. Boxes with different types are instances of the same StorageContainer class but belong to different StorageType instances.
-
SpecimenArray is a Container but not a StorageContainer. The specimen array class is SpecimenArray, but its type is a SpecimenArrayType instance, which is a ContainerType but not a StorageType.
-
A rack is a StorageContainer instance whose type is a StorageType instance which can hold the box StorageType.
-
A freezer is a StorageContainer instance whose type is a StorageType instance which can hold the rack StorageType.
-
Each StorageContainer belongs to a given Site. A child StorageContainer site defaults to its parent container site. Site consistency is not enforced by caTissue, i.e. it is possible to create a rack whose site differs from that of its parent freezer and child boxes.
-
SpecimenArray is not associated to a site.
-
The container children are partitioned into three methods for the three different types and pseudo-types of contained items: StorageContainer, SpecimenArray and Specimen#class.
-
SpecimenArray holds SpecimenArrayContent positions, which are the functional equivalent of SpecimenPosition adapted for specimen arrays, although SpecimenArrayContent is not a SpecimenPosition or even an AbstractPosition. SpecimenPosition is functionally a specimen position in a box, whereas SpecimenArrayContent is functionally a specimen position in a specimen array.
The ContainerType/Container mish-mash is partially rationalized in caRuby as follows:
-
StorageType and StorageContainer include the StorageTypeHolder module, which unifies treatment of contained types.
-
Similarly, AbstractPosition and SpecimenArrayContent include the Position module, which unifies treatment of positions.
-
Contained child types are consolidated into StorageTypeHolder#child_types.
-
Similarly, StorageContainer child items are consolidated into StorageContainer#child_types.
-
The various container and position classes are augmented with helper methods to add, move and find specimens and subcontainers. These methods hide the mind-numbing eccentricity of caTissue specimen storage interaction.
The entire amalgamation is further simplifying by introducing the standard Ruby container add method CaTissue::Container::<<. The only call the caRuby client needs to make to add a specimen box to a freezer is:
freezer << box
which places the box in the first available rack slot in the freezer, or:
freezer.add box :at =>
Instance Method Summary collapse
-
#create_container(vh = nil) ⇒ Container
Returns a new Container instance of this ContainerType with an optional attribute => value hash.
-
#find_available(site, opts = nil) ⇒ Object
An available container of this ContainerType which is not CaTissue::Container#completely_full?.
-
#find_containers(params = nil) ⇒ Object
Fetches containers of this ContainerType from the database.
-
#merge_attributes(other, attributes = nil) ⇒ Object
Override default CaRuby::Resource#merge_attributes to support the Capacity :rows and :columns pseudo-attributes.
Methods included from Resource
#database, included, #tolerant_match?
Methods included from Annotatable
#annotation_proxy, #create_proxy, #method_missing
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class CaTissue::Annotatable
Instance Method Details
#create_container(vh = nil) ⇒ Container
Returns a new Container instance of this ContainerType with an optional attribute => value hash. The container_type of the new Container is this ContainerType.
120 121 122 123 124 |
# File 'lib/catissue/domain/container_type.rb', line 120 def create_container(vh=nil) vh ||= {} vh[:container_type] = self container_class.new(vh) end |
#find_available(site, opts = nil) ⇒ Object
Returns an available container of this ContainerType which is not CaTissue::Container#completely_full?.
100 101 102 103 |
# File 'lib/catissue/domain/container_type.rb', line 100 def find_available(site, opts=nil) find_containers(:site => site).detect { |ctr| not ctr.completely_full? } or (create_container(:site => site).create if Options.get(:create, opts)) end |
#find_containers(params = nil) ⇒ Object
Fetches containers of this ContainerType from the database.
109 110 111 112 113 |
# File 'lib/catissue/domain/container_type.rb', line 109 def find_containers(params=nil) tmpl = create_container(params) logger.debug { "Finding #{name} containers..." } tmpl.query end |
#merge_attributes(other, attributes = nil) ⇒ Object
Override default CaRuby::Resource#merge_attributes to support the Capacity :rows and :columns pseudo-attributes.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/catissue/domain/container_type.rb', line 84 def merge_attributes(other, attributes=nil) if Hash === other then # partition the other hash into the Capacity attributes and ContainerType attributes cp_hash, ct_hash = other.partition { |key, value| key == :rows or key == :columns } self.capacity ||= Capacity.new(cp_hash).add_defaults unless cp_hash.empty? super(ct_hash, attributes) else super(other, attributes) end end |