Class: Role

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Usman::ImportErrorHandler

import_from_csv

Class Method Details

.save_row_data(row, base_path) ⇒ Object



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

def self.save_row_data(row, base_path)

  row.headers.each{ |cell| row[cell] = row[cell].to_s.strip }

  return if row[:name].blank?

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

  if role.valid?
    role.save!
  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)


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

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

#can_be_edited?Boolean

Returns:

  • (Boolean)


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

def can_be_edited?
  true
end

#display_nameObject

  • Return full name

Examples

>>> role.display_name
=> "Products"


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

def display_name
  "#{name}"
end