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). 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)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Instance Attribute Details

- (String) note_object_id

Returns The object id being annotated

Returns:

  • (String)

    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
# File 'app/models/note.rb', line 27

class Note < ApplicationRecord

  # Notes can not be cited!

  include Housekeeping
  include Shared::IsData
  include Shared::AttributeAnnotations
  include Shared::Tags
  include Shared::PolymorphicAnnotator
  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

  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 type being annotated

Returns:

  • (String)

    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
# File 'app/models/note.rb', line 27

class Note < ApplicationRecord

  # Notes can not be cited!

  include Housekeeping
  include Shared::IsData
  include Shared::AttributeAnnotations
  include Shared::Tags
  include Shared::PolymorphicAnnotator
  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

  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

Returns:

  • (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
# File 'app/models/note.rb', line 27

class Note < ApplicationRecord

  # Notes can not be cited!

  include Housekeeping
  include Shared::IsData
  include Shared::AttributeAnnotations
  include Shared::Tags
  include Shared::PolymorphicAnnotator
  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

  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. Markdown is supported.

Returns:

  • (String)

    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
# File 'app/models/note.rb', line 27

class Note < ApplicationRecord

  # Notes can not be cited!

  include Housekeeping
  include Shared::IsData
  include Shared::AttributeAnnotations
  include Shared::Tags
  include Shared::PolymorphicAnnotator
  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

  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



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

def self.annotated_attribute_column
  :note_object_attribute
end

+ (Object) annotation_value_column



51
52
53
# File 'app/models/note.rb', line 51

def self.annotation_value_column
  :text
end

+ (Object) find_for_autocomplete(params)



55
56
57
# File 'app/models/note.rb', line 55

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



61
62
63
# File 'app/models/note.rb', line 61

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