Class: Note
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Note
- Includes:
- Housekeeping, Shared::AttributeAnnotations, Shared::BiologicalAssociationIndexHooks, Shared::IsData, Shared::PolymorphicAnnotator, Shared::Tags
- Defined in:
- app/models/note.rb
Overview
A note is a text annotation on a data instance (record).
Notes are text only annotations on instances that belong to some project (i.e. models that include Housekeeping::Projects). Notes can not be cited.
To annotate global (models that do not include Housekeeping::Projects) instances use a DataAttribute.
#@!attribute note_object_attribute
@return [String]
The specific attribute being annotated.
Instance Attribute Summary collapse
-
#note_object_id ⇒ String
The object id being annotated.
-
#note_object_type ⇒ String
The object type being annotated.
- #project_id ⇒ Integer
-
#text ⇒ String
The content of the note.
Class Method Summary collapse
Instance Method Summary collapse
-
#biological_association_indices ⇒ ActiveRecord::Relation
BiologicalAssociationIndex records for associations that have this note.
-
#note_string ⇒ Object
TODO: make a helper Format a note.
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_in_use?, #similar
Methods included from Shared::PolymorphicAnnotator
#annotated_object_is_persisted?
Methods included from Shared::Tags
#reject_tags, #tag_with, #tagged?, #tagged_with?
Methods included from Shared::AttributeAnnotations
#annotated_column, #annotated_value_is_not_identical_to_attribute, #annotation_value, #attribute_to_annotate_is_valid_for_object, #original_value
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Instance Attribute Details
#note_object_id ⇒ String
Returns The object id being annotated.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/note.rb', line 27 class Note < ApplicationRecord # Notes can not be cited! include Housekeeping include Shared::AttributeAnnotations include Shared::Tags include Shared::PolymorphicAnnotator include Shared::IsData include Shared::BiologicalAssociationIndexHooks polymorphic_annotates(:note_object) ignore_whitespace_on(:text) # Please DO NOT include the following, they get in the way # of the present housekeeping approach. A not null constraint exists # to catch these. # validates_associated :note_object # validates_presence_of :note_object_id, :note_object_type validates_presence_of :text validates_uniqueness_of :text, scope: [:note_object_id, :note_object_type, :project_id] def self.annotated_attribute_column :note_object_attribute end def self.annotation_value_column :text end # TODO: make a helper # Format a note def note_string "#{updated_at}: #{updater.name}: #{text}" + (note_object_attribute.blank? ? '' : "[on: #{note_object_attribute}]") end # @return [ActiveRecord::Relation] # BiologicalAssociationIndex records for associations that have this note def biological_association_indices return BiologicalAssociationIndex.none unless note_object_type == 'BiologicalAssociation' BiologicalAssociationIndex.where(biological_association_id: note_object_id) end end |
#note_object_type ⇒ String
Returns The object type being annotated.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/note.rb', line 27 class Note < ApplicationRecord # Notes can not be cited! include Housekeeping include Shared::AttributeAnnotations include Shared::Tags include Shared::PolymorphicAnnotator include Shared::IsData include Shared::BiologicalAssociationIndexHooks polymorphic_annotates(:note_object) ignore_whitespace_on(:text) # Please DO NOT include the following, they get in the way # of the present housekeeping approach. A not null constraint exists # to catch these. # validates_associated :note_object # validates_presence_of :note_object_id, :note_object_type validates_presence_of :text validates_uniqueness_of :text, scope: [:note_object_id, :note_object_type, :project_id] def self.annotated_attribute_column :note_object_attribute end def self.annotation_value_column :text end # TODO: make a helper # Format a note def note_string "#{updated_at}: #{updater.name}: #{text}" + (note_object_attribute.blank? ? '' : "[on: #{note_object_attribute}]") end # @return [ActiveRecord::Relation] # BiologicalAssociationIndex records for associations that have this note def biological_association_indices return BiologicalAssociationIndex.none unless note_object_type == 'BiologicalAssociation' BiologicalAssociationIndex.where(biological_association_id: note_object_id) end end |
#project_id ⇒ Integer
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/note.rb', line 27 class Note < ApplicationRecord # Notes can not be cited! include Housekeeping include Shared::AttributeAnnotations include Shared::Tags include Shared::PolymorphicAnnotator include Shared::IsData include Shared::BiologicalAssociationIndexHooks polymorphic_annotates(:note_object) ignore_whitespace_on(:text) # Please DO NOT include the following, they get in the way # of the present housekeeping approach. A not null constraint exists # to catch these. # validates_associated :note_object # validates_presence_of :note_object_id, :note_object_type validates_presence_of :text validates_uniqueness_of :text, scope: [:note_object_id, :note_object_type, :project_id] def self.annotated_attribute_column :note_object_attribute end def self.annotation_value_column :text end # TODO: make a helper # Format a note def note_string "#{updated_at}: #{updater.name}: #{text}" + (note_object_attribute.blank? ? '' : "[on: #{note_object_attribute}]") end # @return [ActiveRecord::Relation] # BiologicalAssociationIndex records for associations that have this note def biological_association_indices return BiologicalAssociationIndex.none unless note_object_type == 'BiologicalAssociation' BiologicalAssociationIndex.where(biological_association_id: note_object_id) end end |
#text ⇒ String
Returns The content of the note. Markdown is supported.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/note.rb', line 27 class Note < ApplicationRecord # Notes can not be cited! include Housekeeping include Shared::AttributeAnnotations include Shared::Tags include Shared::PolymorphicAnnotator include Shared::IsData include Shared::BiologicalAssociationIndexHooks polymorphic_annotates(:note_object) ignore_whitespace_on(:text) # Please DO NOT include the following, they get in the way # of the present housekeeping approach. A not null constraint exists # to catch these. # validates_associated :note_object # validates_presence_of :note_object_id, :note_object_type validates_presence_of :text validates_uniqueness_of :text, scope: [:note_object_id, :note_object_type, :project_id] def self.annotated_attribute_column :note_object_attribute end def self.annotation_value_column :text end # TODO: make a helper # Format a note def note_string "#{updated_at}: #{updater.name}: #{text}" + (note_object_attribute.blank? ? '' : "[on: #{note_object_attribute}]") end # @return [ActiveRecord::Relation] # BiologicalAssociationIndex records for associations that have this note def biological_association_indices return BiologicalAssociationIndex.none unless note_object_type == 'BiologicalAssociation' BiologicalAssociationIndex.where(biological_association_id: note_object_id) end end |
Class Method Details
.annotated_attribute_column ⇒ Object
47 48 49 |
# File 'app/models/note.rb', line 47 def self.annotated_attribute_column :note_object_attribute end |
.annotation_value_column ⇒ Object
51 52 53 |
# File 'app/models/note.rb', line 51 def self.annotation_value_column :text end |
Instance Method Details
#biological_association_indices ⇒ ActiveRecord::Relation
Returns BiologicalAssociationIndex records for associations that have this note.
63 64 65 66 67 |
# File 'app/models/note.rb', line 63 def biological_association_indices return BiologicalAssociationIndex.none unless note_object_type == 'BiologicalAssociation' BiologicalAssociationIndex.where(biological_association_id: note_object_id) end |
#note_string ⇒ Object
TODO: make a helper Format a note
57 58 59 |
# File 'app/models/note.rb', line 57 def note_string "#{updated_at}: #{updater.name}: #{text}" + (note_object_attribute.blank? ? '' : "[on: #{note_object_attribute}]") end |