Class: Note

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Housekeeping, Shared::AttributeAnnotations, Shared::IsData, Shared::Taggable
Defined in:
app/models/note.rb

Overview

A note is a text annotation on a data instance (record).

Notes are text only notes on instances that belong to some project (e.g. models that include Shared::IsData). For global instances use DataAttribute.

Notes may include any text excluding pipes ('|'). Pipes are a reserved object separator for output.

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_attribute

TODO:

Returns:

  • (String)


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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/note.rb', line 24

class Note < ActiveRecord::Base
  include Housekeeping
  include Shared::IsData 
  include Shared::AttributeAnnotations
  include Shared::Taggable

  belongs_to :note_object, polymorphic: true
  before_validation :no_pipes

  # 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]

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

  # @return [NoteObject]
  #   alias to simplify reference across classes 
  def annotated_object
    note_object 
  end

  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

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

  protected

  def no_pipes
    if !self.text.blank?
      errors.add(:text, 'TW notes may not contain a pipe (||)') if self.text.include?('||')
    end
  end
end

- (String) note_object_type

TODO:

Returns:

  • (String)


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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/note.rb', line 24

class Note < ActiveRecord::Base
  include Housekeeping
  include Shared::IsData 
  include Shared::AttributeAnnotations
  include Shared::Taggable

  belongs_to :note_object, polymorphic: true
  before_validation :no_pipes

  # 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]

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

  # @return [NoteObject]
  #   alias to simplify reference across classes 
  def annotated_object
    note_object 
  end

  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

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

  protected

  def no_pipes
    if !self.text.blank?
      errors.add(:text, 'TW notes may not contain a pipe (||)') if self.text.include?('||')
    end
  end
end

- (Integer) project_id

the project ID

Returns:

  • (Integer)


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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/note.rb', line 24

class Note < ActiveRecord::Base
  include Housekeeping
  include Shared::IsData 
  include Shared::AttributeAnnotations
  include Shared::Taggable

  belongs_to :note_object, polymorphic: true
  before_validation :no_pipes

  # 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]

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

  # @return [NoteObject]
  #   alias to simplify reference across classes 
  def annotated_object
    note_object 
  end

  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

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

  protected

  def no_pipes
    if !self.text.blank?
      errors.add(:text, 'TW notes may not contain a pipe (||)') if self.text.include?('||')
    end
  end
end

- (String) text

TODO:

Returns:

  • (String)


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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/note.rb', line 24

class Note < ActiveRecord::Base
  include Housekeeping
  include Shared::IsData 
  include Shared::AttributeAnnotations
  include Shared::Taggable

  belongs_to :note_object, polymorphic: true
  before_validation :no_pipes

  # 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]

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

  # @return [NoteObject]
  #   alias to simplify reference across classes 
  def annotated_object
    note_object 
  end

  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

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

  protected

  def no_pipes
    if !self.text.blank?
      errors.add(:text, 'TW notes may not contain a pipe (||)') if self.text.include?('||')
    end
  end
end

Class Method Details

+ (Object) annotated_attribute_column



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

def self.annotated_attribute_column
  :note_object_attribute
end

+ (Object) annotation_value_column



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

def self.annotation_value_column
  :text
end

+ (Object) find_for_autocomplete(params)



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

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

+ (Object) generate_download(scope)



64
65
66
67
68
69
70
71
72
73
# File 'app/models/note.rb', line 64

def self.generate_download(scope)
  CSV.generate do |csv|
    csv << column_names
    scope.order(id: :asc).find_each do |o|
      csv << o.attributes.values_at(*column_names).collect { |i|
        i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
      }
    end
  end
end

Instance Method Details

- (NoteObject) annotated_object

Returns alias to simplify reference across classes

Returns:

  • (NoteObject)

    alias to simplify reference across classes



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

def annotated_object
  note_object 
end

- (Object) no_pipes (protected)



77
78
79
80
81
# File 'app/models/note.rb', line 77

def no_pipes
  if !self.text.blank?
    errors.add(:text, 'TW notes may not contain a pipe (||)') if self.text.include?('||')
  end
end

- (Object) note_string

Format a note



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

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