Class: Aker::GroupMemberships
- Inherits:
-
Array
- Object
- Array
- Aker::GroupMemberships
- Defined in:
- lib/aker/group_membership.rb
Overview
An authority-independent collection of all the group memberships for a particular user at a particular portal.
Instance Attribute Summary collapse
-
#portal ⇒ Symbol
readonly
The portal for which all these group memberships apply.
Instance Method Summary collapse
-
#find(group, *affiliate_ids) ⇒ Array<GroupMembership>
Finds the group memberships that match the given group, possibly constrained by one or more affiliates.
-
#include?(group, *affiliate_ids) ⇒ Boolean
Determines whether this collection indicates that the user is authorized in the the given group, possibly constrained by one or more affiliates.
-
#initialize(portal) ⇒ GroupMemberships
constructor
Create a new instance.
-
#marshal_dump ⇒ Hash
Custom serialization for this array.
-
#marshal_load(dump) ⇒ void
Custom deserialization for this array.
Constructor Details
#initialize(portal) ⇒ GroupMemberships
Create a new instance.
73 74 75 |
# File 'lib/aker/group_membership.rb', line 73 def initialize(portal) @portal = portal.to_sym end |
Instance Attribute Details
#portal ⇒ Symbol (readonly)
The portal for which all these group memberships apply.
64 65 66 |
# File 'lib/aker/group_membership.rb', line 64 def portal @portal end |
Instance Method Details
#find(group, *affiliate_ids) ⇒ Array<GroupMembership>
Finds the group memberships that match the given group, possibly constrained by one or more affiliates.
(Note that this method hides the ‘Enumerable` method `find`. You can still use it under its `detect` alias.)
108 109 110 111 112 |
# File 'lib/aker/group_membership.rb', line 108 def find(group, *affiliate_ids) candidates = self.select { |gm| gm.group.include?(group) } return candidates if affiliate_ids.empty? candidates.select { |gm| affiliate_ids.detect { |id| gm.include_affiliate?(id) } } end |
#include?(group, *affiliate_ids) ⇒ Boolean
Determines whether this collection indicates that the user is authorized in the the given group, possibly constrained by one or more affiliates.
(Note that this method hides the superclass ‘include?` method.)
92 93 94 |
# File 'lib/aker/group_membership.rb', line 92 def include?(group, *affiliate_ids) !find(group, *affiliate_ids).empty? end |
#marshal_dump ⇒ Hash
121 122 123 124 125 126 127 |
# File 'lib/aker/group_membership.rb', line 121 def marshal_dump { :group_roots => find_group_roots, :memberships => dump_gm_hashes, :portal => portal } end |
#marshal_load(dump) ⇒ void
This method returns an undefined value.
Custom deserialization for this array. Reverses #marshal_dump.
134 135 136 137 138 139 140 141 |
# File 'lib/aker/group_membership.rb', line 134 def marshal_load(dump) @portal = dump[:portal] roots = dump[:group_roots] dump[:memberships].each do |gm_hash| self << GroupMembership.new(find_group_from_roots(gm_hash[:group_name], roots)). tap { |gm| gm.affiliate_ids.concat(gm_hash[:affiliate_ids]) } end end |