# class Puppet::Util::ADSI::Group

### Attributes

name[R]
native_group[RW]

### Public Class Methods

create(name) click to toggle source

    # File lib/puppet/util/adsi.rb, line 271
    def self.create(name)
      # Windows error 2224: The account already exists.
      raise Puppet::Error.new( "Cannot create group if user '#{name}' exists." ) if Puppet::Util::ADSI::User.exists? name
      new(name, Puppet::Util::ADSI.create(name, 'group'))
    end

delete(name) click to toggle source

    # File lib/puppet/util/adsi.rb, line 281
    def self.delete(name)
      Puppet::Util::ADSI.delete(name, 'group')
    end

each(&block) click to toggle source

    # File lib/puppet/util/adsi.rb, line 285
    def self.each(&block)
      wql = Puppet::Util::ADSI.execquery( "select * from win32_group" )

      groups = []
      wql.each do |g|
        groups << new(g.name, g)
      end

      groups.each(&block)
    end

exists?(name) click to toggle source

    # File lib/puppet/util/adsi.rb, line 277
    def self.exists?(name)
      Puppet::Util::ADSI.connectable?(Group.uri(name))
    end

new(name, native_group = nil) click to toggle source

    # File lib/puppet/util/adsi.rb, line 210
    def initialize(name, native_group = nil)
      @name = name
      @native_group = native_group
    end

uri(name) click to toggle source

    # File lib/puppet/util/adsi.rb, line 219
    def self.uri(name)
      Puppet::Util::ADSI.uri(name, 'group')
    end

### Public Instance Methods

add_member(*names)
Alias for: add_members
add_members(*names) click to toggle source

    # File lib/puppet/util/adsi.rb, line 236
    def add_members(*names)
      names.each do |name|
        native_group.Add(Puppet::Util::ADSI::User.uri(name))
      end
    end

Also aliased as: add_member
commit() click to toggle source

    # File lib/puppet/util/adsi.rb, line 227
    def commit
      begin
        native_group.SetInfo unless native_group.nil?
      rescue Exception => e
        raise Puppet::Error.new( "Group update failed: #{e}" )
      end
      self
    end

members() click to toggle source

    # File lib/puppet/util/adsi.rb, line 250
    def members
      # WIN32OLE objects aren't enumerable, so no map
      members = []
      native_group.Members.each {|m| members << m.Name}
      members
    end

remove_member(*names)
Alias for: remove_members
remove_members(*names) click to toggle source

    # File lib/puppet/util/adsi.rb, line 243
    def remove_members(*names)
      names.each do |name|
        native_group.Remove(Puppet::Util::ADSI::User.uri(name))
      end
    end

Also aliased as: remove_member
set_members(desired_members) click to toggle source

    # File lib/puppet/util/adsi.rb, line 257
    def set_members(desired_members)
      return if desired_members.nil? or desired_members.empty?

      current_members = self.members

      # First we add all missing members
      members_to_add = desired_members - current_members
      add_members(*members_to_add)

      # Then we remove all extra members
      members_to_remove = current_members - desired_members
      remove_members(*members_to_remove)
    end

uri() click to toggle source

    # File lib/puppet/util/adsi.rb, line 215
    def uri
      self.class.uri(name)
    end