Class: Role
- Inherits:
-
Usman::ApplicationRecord
- Object
- ActiveRecord::Base
- Usman::ApplicationRecord
- Role
- Extended by:
- Usman::ImportErrorHandler
- Defined in:
- app/models/role.rb
Class Method Summary collapse
Instance Method Summary collapse
- #can_be_deleted? ⇒ Boolean
- #can_be_edited? ⇒ Boolean
-
#display_name ⇒ Object
-
Return full name == Examples >>> role.display_name => “Products”.
-
Methods included from Usman::ImportErrorHandler
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..to_sentence}" error_object.errors << { summary: summary, details: details } end return error_object end |
Instance Method Details
#can_be_deleted? ⇒ 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
54 55 56 |
# File 'app/models/role.rb', line 54 def can_be_edited? true end |
#display_name ⇒ Object
-
Return full name
Examples
>>> role.display_name
=> "Products"
50 51 52 |
# File 'app/models/role.rb', line 50 def display_name "#{name}" end |