Class: CaTissue::ContainerType

Inherits:
Object
  • Object
show all
Includes:
Jinx::Unique
Defined in:
lib/catissue/domain/container_type.rb,
lib/catissue/migration/unique.rb

Overview

The caTissue ContainerType domain class wrapper. Each ContainerType subclass is required to implement the container_class method.

Instance Method Summary collapse

Instance Method Details

#find_available(site, opts = nil) ⇒ Object



101
102
103
104
105
# File 'lib/catissue/domain/container_type.rb', line 101

def find_available(site, opts=nil)
  logger.debug { "Finding an available #{site} #{self} container..." }
  find_containers(:site => site).detect { |ctr| not ctr.completely_full? } or
  (new_container(:site => site).create if Options.get(:create, opts))
end

#find_containers(params = nil) ⇒ Object

Fetches containers of this ContainerType from the database.



111
112
113
114
115
# File 'lib/catissue/domain/container_type.rb', line 111

def find_containers(params=nil)
  tmpl = new_container(params)
  logger.debug { "Finding #{name} containers..." }
  tmpl.query
end

#merge_attributes(other, attributes = nil, matches = nil, &filter) ⇒ Object Also known as: merge_container_type_attributes

Override default Jinx::Resource.merge_attributes to support the Capacity :rows and :columns pseudo-attributes.



84
85
86
87
88
89
90
91
# File 'lib/catissue/domain/container_type.rb', line 84

def merge_attributes(other, attributes=nil, matches=nil, &filter)
  if Hash === other then
    # partition the other hash into the Capacity attributes and ContainerType attributes
    cph, other = other.split { |key, value| key == :rows or key == :columns }
    self.capacity ||= CaTissue::Capacity.new(cph).add_defaults unless cph.empty?
  end
  super
end

#new_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.



122
123
124
125
126
# File 'lib/catissue/domain/container_type.rb', line 122

def new_container(vh=nil)
  vh ||= {}
  vh[:container_type] = self
  container_class.new(vh)
end