Module: Shared::IsData
- Extended by:
- ActiveSupport::Concern
- Included in:
- AlternateValue, AnatomicalPart, AssertedDistribution, Attribution, BiocurationClassification, BiologicalAssociation, BiologicalAssociationsBiologicalAssociationsGraph, BiologicalAssociationsGraph, BiologicalRelationship, BiologicalRelationshipType, CachedMap, CachedMapItem, CachedMapItemTranslation, CachedMapRegister, CharacterState, Citation, CitationTopic, CollectingEvent, CollectionObject, CollectionObjectObservation, CollectionProfile, CommonName, Confidence, Container, ContainerItem, Content, ControlledVocabularyTerm, Conveyance, DataAttribute, DatasetRecord, DatasetRecordField, Depiction, DerivedCollectionObject, Descriptor, Document, Documentation, Download, Extract, FieldOccurrence, Gazetteer, GeneAttribute, GeographicArea, GeographicAreaType, GeographicAreasGeographicItem, GeographicItem, Georeference, Identifier, Image, ImportDataset, Label, Language, Lead, LeadItem, Loan, LoanItem, Namespace, Note, Observation, ObservationMatrix, ObservationMatrixColumn, ObservationMatrixColumnItem, ObservationMatrixRow, ObservationMatrixRowItem, Organization, OriginRelationship, Otu, OtuPageLayout, OtuPageLayoutSection, OtuRelationship, Person, PreparationType, ProjectMember, ProjectSource, Protocol, ProtocolRelationship, RangedLotCategory, Repository, Role, Sequence, SequenceRelationship, Serial, SerialChronology, SledImage, Sound, Source, SqedDepiction, Tag, TaggedSectionKeyword, TaxonDetermination, TaxonName, TaxonNameClassification, TaxonNameRelationship, TypeMaterial
- Defined in:
- app/models/concerns/shared/is_data.rb
Overview
Shared code for a classes that are “data” sensu TaxonWorks (things like Projects, users, and preferences are not data).
!! This module must in included last !!
Defined Under Namespace
Modules: Annotation, ClassMethods, HasRoles, Levenshtein, Metamorphosize, Navigation, Pinnable, Scopes, Stripper
Instance Method Summary collapse
- #errors_excepting(*keys) ⇒ Hash
-
#full_error_messages_excepting(*keys) ⇒ Array
TODO: Doesn’t belong here.
- #identical ⇒ Scope
- #is_community? ⇒ Boolean
-
#is_in_use?(exclude = [], only = []) ⇒ Boolean
!! provide only exclude or only.
- #similar ⇒ Scope
Instance Method Details
#errors_excepting(*keys) ⇒ Hash
203 204 205 206 207 208 209 |
# File 'app/models/concerns/shared/is_data.rb', line 203 def errors_excepting(*keys) valid? keys.each do |k| errors.delete(k) end errors end |
#full_error_messages_excepting(*keys) ⇒ Array
TODO: Doesn’t belong here
240 241 242 |
# File 'app/models/concerns/shared/is_data.rb', line 240 def (*keys) errors_excepting(*keys). end |
#identical ⇒ Scope
226 227 228 229 230 231 232 233 234 235 |
# File 'app/models/concerns/shared/is_data.rb', line 226 def identical klass = self.class attr = Stripper.strip_identical_attributes(klass, attributes) if id scope = klass.where(attr).not_self(self) else scope = klass.where(attr) end scope end |
#is_community? ⇒ Boolean
197 198 199 |
# File 'app/models/concerns/shared/is_data.rb', line 197 def is_community? self.class < Shared::SharedAcrossProjects ? true : false end |
#is_in_use?(exclude = [], only = []) ⇒ Boolean
!! provide only exclude or only
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'app/models/concerns/shared/is_data.rb', line 176 def is_in_use?(exclude = [], only = []) if only.empty? self.class.reflect_on_all_associations(:has_many).each do |r| next if exclude.include?(r.name) return true if self.send(r.name).count(:all) > 0 end self.class.reflect_on_all_associations(:has_one).each do |r| next if exclude.include?(r.name) return true if self.send(r.name).count(:all) > 0 end else only.each do |r| return true if self.send(r.to_s).count(:all) > 0 end end false end |
#similar ⇒ Scope
212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'app/models/concerns/shared/is_data.rb', line 212 def similar klass = self.class attr = Stripper.strip_similar_attributes(klass, attributes) # matching only those attributes from the instance which are not empty attr = attr.select{ |_kee, val| val.present? } if id scope = klass.where(attr).not_self(self) else scope = klass.where(attr) end scope end |