Module: Heron::Factories::Concerns::Contents
Overview
This module adds validation and tools to manage factories that act as content in a receptacle Eg: ::Heron::Factories::Sample
Requirements - The method or attribute content_factory needs to be defined with the class that act as factory for contents. Eg: ::Heron::Factories::Sample - The content configuration should be already stored in @params - The content configuration object needs to be in @params - The method or attribute recipients_key will need to identify the key where the config is stored. Eg: :wells - All keys referring to coordinates in the content configuration are considered as validated, if that is not the case, that validation can be provided by including the module Heron::Factories::Concerns::RecipientsCoordinate - The class should include the module Heron::Factories:Concerns::CoordinatesSupport
Use Include the module in the class after checking the previous list of requirements.
Effect Factories for each content in each well will be generated. Any validation error from them will be aggregated in the base object.
Class Method Summary collapse
Instance Method Summary collapse
- #_factories_for_location(location, samples_params) ⇒ Object
- #add_aliquots_into_location(container, factories) ⇒ Object
- 
  
    
      #add_aliquots_into_locations(containers_for_locations)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Creates aliquots for the samples that will be created from contents. 
- #contents ⇒ Object
- #label_for_error_message(location, pos, samples_params) ⇒ Object
- #params_for_contents ⇒ Object
- #study_uuid ⇒ Object
Class Method Details
.included(klass) ⇒ Object
| 30 31 32 | # File 'app/models/heron/factories/concerns/contents.rb', line 30 def self.included(klass) klass.instance_eval { validate :contents } end | 
Instance Method Details
#_factories_for_location(location, samples_params) ⇒ Object
| 81 82 83 84 85 86 87 88 89 90 91 | # File 'app/models/heron/factories/concerns/contents.rb', line 81 def _factories_for_location(location, samples_params) samples_params.each_with_index.map do |sample_params, pos| sample_params = sample_params.merge(study_uuid:) if study_uuid factory = content_factory.new(sample_params) unless factory.valid? label = (location, pos, samples_params) errors.add(label, factory.errors.) end factory end end | 
#add_aliquots_into_location(container, factories) ⇒ Object
| 66 67 68 | # File 'app/models/heron/factories/concerns/contents.rb', line 66 def add_aliquots_into_location(container, factories) factories.each { |factory| factory.create_aliquot_at(container) if factory.valid? } end | 
#add_aliquots_into_locations(containers_for_locations) ⇒ Object
Creates aliquots for the samples that will be created from contents. Args: containers_for_locations: Hash<Coordinate, Container> where container is a Well or a tube and Coordinate is a position in the rack Returns: Boolean indicating if the action was produced
| 57 58 59 60 61 62 63 64 | # File 'app/models/heron/factories/concerns/contents.rb', line 57 def add_aliquots_into_locations(containers_for_locations) return unless contents contents.each_key do |location, _factories| add_aliquots_into_location(containers_for_locations[location], contents[location]) end true end | 
#contents ⇒ Object
| 38 39 40 41 42 43 44 45 46 47 48 49 | # File 'app/models/heron/factories/concerns/contents.rb', line 38 def contents return if errors.count.positive? return unless params_for_contents @contents ||= params_for_contents .keys .each_with_object({}) do |coordinate, memo| samples_params = [params_for_contents[coordinate]].flatten.compact memo[unpad_coordinate(coordinate)] = _factories_for_location(coordinate, samples_params) end end | 
#label_for_error_message(location, pos, samples_params) ⇒ Object
| 93 94 95 | # File 'app/models/heron/factories/concerns/contents.rb', line 93 def (location, pos, samples_params) samples_params.length == 1 ? "Content #{location}" : "Content #{location}, pos: #{pos}" end | 
#params_for_contents ⇒ Object
| 70 71 72 73 74 75 76 77 78 79 | # File 'app/models/heron/factories/concerns/contents.rb', line 70 def params_for_contents return unless @params[recipients_key] @params_for_contents ||= @params[recipients_key] .keys .each_with_object({}) do |location, obj| obj[unpad_coordinate(location)] = @params.dig(recipients_key, location, :content) end end | 
#study_uuid ⇒ Object
| 34 35 36 | # File 'app/models/heron/factories/concerns/contents.rb', line 34 def study_uuid @params[:study_uuid] end |