Module: Shared::BiologicalExtensions
- Extended by:
- ActiveSupport::Concern
- Included in:
- CollectionObject, FieldOccurrence
- Defined in:
- app/models/concerns/shared/biological_extensions.rb
Overview
Shared code that references things with TaxonDeterminations and Biocuration classes
Current FieldOccurence
CollectionObject (should be CollectionObject::BiologicalCollectionObject)
Instance Method Summary collapse
- #descendant_anatomical_part_ids ⇒ Array<Integer> private
-
#missing_determination ⇒ Object
see BiologicalCollectionObject.
-
#name_at_rank_string(rank) ⇒ String
Ugh: TODO: deprecate! no utility gained here, and it’s HTML!!!.
-
#propagate_current_otu_change!(from_id:, to_id:) ⇒ Object
Propagate a change in the accepted OTU (top/position 1 TaxonDetermination) down to descendant AnatomicalParts.
- #reject_otus(attributed) ⇒ Object
- #reject_taxon_determinations(attributed) ⇒ Boolean
- #requires_taxon_determination? ⇒ Boolean
Instance Method Details
#descendant_anatomical_part_ids ⇒ Array<Integer> (private)
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/models/concerns/shared/biological_extensions.rb', line 120 def descendant_anatomical_part_ids project = project_id seen_ids = Set.new result = [] frontier = [id] old_type = self.class.base_class.name while frontier.any? old_frontier = frontier frontier = [] old_old_type = old_type old_type = 'AnatomicalPart' old_frontier.each do |old_id| rels = OriginRelationship .where( project_id: project, old_object_type: old_old_type, old_object_id: old_id, new_object_type: 'AnatomicalPart') .pluck(:new_object_id) rels.each do |anatomical_part_id| next if seen_ids.include?(anatomical_part_id) seen_ids << anatomical_part_id result << anatomical_part_id frontier << anatomical_part_id end end end result end |
#missing_determination ⇒ Object
see BiologicalCollectionObject
72 73 |
# File 'app/models/concerns/shared/biological_extensions.rb', line 72 def missing_determination end |
#name_at_rank_string(rank) ⇒ String
Ugh: TODO: deprecate! no utility gained here, and it’s HTML!!!
82 83 84 |
# File 'app/models/concerns/shared/biological_extensions.rb', line 82 def name_at_rank_string(rank) current_taxon_name.try(:ancestor_at_rank, rank).try(:cached_html) end |
#propagate_current_otu_change!(from_id:, to_id:) ⇒ Object
Propagate a change in the accepted OTU (top/position 1 TaxonDetermination) down to descendant AnatomicalParts.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/models/concerns/shared/biological_extensions.rb', line 99 def propagate_current_otu_change!(from_id:, to_id:) return true if from_id == to_id # includes nil == nil return true if !AnatomicalPart.valid_old_object_classes.include?(self.class.name) anatomical_part_ids = descendant_anatomical_part_ids return true if anatomical_part_ids.empty? scope = AnatomicalPart .where(project_id: project_id, id: anatomical_part_ids) .where(cached_otu_id: from_id) scope.update_all(cached_otu_id: to_id) true rescue => e Rails.logger.warn("#{self.class}##{id} propagation failed: #{e.class}: #{e.}") false end |
#reject_otus(attributed) ⇒ Object
91 92 93 94 95 |
# File 'app/models/concerns/shared/biological_extensions.rb', line 91 def reject_otus(attributed) a = attributed['taxon_name_id'] b = attributed['name'] a.blank? && b.blank? end |
#reject_taxon_determinations(attributed) ⇒ Boolean
87 88 89 |
# File 'app/models/concerns/shared/biological_extensions.rb', line 87 def reject_taxon_determinations(attributed) attributed['otu_id'].blank? && attributed[:otu]&.id.blank? end |
#requires_taxon_determination? ⇒ Boolean
75 76 77 |
# File 'app/models/concerns/shared/biological_extensions.rb', line 75 def requires_taxon_determination? false end |