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


54
55
56
# File 'app/models/aliquot/data_for_substitution.rb', line 54

def changes
  @changes ||= saved_changes
end

#generate_substitution_hashObject


13
14
15
16
17
18
# 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


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

def original_tag2_id
  changes[:tag2_id].first
end

#original_tag_idObject


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

def original_tag_id
  changes[:tag_id].first
end

#other_attributes_for_substitutionObject


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

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

#substitute_tag2_idObject


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

def substitute_tag2_id
  changes[:tag2_id].last
end

#substitute_tag_idObject


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

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


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

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


20
21
22
23
24
25
# File 'app/models/aliquot/data_for_substitution.rb', line 20

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

  { original_tag_id: original_tag_id,
    substitute_tag_id: substitute_tag_id }
end