Module: Tag::MatrixHooks
Instance Method Summary collapse
- #dynamic_tag_column_items ⇒ Object protected
- #dynamic_tag_row_items ⇒ Object protected
- #in_scope_observation_matrix_column_items ⇒ Object
-
#in_scope_observation_matrix_row_items ⇒ Object
MatrixColumn/RowItem interface _change methods use the array to see how the record was updated new -> [nil, 1] change -> [1, 2].
-
#increment_matrix_counts ⇒ Object
protected
This is a dynamic check.
-
#move_in_matrices ⇒ Object
protected
Decrement the previous tag_object's dynamic row/column, increment the new tag_object's.
- #out_of_scope_observation_matrix_column_items ⇒ Object
- #out_of_scope_observation_matrix_row_items ⇒ Object
- #purge_from_matrices ⇒ Object protected
-
#release_from_matrices(type, id) ⇒ Object
protected
Decrement the dynamic row/column of the object of this type and id.
Instance Method Details
#dynamic_tag_column_items ⇒ Object (protected)
103 104 105 106 107 |
# File 'app/models/tag/matrix_hooks.rb', line 103 def dynamic_tag_column_items ObservationMatrixColumnItem::Dynamic::Tag.where( controlled_vocabulary_term_id: keyword_id ) end |
#dynamic_tag_row_items ⇒ Object (protected)
96 97 98 99 100 101 |
# File 'app/models/tag/matrix_hooks.rb', line 96 def dynamic_tag_row_items ObservationMatrixRowItem::Dynamic::Tag.where( observation_object_type: 'ControlledVocabularyTerm', observation_object_id: keyword_id ) end |
#in_scope_observation_matrix_column_items ⇒ Object
39 40 41 42 |
# File 'app/models/tag/matrix_hooks.rb', line 39 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_items ⇒ Object
MatrixColumn/RowItem interface
_change methods use the array to see how the record was updated new -> [nil, 1] change -> [1, 2]
29 30 31 32 |
# File 'app/models/tag/matrix_hooks.rb', line 29 def in_scope_observation_matrix_row_items return [] unless keyword_id_changed? ObservationMatrixRowItem::Dynamic::Tag.where(observation_object_type: 'ControlledVocabularyTerm', observation_object_id: keyword_id_change.last) end |
#increment_matrix_counts ⇒ Object (protected)
This is a dynamic check. For all row items that reference this keyword, increment the reference of just that object.
90 91 92 93 94 |
# File 'app/models/tag/matrix_hooks.rb', line 90 def increment_matrix_counts dynamic_tag_row_items.each do |mri| mri.update_single_matrix_row(tag_object) end end |
#move_in_matrices ⇒ Object (protected)
Decrement the previous tag_object's dynamic row/column, increment the new tag_object's.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/tag/matrix_hooks.rb', line 57 def move_in_matrices release_from_matrices( tag_object_type_before_last_save, tag_object_id_before_last_save ) case tag_object_type when 'Descriptor' dynamic_tag_column_items.each do |mci| mci.update_single_matrix_column(tag_object) end when 'Otu', 'CollectionObject', 'Extract' increment_matrix_counts end end |
#out_of_scope_observation_matrix_column_items ⇒ Object
44 45 46 47 |
# File 'app/models/tag/matrix_hooks.rb', line 44 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_items ⇒ Object
34 35 36 37 |
# File 'app/models/tag/matrix_hooks.rb', line 34 def out_of_scope_observation_matrix_row_items return [] unless keyword_id_changed? && keyword_id_change.first ObservationMatrixRowItem::Dynamic::Tag.where(observation_object_type: 'ControlledVocabularyTerm', observation_object_id: keyword_id_change.first) end |
#purge_from_matrices ⇒ Object (protected)
51 52 53 |
# File 'app/models/tag/matrix_hooks.rb', line 51 def purge_from_matrices release_from_matrices(tag_object_type, tag_object_id) end |
#release_from_matrices(type, id) ⇒ Object (protected)
Decrement the dynamic row/column of the object of this type and id
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/tag/matrix_hooks.rb', line 73 def release_from_matrices(type, id) case type when 'Descriptor' dynamic_tag_column_items.each do |mci| mci.cleanup_single_matrix_column(id) # a descriptor_id end when 'Otu', 'CollectionObject', 'Extract' dynamic_tag_row_items.each do |mri| mri.cleanup_single_matrix_row_for(type, id) end else true end end |