From ed59645cd8cc6fb1543d3c5d69cd0a70f8cbbcf6 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 27 Jul 2015 20:42:52 +0200 Subject: [PATCH] Revert "Improved code layout." This reverts commit a286b9e17ec18dc42b7ffadee14636b20700c732. --- app/models/application_model.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 14c912fd4..f5e4fd9c6 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -340,17 +340,25 @@ returns =end def self.create_if_not_exists(data) - record = nil if data[:id] record = find_by( id: data[:id] ) + return record if record elsif data[:name] - record = find_by( name: data[:name] ) + records = where( name: data[:name] ) + records.each {|loop_record| + return loop_record if loop_record.name == data[:name] + } elsif data[:login] - record = find_by( login: data[:login] ) + records = where( login: data[:login] ) + records.each {|loop_record| + return loop_record if loop_record.login == data[:login] + } elsif data[:locale] && data[:source] - record = find_by( locale: data[:locale], source: data[:source] ) + records = where( locale: data[:locale], source: data[:source] ) + records.each {|loop_record| + return loop_record if loop_record.source == data[:source] + } end - return record if record create(data) end