lib/scrivito/membership_collection.rb in scrivito_sdk-0.66.0 vs lib/scrivito/membership_collection.rb in scrivito_sdk-0.70.0.rc1
- old
+ new
@@ -1,57 +1,57 @@
module Scrivito
# @api public
# The MembershipCollection includes all members of a given {Workspace}.
- # You can access it using {Workspace#memberships} method.
+ # You can access it using the {Workspace#memberships} method.
class MembershipCollection
extend Forwardable
include Enumerable
attr_reader :workspace
# @api public
# @!method each
# Iterate over all {Membership Memberships} of a specific {Workspace}. Allows
- # you to use all methods defined by ruby's Enumerable module.
+ # you to use all the methods defined by Ruby's Enumerable module.
#
# @yield [Membership]
#
- # @return [Enumerator] if no block is given an Enumerator is returned
+ # @return [Enumerator] if no block is given, an Enumerator is returned
#
# @example
- # # Obtain all owners of a workspace
+ # # Obtain all owners of a workspace.
# my_workspace.memberships.select do |membership|
# membership.role == "owner"
# end
#
- # # Get an array of all the members' user_ids
+ # # Get an array of all the members' user_ids.
# my_workspace.memberships.map { |membership| membership.user_id }
#
- # # Or use it directly to iterate over all items
+ # # Or use it directly to iterate over all items.
# my_workspace.memberships.each do |membership|
# puts "User #{membership.user_id} has the role #{membership.role}"
# end
#
- # @note For a complete list of all provided methods please view the
- # documentation of the Enumerable module
+ # @note For a complete list of the provided methods, please refer to the
+ # documentation of the Enumerable module.
def_delegator :memberships, :each
def initialize(workspace)
@workspace = workspace
end
# @api public
- # return a hash where the keys are user_ids and the values are Membership-Instances
+ # Returns a hash where the keys are +user_id+s and the values are Membership instances.
# @return [Hash<String, Membership>]
def to_h
memberships.inject(HashWithIndifferentAccess.new) do |hash, membership|
hash[membership.user_id] = membership
hash
end
end
# @api public
- # Returns the membership for a user or nil
+ # Returns the membership of a user or nil.
#
# @param [User, String] id_or_user
# @return [Membership, nil]
def [](id_or_user)
id = if id_or_user.respond_to?(:id)