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


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

def changes
  @changes ||= saved_changes
end

#generate_substitution_hashObject


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

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

#original_tag2_idObject


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

def original_tag2_id
  changes[:tag2_id].first
end

#original_tag_idObject


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

def original_tag_id
  changes[:tag_id].first
end

#other_attributes_for_substitutionObject


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

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

#substitute_tag2_idObject


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

def substitute_tag2_id
  changes[:tag2_id].last
end

#substitute_tag_idObject


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

def substitute_tag_id
  changes[:tag_id].last
end

#substitution_hashObject


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

def substitution_hash
  return if id_previously_changed?

  generate_substitution_hash if saved_changes?
end

#tag2_id_substitutionObject


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

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


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

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

  { original_tag_id: original_tag_id,
    substitute_tag_id: substitute_tag_id }
end