Class: ObservationMatrixColumnItem

Inherits:
ActiveRecord::Base
  • Object
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?

Class Method Details

+ (Object) human_name



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

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

+ (Array) subclass_attributes

override

Returns:

  • (Array)

    the required attributes for this subclass



62
63
64
# File 'app/models/observation_matrix_column_item.rb', line 62

def self.subclass_attributes
  []
end

Instance Method Details

- (Object) cleanup_matrix_columns



26
27
28
29
30
31
# File 'app/models/observation_matrix_column_item.rb', line 26

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)



39
40
41
42
43
44
45
46
47
48
# File 'app/models/observation_matrix_column_item.rb', line 39

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



69
70
71
# File 'app/models/observation_matrix_column_item.rb', line 69

def descriptors
  false    
end

- (Object) other_subclass_attributes_not_set (protected)



75
76
77
78
79
# File 'app/models/observation_matrix_column_item.rb', line 75

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)



81
82
83
84
85
# File 'app/models/observation_matrix_column_item.rb', line 81

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



33
34
35
36
37
# File 'app/models/observation_matrix_column_item.rb', line 33

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

- (Object) update_single_matrix_column(descriptor)



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

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