Class: SakaiInfo::Group
Instance Attribute Summary collapse
Attributes inherited from SakaiObject
#id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from SakaiObject
#dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml
Constructor Details
#initialize(dbrow) ⇒ Group
Returns a new instance of Group.
21
22
23
24
25
26
27
|
# File 'lib/sakai-info/group.rb', line 21
def initialize(dbrow)
@dbrow = dbrow
@id = dbrow[:group_id]
@site_id = dbrow[:site_id]
@title = dbrow[:title]
end
|
Instance Attribute Details
#dbrow ⇒ Object
Returns the value of attribute dbrow.
14
15
16
|
# File 'lib/sakai-info/group.rb', line 14
def dbrow
@dbrow
end
|
#site_id ⇒ Object
Returns the value of attribute site_id.
14
15
16
|
# File 'lib/sakai-info/group.rb', line 14
def site_id
@site_id
end
|
#title ⇒ Object
Returns the value of attribute title.
14
15
16
|
# File 'lib/sakai-info/group.rb', line 14
def title
@title
end
|
Class Method Details
.all_serializations ⇒ Object
109
110
111
|
# File 'lib/sakai-info/group.rb', line 109
def self.all_serializations
[:default, :users, :realm]
end
|
.clear_cache ⇒ Object
16
17
18
|
# File 'lib/sakai-info/group.rb', line 16
def self.clear_cache
@@cache = {}
end
|
.count_by_site_id(site_id) ⇒ Object
53
54
55
|
# File 'lib/sakai-info/group.rb', line 53
def self.count_by_site_id(site_id)
Group.query_by_site_id(site_id).count
end
|
.find(id) ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/sakai-info/group.rb', line 33
def self.find(id)
if @@cache[id].nil?
row = DB.connect[:sakai_site_group].filter(:group_id => id).first
if row.nil?
raise ObjectNotFoundException.new(Group, id)
end
@@cache[id] = Group.new(row)
end
@@cache[id]
end
|
.find_by_site_id(site_id) ⇒ Object
48
49
50
51
|
# File 'lib/sakai-info/group.rb', line 48
def self.find_by_site_id(site_id)
Group.query_by_site_id(site_id).all.
collect { |row| @@cache[row[:group_id]] = Group.new(row) }
end
|
.query_by_site_id(site_id) ⇒ Object
44
45
46
|
# File 'lib/sakai-info/group.rb', line 44
def self.query_by_site_id(site_id)
DB.connect[:sakai_site_group].where(:site_id => site_id)
end
|
Instance Method Details
#default_serialization ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/sakai-info/group.rb', line 74
def default_serialization
result = {
"id" => self.id,
"title" => self.title,
"site" => self.site.serialize(:summary),
"user_count" => self.realm.user_count,
"providers" => self.providers,
"properties" => self.properties
}
if result["properties"] == {}
result.delete("properties")
end
result
end
|
#providers ⇒ Object
65
66
67
|
# File 'lib/sakai-info/group.rb', line 65
def providers
@providers ||= self.realm.providers
end
|
#realm_serialization ⇒ Object
103
104
105
106
107
|
# File 'lib/sakai-info/group.rb', line 103
def realm_serialization
{
"realm" => self.realm.name
}
end
|
#site ⇒ Object
29
30
31
|
# File 'lib/sakai-info/group.rb', line 29
def site
@site ||= Site.find(@site_id)
end
|
#summary_serialization ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/sakai-info/group.rb', line 89
def summary_serialization
{
"id" => self.id,
"title" => self.title,
"user_count" => self.realm.user_count
}
end
|
#users_serialization ⇒ Object
97
98
99
100
101
|
# File 'lib/sakai-info/group.rb', line 97
def users_serialization
{
"users" => self.users.collect { |u| u.serialize(:summary) }
}
end
|