Class: ObservationMatrixColumnItem

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::Identifiable, Shared::IsData, Shared::Notable, Shared::Taggable
Defined in:
app/models/observation_matrix_column_item.rb

Overview

Each ObservationMatrixColumnItem is set of descriptors

Direct Known Subclasses

SingleDescriptor, TaggedDescriptor

Defined Under Namespace

Classes: SingleDescriptor, TaggedDescriptor

Constant Summary

ALL_STI_ATTRIBUTES =
[:descriptor_id, :controlled_vocabulary_term_id]

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Class Method Details

+ (Object) human_name



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

def self.human_name
  self.name.demodulize.humanize
end

+ (Array) subclass_attributes

override

Returns:

  • (Array)

    the required attributes for this subclass



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

def self.subclass_attributes
  []
end

Instance Method Details

- (Object) cleanup_matrix_columns



30
31
32
33
34
35
# File 'app/models/observation_matrix_column_item.rb', line 30

def cleanup_matrix_columns
  ObservationMatrixColumn.where(descriptor_id: descriptors.map(&:id), observation_matrix: observation_matrix).each do |mc|
    cleanup_single_matrix_column mc.descriptor_id, mc
  end
  true
end

- (Object) cleanup_single_matrix_column(descriptor_id, mc = nil)



43
44
45
46
47
48
49
50
51
52
# File 'app/models/observation_matrix_column_item.rb', line 43

def cleanup_single_matrix_column(descriptor_id, mc = nil)
  mc ||= ObservationMatrixColumn.where(descriptor_id: descriptor_id, observation_matrix: observation_matrix).first

  current = mc.reference_count - 1
  if current == 0
    mc.delete
  else
    mc.update_columns(reference_count: current)
  end
end

- (Array) descriptors

override

Returns:

  • (Array)

    the descriptors “defined” by this matrix column item



73
74
75
# File 'app/models/observation_matrix_column_item.rb', line 73

def descriptors
  false
end

- (Object) other_subclass_attributes_not_set (protected)



79
80
81
82
83
# File 'app/models/observation_matrix_column_item.rb', line 79

def other_subclass_attributes_not_set
  (ALL_STI_ATTRIBUTES - self.class.subclass_attributes).each do |atr|
    errors.add(atr, 'is not valid for this type of observation matrix column item') if !send(atr).blank?
  end
end

- (Object) type_is_subclassed (protected)



85
86
87
88
89
# File 'app/models/observation_matrix_column_item.rb', line 85

def type_is_subclassed
  if !MATRIX_COLUMN_ITEM_TYPES[type]
    errors.add(:type, 'type must be a valid subclass')
  end
end

- (Object) update_matrix_columns



37
38
39
40
41
# File 'app/models/observation_matrix_column_item.rb', line 37

def update_matrix_columns
  descriptors.each do |d|
    update_single_matrix_column d
  end
end

- (Object) update_single_matrix_column(descriptor)



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

def update_single_matrix_column(descriptor)
  mc = ObservationMatrixColumn.find_or_create_by(observation_matrix: observation_matrix, descriptor: descriptor)
  mc.update_columns(reference_count: mc.reference_count + 1)
end