Class: AlternateValue

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::AttributeAnnotations, Shared::DualAnnotator, Shared::IsData, Shared::PolymorphicAnnotator
Defined in:
app/models/alternate_value.rb

Overview

AlternateValue(s) are annotations on an object or object attribute. Use only when the annotations are related to the same thing. (e.g. HernĂ¡n vs. Hernan, NOT Bean Books (publisher1) vs. Dell Books (publisher2))

If you want the annotation to be community wide and it's a valid target use `is_community_annotation: true`.

Defined Under Namespace

Classes: Abbreviation, AlternateSpelling, Misspelling, Translation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Housekeeping

#has_polymorphic_relationship?

Instance Attribute Details

#alternate_value_object_attributeString

Returns the attribute (column) that this is an alternate value for

Returns:

  • (String)

    the attribute (column) that this is an alternate value for



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
83
84
85
86
87
88
# File 'app/models/alternate_value.rb', line 34

class AlternateValue < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::AttributeAnnotations
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:alternate_value_object)

  belongs_to :language

  # Please DO NOT include the following:
  # validates :alternate_value_object, presence: true

  validates :language, presence: true, allow_blank: true
  validates_presence_of :type, :value, :alternate_value_object_attribute
  validates_uniqueness_of :value, scope: [:alternate_value_object, :type, :alternate_value_object_attribute, :project_id] # !! think about project/community on same object

  def self.class_name
    self.name.demodulize.underscore.humanize.downcase
  end

  def klass_name
    self.class.class_name
  end

  def self.find_for_autocomplete(params)
    where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
          "%#{params[:term]}%", params[:project_id])
  end

  # @return [Symbol]
  #   the column name containing the attribute name being annotated
  def self.annotated_attribute_column
    :alternate_value_object_attribute
  end

  def self.annotation_value_column
    :value
  end

  def type_name
    r = self.type.to_s
    ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
  end

  def type_class=(value)
    write_attribute(:type, value.to_s)
  end

  def type_class
    r = read_attribute(:type).to_s
    r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  end

end

#alternate_value_object_typeString

the kind of thing being annotated

Returns:

  • (String)


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
83
84
85
86
87
88
# File 'app/models/alternate_value.rb', line 34

class AlternateValue < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::AttributeAnnotations
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:alternate_value_object)

  belongs_to :language

  # Please DO NOT include the following:
  # validates :alternate_value_object, presence: true

  validates :language, presence: true, allow_blank: true
  validates_presence_of :type, :value, :alternate_value_object_attribute
  validates_uniqueness_of :value, scope: [:alternate_value_object, :type, :alternate_value_object_attribute, :project_id] # !! think about project/community on same object

  def self.class_name
    self.name.demodulize.underscore.humanize.downcase
  end

  def klass_name
    self.class.class_name
  end

  def self.find_for_autocomplete(params)
    where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
          "%#{params[:term]}%", params[:project_id])
  end

  # @return [Symbol]
  #   the column name containing the attribute name being annotated
  def self.annotated_attribute_column
    :alternate_value_object_attribute
  end

  def self.annotation_value_column
    :value
  end

  def type_name
    r = self.type.to_s
    ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
  end

  def type_class=(value)
    write_attribute(:type, value.to_s)
  end

  def type_class
    r = read_attribute(:type).to_s
    r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  end

end

#attribute_value_object_idInteger

the ID of the thing being annotated

Returns:

  • (Integer)


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
83
84
85
86
87
88
# File 'app/models/alternate_value.rb', line 34

class AlternateValue < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::AttributeAnnotations
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:alternate_value_object)

  belongs_to :language

  # Please DO NOT include the following:
  # validates :alternate_value_object, presence: true

  validates :language, presence: true, allow_blank: true
  validates_presence_of :type, :value, :alternate_value_object_attribute
  validates_uniqueness_of :value, scope: [:alternate_value_object, :type, :alternate_value_object_attribute, :project_id] # !! think about project/community on same object

  def self.class_name
    self.name.demodulize.underscore.humanize.downcase
  end

  def klass_name
    self.class.class_name
  end

  def self.find_for_autocomplete(params)
    where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
          "%#{params[:term]}%", params[:project_id])
  end

  # @return [Symbol]
  #   the column name containing the attribute name being annotated
  def self.annotated_attribute_column
    :alternate_value_object_attribute
  end

  def self.annotation_value_column
    :value
  end

  def type_name
    r = self.type.to_s
    ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
  end

  def type_class=(value)
    write_attribute(:type, value.to_s)
  end

  def type_class
    r = read_attribute(:type).to_s
    r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  end

end

#language_idInteger

the ID of the language used for translation

Returns:

  • (Integer)


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
83
84
85
86
87
88
# File 'app/models/alternate_value.rb', line 34

class AlternateValue < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::AttributeAnnotations
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:alternate_value_object)

  belongs_to :language

  # Please DO NOT include the following:
  # validates :alternate_value_object, presence: true

  validates :language, presence: true, allow_blank: true
  validates_presence_of :type, :value, :alternate_value_object_attribute
  validates_uniqueness_of :value, scope: [:alternate_value_object, :type, :alternate_value_object_attribute, :project_id] # !! think about project/community on same object

  def self.class_name
    self.name.demodulize.underscore.humanize.downcase
  end

  def klass_name
    self.class.class_name
  end

  def self.find_for_autocomplete(params)
    where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
          "%#{params[:term]}%", params[:project_id])
  end

  # @return [Symbol]
  #   the column name containing the attribute name being annotated
  def self.annotated_attribute_column
    :alternate_value_object_attribute
  end

  def self.annotation_value_column
    :value
  end

  def type_name
    r = self.type.to_s
    ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
  end

  def type_class=(value)
    write_attribute(:type, value.to_s)
  end

  def type_class
    r = read_attribute(:type).to_s
    r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  end

