You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: AWS::IAM::UserGroupCollection

Inherits:
Object
  • Object
show all
Includes:
Collection
Defined in:
lib/aws/iam/user_group_collection.rb

Overview

A collection that provides access to IAM groups to which a particular user belongs.

user = AWS::IAM.new.users.first
groups = user.groups
groups.each { |g| puts g.name }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Core::Collection

#each_batch, #enum, #first, #in_groups_of, #page

Instance Attribute Details

#userObject (readonly)



29
30
31
# File 'lib/aws/iam/user_group_collection.rb', line 29

def user
  @user
end

Instance Method Details

#add(group) ⇒ Object

Adds the user to a group.

Parameters:

  • group (Group)

    The group to which the user should be added.



40
41
42
43
44
# File 'lib/aws/iam/user_group_collection.rb', line 40

def add(group)
  client.add_user_to_group(:group_name => group.name,
                           :user_name => user.name)
  nil
end

#clearnil

Removes this user from all groups.

Returns:

  • (nil)


57
58
59
60
61
# File 'lib/aws/iam/user_group_collection.rb', line 57

def clear
  each do |group|
    remove(group)
  end
end

#each(options = {}) {|group| ... } ⇒ nil

Yields once for each group that the user is in.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :limit (Integer)

    Limits the number of groups that are returned.

  • :batch_size (Integer)

    Controls how many groups are requested from the service at once.

Yield Parameters:

Returns:

  • (nil)


76
77
78
# File 'lib/aws/iam/user_group_collection.rb', line 76

def each(options = {}, &block)
  super(options.merge(:user_name => user.name), &block)
end

#remove(group) ⇒ Object

Removes the user from a group.

Parameters:

  • group (Group)

    The group from which the user should be removed



49
50
51
52
53
# File 'lib/aws/iam/user_group_collection.rb', line 49

def remove(group)
  client.remove_user_from_group(:group_name => group.name,
                                :user_name => user.name)
  nil
end