-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCGUserGroup.rb
49 lines (39 loc) · 883 Bytes
/
CGUserGroup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/ruby
#
require 'set'
require 'rubygems'
require 'xml/mapping'
class CGUserGroup
include XML::Mapping
object_node :users, "users",
:unmarshaller=>proc{|xml|
set = Set.new []
xml.each_element { |xpath|
set << CGUser.load_from_xml(xpath)
}
set
},
:marshaller=>proc{|xml,value|
value.each { |user|
e = xml.elements.add(user.save_to_xml)
}
}
text_node :name, "@name"
text_node :uuid, "@uuid"
attr_reader :users, :name
def initialize(name)
self.initialize(name, [])
end
# users is an array
def initialize(name, users)
@name = name
@users = Set.new users
@uuid = `uuidgen`.strip
end
def hash
@uuid.tr("-", '').hex
end
def eql?(other)
return @uuid == other.uuid
end
end