end

#project_idInteger

the project ID

Returns:

  • (Integer)


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
83
84
85
86
87
88
# File 'app/models/alternate_value.rb', line 34

class AlternateValue < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::AttributeAnnotations
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:alternate_value_object)

  belongs_to :language

  # Please DO NOT include the following:
  # validates :alternate_value_object, presence: true

  validates :language, presence: true, allow_blank: true
  validates_presence_of :type, :value, :alternate_value_object_attribute
  validates_uniqueness_of :value, scope: [:alternate_value_object, :type, :alternate_value_object_attribute, :project_id] # !! think about project/community on same object

  def self.class_name
    self.name.demodulize.underscore.humanize.downcase
  end

  def klass_name
    self.class.class_name
  end

  def self.find_for_autocomplete(params)
    where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
          "%#{params[:term]}%", params[:project_id])
  end

  # @return [Symbol]
  #   the column name containing the attribute name being annotated
  def self.annotated_attribute_column
    :alternate_value_object_attribute
  end

  def self.annotation_value_column
    :value
  end

  def type_name
    r = self.type.to_s
    ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
  end

  def type_class=(value)
    write_attribute(:type, value.to_s)
  end

  def type_class
    r = read_attribute(:type).to_s
    r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  end

end

#typeString

the annotated type

Returns:

  • (String)


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
83
84
85
86
87
88
# File 'app/models/alternate_value.rb', line 34

class AlternateValue < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::AttributeAnnotations
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:alternate_value_object)

  belongs_to :language

  # Please DO NOT include the following:
  # validates :alternate_value_object, presence: true

  validates :language, presence: true, allow_blank: true
  validates_presence_of :type, :value, :alternate_value_object_attribute
  validates_uniqueness_of :value, scope: [:alternate_value_object, :type, :alternate_value_object_attribute, :project_id] # !! think about project/community on same object

  def self.class_name
    self.name.demodulize.underscore.humanize.downcase
  end

  def klass_name
    self.class.class_name
  end

  def self.find_for_autocomplete(params)
    where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
          "%#{params[:term]}%", params[:project_id])
  end

  # @return [Symbol]
  #   the column name containing the attribute name being annotated
  def self.annotated_attribute_column
    :alternate_value_object_attribute
  end

  def self.annotation_value_column
    :value
  end

  def type_name
    r = self.type.to_s
    ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
  end

  def type_class=(value)
    write_attribute(:type, value.to_s)
  end

  def type_class
    r = read_attribute(:type).to_s
    r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  end

end

#valueString

the annotated value

Returns:

  • (String)


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
83
84
85
86
87
88
# File 'app/models/alternate_value.rb', line 34

class AlternateValue < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::AttributeAnnotations
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:alternate_value_object)

  belongs_to :language

  # Please DO NOT include the following:
  # validates :alternate_value_object, presence: true

  validates :language, presence: true, allow_blank: true
  validates_presence_of :type, :value, :alternate_value_object_attribute
  validates_uniqueness_of :value, scope: [:alternate_value_object, :type, :alternate_value_object_attribute, :project_id] # !! think about project/community on same object

  def self.class_name
    self.name.demodulize.underscore.humanize.downcase
  end

  def klass_name
    self.class.class_name
  end

  def self.find_for_autocomplete(params)
    where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
          "%#{params[:term]}%", params[:project_id])
  end

  # @return [Symbol]
  #   the column name containing the attribute name being annotated
  def self.annotated_attribute_column
    :alternate_value_object_attribute
  end

  def self.annotation_value_column
    :value
  end

  def type_name
    r = self.type.to_s
    ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
  end

  def type_class=(value)
    write_attribute(:type, value.to_s)
  end

  def type_class
    r = read_attribute(:type).to_s
    r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  end

end

Class Method Details

.annotated_attribute_columnSymbol

Returns the column name containing the attribute name being annotated

Returns:

  • (Symbol)

    the column name containing the attribute name being annotated



66
67
68
# File 'app/models/alternate_value.rb', line 66

def self.annotated_attribute_column
  :alternate_value_object_attribute
end

.annotation_value_columnObject



70
71
72
# File 'app/models/alternate_value.rb', line 70

def self.annotation_value_column
  :value
end

.class_nameObject



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

def self.class_name
  self.name.demodulize.underscore.humanize.downcase
end

.find_for_autocomplete(params) ⇒ Object



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

def self.find_for_autocomplete(params)
  where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
        "%#{params[:term]}%", params[:project_id])
end

Instance Method Details

#klass_nameObject



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

def klass_name
  self.class.class_name
end

#type_classObject



83
84
85
86
# File 'app/models/alternate_value.rb', line 83

def type_class
  r = read_attribute(:type).to_s
  r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
end

#type_class=(value) ⇒ Object



79
80
81
# File 'app/models/alternate_value.rb', line 79

def type_class=(value)
  write_attribute(:type, value.to_s)
end

#type_nameObject



74
75
76
77
# File 'app/models/alternate_value.rb', line 74

def type_name
  r = self.type.to_s
  ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
end