Class: Scrivito::MembershipCollection
- Inherits:
-
Object
- Object
- Scrivito::MembershipCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/scrivito/membership_collection.rb
Overview
The MembershipCollection includes all members of a given Workspace. You can access it using Workspace#memberships method.
Instance Method Summary collapse
-
#[](id_or_user) ⇒ Membership?
Returns the membership for a user or nil.
-
#each {|Membership| ... } ⇒ Enumerator
Iterate over all Memberships of a specfic Workspace.
-
#to_h ⇒ Hash<String, Membership>
return a hash where the keys are user_ids and the values are Membership-Instances.
Instance Method Details
#[](id_or_user) ⇒ Membership?
Returns the membership for a user or nil
57 58 59 60 61 62 63 64 65 |
# File 'lib/scrivito/membership_collection.rb', line 57 def [](id_or_user) id = if id_or_user.respond_to?(:id) id_or_user.id else id_or_user end to_h[id] end |
#each {|Membership| ... } ⇒ Enumerator
Note:
For a complete list of all provided methods please view the documentation of the Enumerable module
Iterate over all Memberships of a specfic Workspace. Allows you to use all methods defined by ruby’s Enumerable module.
36 |
# File 'lib/scrivito/membership_collection.rb', line 36 def_delegator :memberships, :each |
#to_h ⇒ Hash<String, Membership>
return a hash where the keys are user_ids and the values are Membership-Instances
45 46 47 48 49 50 |
# File 'lib/scrivito/membership_collection.rb', line 45 def to_h memberships.inject(HashWithIndifferentAccess.new) do |hash, membership| hash[membership.user_id] = membership hash end end |