Class: Waylon::Group
- Inherits:
-
Object
- Object
- Waylon::Group
- Defined in:
- lib/waylon/group.rb
Overview
Note:
This class can be subclassed for external authentication mechanisms per Sense
The basic, built-in Group class. Relies on Redis for storage and is managed directly by Waylon.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#add(user) ⇒ Boolean
Add a user to the group.
-
#include?(user) ⇒ Boolean
Checks if a user a member.
-
#initialize(name) ⇒ Group
constructor
A new instance of Group.
-
#members ⇒ Array<User>
(also: #to_a)
Waylon Users in this group.
-
#remove(user) ⇒ Boolean
Remove a user from the group.
Constructor Details
#initialize(name) ⇒ Group
Returns a new instance of Group.
10 11 12 |
# File 'lib/waylon/group.rb', line 10 def initialize(name) @name = name.to_sym end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/waylon/group.rb', line 7 def name @name end |
Instance Method Details
#add(user) ⇒ Boolean
Add a user to the group
17 18 19 20 21 22 23 24 |
# File 'lib/waylon/group.rb', line 17 def add(user) return false if include?(user) users = members users << user.email.downcase storage.store(key, users) true end |
#include?(user) ⇒ Boolean
Checks if a user a member
52 53 54 |
# File 'lib/waylon/group.rb', line 52 def include?(user) members.include?(user.email.downcase) end |
#members ⇒ Array<User> Also known as: to_a
Waylon Users in this group
40 41 42 43 44 45 |
# File 'lib/waylon/group.rb', line 40 def members # all actions on Group funnel through here, so always make sure the key exists first storage.store(key, []) unless storage.key?(key) storage.load(key).sort.uniq end |
#remove(user) ⇒ Boolean
Remove a user from the group
29 30 31 32 33 34 35 36 |
# File 'lib/waylon/group.rb', line 29 def remove(user) return false unless include?(user) users = members users.delete(user.email.downcase) storage.store(key, users) true end |