Commit 9e1f8ac2 authored by James Lopez's avatar James Lopez

refactored code

parent e5f91e52
...@@ -56,8 +56,7 @@ module Gitlab ...@@ -56,8 +56,7 @@ module Gitlab
if relation.is_a?(Hash) if relation.is_a?(Hash)
create_sub_relations(relation, @tree_hash) create_sub_relations(relation, @tree_hash)
elsif @tree_hash[relation.to_s].present? elsif @tree_hash[relation.to_s].present?
relation_key = relation.is_a?(Hash) ? relation.keys.first : relation save_relation_hash(@tree_hash[relation.to_s], relation)
save_relation_hash(@tree_hash[relation_key.to_s], relation_key)
end end
end end
...@@ -101,7 +100,7 @@ module Gitlab ...@@ -101,7 +100,7 @@ module Gitlab
# issue, finds any subrelations such as notes, creates them and assign them back to the hash # issue, finds any subrelations such as notes, creates them and assign them back to the hash
# #
# Recursively calls this method if the sub-relation is a hash containing more sub-relations # Recursively calls this method if the sub-relation is a hash containing more sub-relations
def create_sub_relations(relation, tree_hash, save = true) def create_sub_relations(relation, tree_hash, save: true)
relation_key = relation.keys.first.to_s relation_key = relation.keys.first.to_s
return if tree_hash[relation_key].blank? return if tree_hash[relation_key].blank?
...@@ -133,7 +132,7 @@ module Gitlab ...@@ -133,7 +132,7 @@ module Gitlab
# We just use author to get the user ID, do not attempt to create an instance. # We just use author to get the user ID, do not attempt to create an instance.
next if sub_relation == :author next if sub_relation == :author
create_sub_relations(sub_relation, relation_item, false) if sub_relation.is_a?(Hash) create_sub_relations(sub_relation, relation_item, save: false) if sub_relation.is_a?(Hash)
relation_hash, sub_relation = assign_relation_hash(relation_item, sub_relation) relation_hash, sub_relation = assign_relation_hash(relation_item, sub_relation)
relation_item[sub_relation.to_s] = create_relation(sub_relation, relation_hash) unless relation_hash.blank? relation_item[sub_relation.to_s] = create_relation(sub_relation, relation_hash) unless relation_hash.blank?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment