Class: CaTissue::ContainerType

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

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.

Parameters:

  • vh ({Symbol => Object}) (defaults to: nil)

    the attribute => value hash

Returns:



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?.

Parameters:

  • site (CaTissue::Site)

    the site where the candidate containers are located

Returns:



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.

Parameters:

  • params (<Symbol => Object>) (defaults to: nil)

    the optional search attribute => value hash

Returns:

  • the containers of this type which satisfy the search parameters



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