module Scrivito # @api public # Represents a Membership of a {User} in a {Workspace} class Membership # @api public # The {User User's} id # # @return [String] attr_reader :user_id # @api public # The role associated with this membership. # # @note Currently the only available role is "owner". # # @return [String] the name of role attr_reader :role def initialize(user_id, data) @user_id = user_id @role = data.fetch("role") end # Fetches and returns the {User} with the id {Membership#user_id}. # Uses the proc set in {Configuration.find_user} to fetch the user. # @api public # @return The value returned by the proc set in {Configuration.find_user}. # @return An unknown user if no proc is set in {Configuration.find_user} or the proc returns a # falsy value. The unknown user will have the id of the original user and no abilities. # @see Scrivito::Configuration.find_user def user User.find(user_id) || User.unknown_user(user_id) end end end