Class: Role

Inherits:
Usman::ApplicationRecord show all
Defined in:
app/models/role.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.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

Instance Method Details

#can_be_deleted?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/models/role.rb', line 59

def can_be_deleted?
  self.users.count > 0 ? false : true
end

#can_be_edited?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/role.rb', line 55

def can_be_edited?
  true
end

#display_nameObject

  • Return full name

Examples

>>> role.display_name
=> "Products"


51
52
53
# File 'app/models/role.rb', line 51

def display_name
  "#{name}"
end