Module: Aliquot::DataForSubstitution

Included in:
Aliquot
Defined in:
app/models/aliquot/data_for_substitution.rb

Overview

This module is used to create a substitution hash to be used in TagSubstitution library after an aliquot is updated (saved), it uses aliquot.saved_changes to create substitution hash substitution hash is then used by TagSubstitution to find similar aliquots and update them

Instance Method Summary collapse

Instance Method Details

#changesObject


49
50
51
# File 'app/models/aliquot/data_for_substitution.rb', line 49

def changes
  @changes ||= saved_changes
end

#generate_substitution_hashObject


13
14
15
# File 'app/models/aliquot/data_for_substitution.rb', line 13

def generate_substitution_hash
  aliquot_identifiers.merge(tag_id_substitution).merge(tag2_id_substitution).merge(other_attributes_for_substitution)
end

#original_tag2_idObject


37
38
39
# File 'app/models/aliquot/data_for_substitution.rb', line 37

def original_tag2_id
  changes[:tag2_id].first
end

#original_tag_idObject


29
30
31
# File 'app/models/aliquot/data_for_substitution.rb', line 29

def original_tag_id
  changes[:tag_id].first
end

#other_attributes_for_substitutionObject


45
46
47
# File 'app/models/aliquot/data_for_substitution.rb', line 45

def other_attributes_for_substitution
  changes.transform_values(&:last).except(:updated_at, :tag_id, :tag2_id)
end

#substitute_tag2_idObject


41
42
43
# File 'app/models/aliquot/data_for_substitution.rb', line 41

def substitute_tag2_id
  changes[:tag2_id].last
end

#substitute_tag_idObject


33
34
35
# File 'app/models/aliquot/data_for_substitution.rb', line 33

def substitute_tag_id
  changes[:tag_id].last
end

#substitution_hashObject


7
8
9
10
11
# File 'app/models/aliquot/data_for_substitution.rb', line 7

def substitution_hash
  return if id_previously_changed?

  generate_substitution_hash if saved_changes?
end

#tag2_id_substitutionObject


23
24
25
26
27
# File 'app/models/aliquot/data_for_substitution.rb', line 23

def tag2_id_substitution
  return {} if changes[:tag2_id].blank?

  { original_tag2_id: original_tag2_id, substitute_tag2_id: substitute_tag2_id }
end

#tag_id_substitutionObject


17
18
19
20
21
# File 'app/models/aliquot/data_for_substitution.rb', line 17

def tag_id_substitution
  return {} if changes[:tag_id].blank?

  { original_tag_id: original_tag_id, substitute_tag_id: substitute_tag_id }
end