Module: Shared::AttributeAnnotations

Extended by:
ActiveSupport::Concern
Included in:
AlternateValue, Note, Tag
Defined in:
app/models/concerns/shared/attribute_annotations.rb

Overview

Shared code for polymorphics that reference specific attributes

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary (collapse)

Instance Method Details

- (String) annotated_column

Returns:

  • (String)


17
18
19
# File 'app/models/concerns/shared/attribute_annotations.rb', line 17

def annotated_column
  self.send(self.class.annotated_attribute_column)
end

- (Object) annotated_value_is_not_identical_to_attribute (protected)



40
41
42
# File 'app/models/concerns/shared/attribute_annotations.rb', line 40

def annotated_value_is_not_identical_to_attribute
  errors.add(self.class.annotated_attribute_column, 'contains annotation identical to existing attribute') if annotation_value == original_value
end

- (Object) annotation_value



21
22
23
# File 'app/models/concerns/shared/attribute_annotations.rb', line 21

def annotation_value
  self.send(self.class.annotation_value_column)
end

- (Object) attribute_to_annotate_is_valid_for_object (protected)

Tests presence of original value AND legality of attribute being annotated



32
33
34
35
36
37
38
# File 'app/models/concerns/shared/attribute_annotations.rb', line 32

def attribute_to_annotate_is_valid_for_object
  if annotated_object
    if !ApplicationEnumeration.annotatable_attributes(annotated_object).include?(annotated_column.to_sym)
      errors.add(self.class.annotated_attribute_column, "#{annotated_column} is not annotatable, it may be empty or non-annotatable")
    end
  end
end

- (Object) original_value



25
26
27
# File 'app/models/concerns/shared/attribute_annotations.rb', line 25

def original_value
  annotated_object.send(annotated_column) if annotated_object.respond_to?(annotated_column)
end