Class: Note

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::AttributeAnnotations, 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).

To annotate global (models that do not include Housekeeping::Projects) instances use a DataAttribute.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Instance Attribute Details

- (String) note_object_attribute

Returns The specific attribute being annotated.

Returns:

  • (String)

    The specific attribute being annotated.



23
24
25
26
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
# File 'app/models/note.rb', line 23

class Note < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::AttributeAnnotations
  include Shared::Tags
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:note_object)
  
  # Please DO NOT include the following, they get in the way
  # of the present housekeeping approach. A not null constraint exists
  # to catch these at present.
  #    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

  def self.find_for_autocomplete(params)
    where('text LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id])
  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

end

- (String) note_object_type

Returns The object being annotated.

Returns:

  • (String)

    The object being annotated.



23
24
25
26
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
# File 'app/models/note.rb', line 23

class Note < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::AttributeAnnotations
  include Shared::Tags
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:note_object)
  
  # Please DO NOT include the following, they get in the way
  # of the present housekeeping approach. A not null constraint exists
  # to catch these at present.
  #    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

  def self.find_for_autocomplete(params)
    where('text LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id])
  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

end

- (Integer) project_id

the project ID

Returns:

  • (Integer)


23
24
25
26
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
# File 'app/models/note.rb', line 23

class Note < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::AttributeAnnotations
  include Shared::Tags
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:note_object)
  
  # Please DO NOT include the following, they get in the way
  # of the present housekeeping approach. A not null constraint exists
  # to catch these at present.
  #    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

  def self.find_for_autocomplete(params)
    where('text LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id])
  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

end

- (String) text

Returns The content of the note, in Markdown if you wish.

Returns:

  • (String)

    The content of the note, in Markdown if you wish.



23
24
25
26
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
# File 'app/models/note.rb', line 23

class Note < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::AttributeAnnotations
  include Shared::Tags
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:note_object)
  
  # Please DO NOT include the following, they get in the way
  # of the present housekeeping approach. A not null constraint exists
  # to catch these at present.
  #    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

  def self.find_for_autocomplete(params)
    where('text LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id])
  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

end

Class Method Details

+ (Object) annotated_attribute_column



39
40
41
# File 'app/models/note.rb', line 39

def self.annotated_attribute_column
  :note_object_attribute
end

+ (Object) annotation_value_column



43
44
45
# File 'app/models/note.rb', line 43

def self.annotation_value_column
  :text
end

+ (Object) find_for_autocomplete(params)



47
48
49
# File 'app/models/note.rb', line 47

def self.find_for_autocomplete(params)
  where('text LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id])
end

Instance Method Details

- (Object) note_string

TODO: make a helper Format a note



53
54
55
# File 'app/models/note.rb', line 53

def note_string
  "#{updated_at}: #{updater.name}: #{text}" + (note_object_attribute.blank? ? "" : "[on: #{note_object_attribute}]")
end