Method: Role.save_row_data

Defined in:
app/models/role.rb

.save_row_data(hsh) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/role.rb', line 21

def self.save_row_data(hsh)

  return if hsh[:name].blank?

  role = Role.find_by_name(hsh[:name]) || Role.new
  role.name = hsh[:name]
  
  # Initializing error hash for displaying all errors altogether
  error_object = Kuppayam::Importer::ErrorHash.new

  if role.valid?
    begin
      role.save!
    rescue Exception => e
      summary = "uncaught #{e} exception while handling connection: #{e.message}"
      details = "Stack trace: #{e.backtrace.map {|l| "  #{l}\n"}.join}"
      error_object.errors << { summary: summary, details: details }        
    end
  else
    summary = "Error while saving role: #{role.name}"
    details = "Error! #{role.errors.full_messages.to_sentence}"
    error_object.errors << { summary: summary, details: details }
  end
  return error_object
end