Module: Tag::MatrixHooks

Extended by:
ActiveSupport::Concern
Included in:
Tag
Defined in:
app/models/tag/matrix_hooks.rb

Instance Method Summary collapse

Instance Method Details

#in_scope_observation_matrix_column_itemsObject



32
33
34
35
# File 'app/models/tag/matrix_hooks.rb', line 32

def in_scope_observation_matrix_column_items
  return [] unless keyword_id_changed?
  ObservationMatrixColumnItem::Dynamic::Tag.where(controlled_vocabulary_term_id: keyword_id_change.last)
end

#in_scope_observation_matrix_row_itemsObject

MatrixColumn/RowItem interface

_change methods use the array to see how the record was updated new -> [nil, 1] change -> [1, 2]



22
23
24
25
# File 'app/models/tag/matrix_hooks.rb', line 22

def in_scope_observation_matrix_row_items
  return [] unless keyword_id_changed?
  ObservationMatrixRowItem::Dynamic::Tag.where(controlled_vocabulary_term_id: keyword_id_change.last)
end

#increment_matrix_countsObject (protected)

This is a dynamic check. For all row items that reference this keyword, increment the reference of just that object.



61
62
63
64
65
# File 'app/models/tag/matrix_hooks.rb', line 61

def increment_matrix_counts
  ObservationMatrixRowItem::Dynamic::Tag.where(controlled_vocabulary_term_id: keyword_id).each do |mri|
    mri.update_single_matrix_row(tag_object)
  end
end

#out_of_scope_observation_matrix_column_itemsObject



37
38
39
40
# File 'app/models/tag/matrix_hooks.rb', line 37

def out_of_scope_observation_matrix_column_items
  return [] unless keyword_id_changed? && keyword_id_change.first
  ObservationMatrixColumnItem::Dynamic::Tag.where(controlled_vocabulary_term_id: keyword_id_change.first)
end

#out_of_scope_observation_matrix_row_itemsObject



27
28
29
30
# File 'app/models/tag/matrix_hooks.rb', line 27

def out_of_scope_observation_matrix_row_items
  return [] unless keyword_id_changed? && keyword_id_change.first
  ObservationMatrixRowItem::Dynamic::Tag.where(controlled_vocabulary_term_id: keyword_id_change.first)
end

#purge_from_matricesObject (protected)



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/tag/matrix_hooks.rb', line 44

def purge_from_matrices
  case tag_object_type 
  when 'Descriptor'
    ObservationMatrixColumnItem::Dynamic::Tag.where(controlled_vocabulary_term_id: keyword_id).each do |mci|
      mci.cleanup_single_matrix_column(tag_object_id) # a descriptor_id
    end
  when 'Otu', 'CollectionObject'
    ObservationMatrixRowItem::Dynamic::Tag.where(controlled_vocabulary_term_id: keyword_id).each do |mri|
      mri.cleanup_single_matrix_row(tag_object)
    end
  else
    true
  end 
end