Sha256: 20c55bfdaafc6b9b5b19eeb6437237913d522501af9739da769d81cb96397137

Contents?: true

Size: 1.1 KB

Versions: 15

Compression:

Stored size: 1.1 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

15 entries across 15 versions & 2 rubygems

Version Path
jbox-gitolite-1.2.0 lib/gitolite/config/group.rb
jbox-gitolite-1.1.11 lib/gitolite/config/group.rb
jbox-gitolite-1.1.10 lib/gitolite/config/group.rb
jbox-gitolite-1.1.9 lib/gitolite/config/group.rb
jbox-gitolite-1.1.8 lib/gitolite/config/group.rb
jbox-gitolite-1.1.7 lib/gitolite/config/group.rb
jbox-gitolite-1.1.6 lib/gitolite/config/group.rb
jbox-gitolite-1.1.5 lib/gitolite/config/group.rb
jbox-gitolite-1.1.4 lib/gitolite/config/group.rb
jbox-gitolite-1.1.3 lib/gitolite/config/group.rb
jbox-gitolite-1.1.2 lib/gitolite/config/group.rb
gitolite-1.1.0 lib/gitolite/config/group.rb
gitolite-1.0.1 lib/gitolite/config/group.rb
gitolite-1.0.0 lib/gitolite/config/group.rb
gitolite-0.0.3.alpha lib/gitolite/config/group.rb