Module: Sunrise::Models::User
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #admin? ⇒ Boolean
- #default? ⇒ Boolean
- #events_for_current_state ⇒ Object
- #has_login? ⇒ Boolean
- #has_role?(role_name) ⇒ Boolean
- #moderator? ⇒ Boolean
- #role_empty? ⇒ Boolean
- #role_symbol ⇒ Object
- #role_symbols ⇒ Object
- #state ⇒ Object
Instance Method Details
#admin? ⇒ Boolean
56 57 58 |
# File 'lib/sunrise/models/user.rb', line 56 def admin? has_role?(:admin) end |
#default? ⇒ Boolean
48 49 50 |
# File 'lib/sunrise/models/user.rb', line 48 def default? has_role?(:default) end |
#events_for_current_state ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/sunrise/models/user.rb', line 87 def events_for_current_state events = [] events << 'activate' unless confirmed? events << 'unlock' if access_locked? # TODO: ban access for active users # events << 'suspend' if active_for_authentication? events end |
#has_login? ⇒ Boolean
68 69 70 |
# File 'lib/sunrise/models/user.rb', line 68 def has_login? respond_to?(:login) end |
#has_role?(role_name) ⇒ Boolean
60 61 62 |
# File 'lib/sunrise/models/user.rb', line 60 def has_role?(role_name) role_symbols.include?(role_name.to_sym) end |
#moderator? ⇒ Boolean
52 53 54 |
# File 'lib/sunrise/models/user.rb', line 52 def moderator? has_role?(:moderator) end |
#role_empty? ⇒ Boolean
64 65 66 |
# File 'lib/sunrise/models/user.rb', line 64 def role_empty? self.role_type_id.nil? end |
#role_symbol ⇒ Object
76 77 78 |
# File 'lib/sunrise/models/user.rb', line 76 def role_symbol role_symbols.first end |
#role_symbols ⇒ Object
72 73 74 |
# File 'lib/sunrise/models/user.rb', line 72 def role_symbols [role_type.try(:code)] end |
#state ⇒ Object
80 81 82 83 84 85 |
# File 'lib/sunrise/models/user.rb', line 80 def state return 'active' if active_for_authentication? return 'register' unless confirmed? return 'suspend' if access_locked? return 'pending' end |