Module: Shared::IsData

Extended by:
ActiveSupport::Concern
Included in:
AlternateValue, AssertedDistribution, BiocurationClassification, BiologicalAssociation, BiologicalAssociationsBiologicalAssociationsGraph, BiologicalAssociationsGraph, BiologicalRelationship, BiologicalRelationshipType, CharacterState, Citation, CitationTopic, CollectingEvent, CollectionObject, CollectionObjectObservation, CollectionProfile, CommonName, Confidence, Container, ContainerItem, Content, ControlledVocabularyTerm, DataAttribute, Depiction, DerivedCollectionObject, Descriptor, Document, Documentation, Extract, GeneAttribute, GeographicArea, GeographicAreaType, GeographicAreasGeographicItem, GeographicItem, Georeference, Identifier, Image, Language, Loan, LoanItem, Namespace, Note, Observation, ObservationMatrix, ObservationMatrixColumn, ObservationMatrixColumnItem, ObservationMatrixRow, ObservationMatrixRowItem, OriginRelationship, Otu, OtuPageLayout, OtuPageLayoutSection, Person, PreparationType, ProjectMember, ProjectSource, Protocol, ProtocolRelationship, RangedLotCategory, Repository, Role, Sequence, SequenceRelationship, Serial, SerialChronology, Source, 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: ClassMethods

Instance Method Summary (collapse)

Instance Method Details

- (Object) errors_excepting(*keys)



37
38
39
40
41
42
43
# File 'app/models/concerns/shared/is_data.rb', line 37

def errors_excepting(*keys)
  valid?
  keys.each do |k|
    errors.delete(k)
  end
  errors
end

- (Object) full_error_messages_excepting(*keys)



45
46
47
# File 'app/models/concerns/shared/is_data.rb', line 45

def full_error_messages_excepting(*keys)
  errors_excepting(*keys).full_messages
end

- (Boolean) is_community?

Returns:

  • (Boolean)


21
22
23
# File 'app/models/concerns/shared/is_data.rb', line 21

def is_community?
  self.class < Shared::SharedAcrossProjects ? true : false
end

- (Boolean) is_in_use?

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/concerns/shared/is_data.rb', line 25

def is_in_use?
  self.class.reflect_on_all_associations(:has_many).each do |r|
    return true if self.send(r.name).count > 0
  end

  self.class.reflect_on_all_associations(:has_one).each do |r|
    return true if self.send(r.name).count > 0
  end

  false
end

- (Object) metamorphosize



16
17
18
19
# File 'app/models/concerns/shared/is_data.rb', line 16

def metamorphosize
  return self if self.class.descends_from_active_record?
  self.becomes(self.class.base_class)
end