Sha256: b306bac570428d2ecdff1d4a2c4ce435e24f4ded6284b587b14abcb97d22e49e

Contents?: true

Size: 1.12 KB

Versions: 10

Compression:

Stored size: 1.12 KB

Contents

module Gitolite
  class Config

    # Represents a group inside the gitolite configuration.  The name and users
    # options are all encapsulated in this class.  All users are stored as
    # Strings!
    class Group

      attr_accessor :name, :users

      PREPEND_CHAR = '@'

      def initialize(name)
        # naively remove the prepend char
        # I don't think you can have two of them in a group name
        @name = name.gsub(PREPEND_CHAR, '')
        @users = []
      end


      def empty!
        @users.clear
      end


      def add_user(user)
        return if has_user?(user)
        @users.push(user.to_s).sort!
      end


      def add_users(*users)
        fixed_users = users.flatten.map{ |u| u.to_s }
        @users.concat(fixed_users).sort!.uniq!
      end


      def rm_user(user)
        @users.delete(user.to_s)
      end


      def has_user?(user)
        @users.include? user.to_s
      end


      def size
        @users.length
      end


      def to_s
        members = @users.join(' ')
        name = "#{PREPEND_CHAR}#{@name}"
        "#{name.ljust(20)}= #{members}\n"
      end

    end

  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
jbox-gitolite-1.2.7 lib/gitolite/config/group.rb
jbox-gitolite-1.2.6 lib/gitolite/config/group.rb
gitolite-rugged-1.2.2 lib/gitolite/config/group.rb
jbox-gitolite-1.2.5 lib/gitolite/config/group.rb
jbox-gitolite-1.2.4 lib/gitolite/config/group.rb
jbox-gitolite-1.2.3 lib/gitolite/config/group.rb
gitolite-rugged-1.2.1.pre.devel lib/gitolite/config/group.rb
gitolite-rugged-1.2.pre.devel lib/gitolite/config/group.rb
jbox-gitolite-1.2.2 lib/gitolite/config/group.rb
jbox-gitolite-1.2.1 lib/gitolite/config/group.rb