Class: Role
- Inherits:
-
Usman::ApplicationRecord
- Object
- ActiveRecord::Base
- Usman::ApplicationRecord
- Role
- 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”.
-
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.}" 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..to_sentence}" error_object.errors << { summary: summary, details: details } end return error_object end |
Instance Method Details
#can_be_deleted? ⇒ 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
55 56 57 |
# File 'app/models/role.rb', line 55 def can_be_edited? true end |
#display_name ⇒ Object
-
Return full name
Examples
>>> role.display_name
=> "Products"
51 52 53 |
# File 'app/models/role.rb', line 51 def display_name "#{name}" end |