Module: Shared::IsData

Extended by:
ActiveSupport::Concern
Included in:
AlternateValue, AssertedDistribution, BiocurationClassification, BiologicalAssociation, BiologicalAssociationsBiologicalAssociationsGraph, BiologicalAssociationsGraph, BiologicalRelationship, BiologicalRelationshipType, Citation, CitationTopic, CollectingEvent, CollectionObject, CollectionObjectObservation, CollectionProfile, CommonName, Confidence, Container, ContainerItem, ContainerLabel, Content, ControlledVocabularyTerm, DataAttribute, Depiction, DerivedCollectionObject, Document, Documentation, GeographicArea, GeographicAreaType, GeographicAreasGeographicItem, GeographicItem, Georeference, Identifier, Image, Language, Loan, LoanItem, Namespace, Note, Otu, OtuPageLayout, OtuPageLayoutSection, Person, PreparationType, ProjectMember, ProjectSource, Protocol, ProtocolRelationship, RangedLotCategory, Repository, Role, 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).

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary (collapse)

Instance Method Details

- (#annotations_hash) annotations

an accessor for the annotations_hash, overwritten by some inheriting classes

Returns:

  • (#annotations_hash)


78
79
80
# File 'app/models/concerns/shared/is_data.rb', line 78

def annotations
  annotations_hash
end

- (Hash) annotations_hash (protected)

Contains all “annotations” for this instance

Returns:

  • (Hash)


145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'app/models/concerns/shared/is_data.rb', line 145

def annotations_hash
  result = {}
  result['alternate values'] = self.alternate_values if self.has_alternate_values? && self.alternate_values.any?
  result['citations'] = self.citations if self.has_citations? && self.citations.any?
  result['data attributes'] = self.data_attributes if self.has_data_attributes? && self.data_attributes.any?
  result['identifiers'] = self.identifiers if self.has_identifiers? && self.identifiers.any?
  result['notes'] = self.notes if self.has_notes? && self.notes.any?
  result['tags'] = self.tags if self.has_tags? && self.tags.any?
  result['depictions'] = self.depictions.order('depictions.position') if self.has_depictions? && self.depictions.any?
  result['confidences'] = self.confidences if self.has_confidences? && self.confidences.any?
  result['protocols'] = self.protocols if self.has_protocols? && self.protocols.any?
  result
end

- (Object) errors_excepting(*keys)



82
83
84
85
86
87
88
# File 'app/models/concerns/shared/is_data.rb', line 82

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

- (Object) full_error_messages_excepting(*keys)



90
91
92
# File 'app/models/concerns/shared/is_data.rb', line 90

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

- (Boolean) has_alternate_values?

Determines whether the instance can be annotated in one of the following ways

Returns:

  • (Boolean)


19
20
21
# File 'app/models/concerns/shared/is_data.rb', line 19

def has_alternate_values?
  self.class < Shared::AlternateValues ? true : false
end

- (Boolean) has_citations?

Returns:

  • (Boolean)


23
24
25
# File 'app/models/concerns/shared/is_data.rb', line 23

def has_citations?
  self.class < Shared::Citable ? true : false
end

- (Boolean) has_confidences?

Returns:

  • (Boolean)


43
44
45
# File 'app/models/concerns/shared/is_data.rb', line 43

def has_confidences?
  self.class < Shared::Confidence ? true : false
end

- (Boolean) has_data_attributes?

Returns:

  • (Boolean)


27
28
29
# File 'app/models/concerns/shared/is_data.rb', line 27

def has_data_attributes?
  self.class < Shared::DataAttributes ? true : false
end

- (Boolean) has_depictions?

Returns:

  • (Boolean)


47
48
49
# File 'app/models/concerns/shared/is_data.rb', line 47

def has_depictions?
  self.class < Shared::Depictions ? true : false
end

- (Boolean) has_identifiers?

Returns:

  • (Boolean)


31
32
33
# File 'app/models/concerns/shared/is_data.rb', line 31

def has_identifiers?
  self.class < Shared::Identifiable ? true : false
end

- (Boolean) has_notes?

Returns:

  • (Boolean)


35
36
37
# File 'app/models/concerns/shared/is_data.rb', line 35

def has_notes?
  self.class < Shared::Notable ? true : false
end

- (Boolean) has_protocols?

Returns:

  • (Boolean)


55
56
57
# File 'app/models/concerns/shared/is_data.rb', line 55

def has_protocols?
  self.class < Shared::Protocols ? true : false
end

- (Boolean) has_tags?

Returns:

  • (Boolean)


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

def has_tags?
  self.class < Shared::Taggable ? true : false
end

- (Boolean) is_community?

Returns:

  • (Boolean)


72
73
74
# File 'app/models/concerns/shared/is_data.rb', line 72

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

- (Boolean) is_in_use?

Also need to check has_one relationships

Returns:

  • (Boolean)


60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/concerns/shared/is_data.rb', line 60

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

- (Boolean) is_loanable?

Returns:

  • (Boolean)


51
52
53
# File 'app/models/concerns/shared/is_data.rb', line 51

def is_loanable? 
  self.class < Shared::Loanable ? true : false
end

- (Object) metamorphosize



12
13
14
15
# File 'app/models/concerns/shared/is_data.rb', line 12

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