Class: Goz::Group::Grouper

Inherits:
Base
  • Object
show all
Defined in:
lib/goz/group/grouper.rb,
lib/goz/group/grouper/stemmed_groups.rb

Overview

:nodoc:

Direct Known Subclasses

StemmedGroups

Defined Under Namespace

Classes: StemmedGroups

Constant Summary collapse

TAG =
self.name

Instance Attribute Summary

Attributes inherited from Base

#display_name, #identifier, #klass, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], configuration, #to_hash, #to_s

Constructor Details

#initialize(g) ⇒ Grouper

Returns a new instance of Grouper.



30
31
32
33
34
35
# File 'lib/goz/group/grouper.rb', line 30

def initialize(g)
  @display_name = _prettify_name g['name']
  @identifier   = g['uuid']
  @klass        = self.class.name
  @name         = g['name']
end

Class Method Details

.extension(name) ⇒ Object

TODO



67
68
69
70
# File 'lib/goz/group/grouper.rb', line 67

def self.extension(name)
  m = name.match( /^.+:(.+)$/ )
  m ? m[1] : nil
end

.find_by_name(name) ⇒ Object

Find Goz::Group by name or return nil



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/goz/group/grouper.rb', line 41

def self.find_by_name(name)
  Goz::Logger.debug TAG, "find_by_name( name=#{name} )"
  connect do |grouper|
    g = grouper.group(name.rstrip) # TODO Sigh...
    if g.nil?
      Goz::Logger.warn TAG, "find_by_name( name=#{name} ) - not found"
      return nil
    end
    group = new g
    yield group if block_given?
    return group
  end
  nil
end

.groups(user) ⇒ Object

Return groups where user is an admin.



89
90
91
92
# File 'lib/goz/group/grouper.rb', line 89

def self.groups(user)
  Goz::Logger.debug TAG, "groups( user.login=#{user.} ) - not implemented"
  []
end

.memberships(user) ⇒ Object

Return groups where user is a member.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/goz/group/grouper.rb', line 97

def self.memberships(user)
  if user.nil?
    Goz::Logger.warn TAG, "memberships( user=nil )"
    return []
  end
  Goz::Logger.debug TAG, "memberships( user.login=#{user.} )"
  groups = []
  self.connect do |grouper|
    subject = grouper.subject user.identifier
    if subject.nil?
      Goz::Logger.warn TAG, "memberships( user.login=#{user.} ) - could not find user with identifier=#{ user.identifier }"
      break
    end
    groups = subject.groups( @@cf['base'] ).collect { |g| new g }
  end
  groups.each { |g| yield g } if block_given?
  groups
end

.stem(name) ⇒ Object

TODO



119
120
121
122
# File 'lib/goz/group/grouper.rb', line 119

def self.stem(name)
  m = name.match( /^(.+):.+$/ )
  m ? m[1] : nil
end

.stemmed_group?(name) ⇒ Boolean

TODO

Returns:

  • (Boolean)


127
128
129
130
# File 'lib/goz/group/grouper.rb', line 127

def self.stemmed_group?(name)
  suffixes  = @@cf['admin_suffix'] | @@cf['member_suffix']
  Regexp.new( "^.*?:(#{ suffixes.join('|') })$" ).match(name) ? true : false
end

Instance Method Details

#adminsObject

TODO



59
60
61
62
# File 'lib/goz/group/grouper.rb', line 59

def admins()
  Goz::Logger.debug TAG, "name=#{self.name} - #admins() - not implemented"
  [] # TODO
end

#membersObject

TODO



75
76
77
78
79
80
81
82
83
84
# File 'lib/goz/group/grouper.rb', line 75

def members()
  Goz::Logger.debug TAG, "#{self.name} - #members()"
  users = []
  Goz::Group::Grouper.connect do |grouper|
    users = grouper.group(self.name).members.collect { |m| Goz::User.find_by_identifier m['id'] }
    users.delete_if { |_| _.nil? }
  end
  users.each { |u| yield u } if block_given?
  users
end