Improved code layout.
This commit is contained in:
parent
6e6b7fe5a6
commit
a286b9e17e
1 changed files with 5 additions and 13 deletions
|
@ -340,25 +340,17 @@ 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]
|
||||
records = where( name: data[:name] )
|
||||
records.each {|loop_record|
|
||||
return loop_record if loop_record.name == data[:name]
|
||||
}
|
||||
record = find_by( name: data[:name] )
|
||||
elsif data[:login]
|
||||
records = where( login: data[:login] )
|
||||
records.each {|loop_record|
|
||||
return loop_record if loop_record.login == data[:login]
|
||||
}
|
||||
record = find_by( login: data[:login] )
|
||||
elsif data[:locale] && data[:source]
|
||||
records = where( locale: data[:locale], source: data[:source] )
|
||||
records.each {|loop_record|
|
||||
return loop_record if loop_record.source == data[:source]
|
||||
}
|
||||
record = find_by( locale: data[:locale], source: data[:source] )
|
||||
end
|
||||
return record if record
|
||||
create(data)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue