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

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from Core::Collection::Limitable

#each_batch

Methods included from Core::Collection

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

Methods included from Core::Model

#client, #config_prefix, #inspect

Constructor Details

#initialize(user, opts = {}) ⇒ UserGroupCollection

Returns a new instance of UserGroupCollection.


32
33
34
35
# File 'lib/aws/iam/user_group_collection.rb', line 32

def initialize(user, opts = {})
  @user = user
  super
end

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