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

Direct Known Subclasses

Abbreviation, AlternateSpelling, Misspelling, Translation

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?

Methods included from ActiverecordUtilities

#trim_attributes

Instance Attribute Details

- (String) alternate_value_object_attribute

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

Returns:

  • (String)

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



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

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

  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
end

- (String) alternate_value_object_type

the kind of thing being annotated

Returns:

  • (String)


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

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

  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
end

- (Integer) attribute_value_object_id

the ID of the thing being annotated

Returns:

  • (Integer)


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

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

  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
end

- (Integer) language_id

the ID of the language used for translation

Returns:

  • (Integer)


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

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

  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
end

- (Integer) project_id

the project ID

Returns:

  • (Integer)


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

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

  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
end

- (String) type

the annotated type

Returns:

  • (String)


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

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

  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
end

- (String) value

the annotated value

Returns:

  • (String)


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

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

  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
end

Class Method Details

+ (Symbol) annotated_attribute_column

Returns the column name containing the attribute name being annotated

Returns:

  • (Symbol)

    the column name containing the attribute name being annotated



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

def self.annotated_attribute_column
  :alternate_value_object_attribute
end

+ (Object) annotation_value_column



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

def self.annotation_value_column
  :value
end

+ (Object) class_name



63
64
65
# File 'app/models/alternate_value.rb', line 63

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

+ (Object) find_for_autocomplete(params)



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

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

- (Object) klass_name



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

def klass_name
  self.class.class_name
end

- (Object) type_class



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

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

- (Object) type_class=(value)



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

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

- (Object) type_name



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

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