Class: SakaiInfo::AuthzRole
Constant Summary
collapse
- @@cache =
{}
Instance Attribute Summary collapse
Attributes inherited from SakaiObject
#id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from SakaiObject
all_serializations, #dbrow_only_serialization, #dbrow_serialization, #default_serialization, #object_type_serialization, #serialize, #to_json, #to_yaml
Constructor Details
#initialize(id, name) ⇒ AuthzRole
Returns a new instance of AuthzRole.
16
17
18
19
|
# File 'lib/sakai-info/authz.rb', line 16
def initialize(id, name)
@id = id
@name = name
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
14
15
16
|
# File 'lib/sakai-info/authz.rb', line 14
def name
@name
end
|
Class Method Details
.find(id_or_name) ⇒ Object
.find_by_id(id) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/sakai-info/authz.rb', line 26
def self.find_by_id(id)
id = id.to_s
if @@cache[id].nil?
row = DB.connect.fetch("select role_name from sakai_realm_role " +
"where role_key = ?", id.to_i).first
if row.nil?
raise ObjectNotFoundException.new(AuthzRole, id)
end
@@cache[id] = AuthzRole.new(id, row[:role_name])
@@cache[name] = @@cache[id]
end
@@cache[id]
end
|
.find_by_name(name) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/sakai-info/authz.rb', line 40
def self.find_by_name(name)
if name.nil?
raise ObjectNotFoundException.new(AuthzRole, "")
end
if @@cache[name].nil?
row = DB.connect.fetch("select role_key from sakai_realm_role " +
"where role_name = ?", name).first
if row.nil?
raise ObjectNotFoundException.new(AuthzRole, name)
end
id = row[:role_key].to_i.to_s
@@cache[name] = AuthzRole.new(id, name)
@@cache[id] = @@cache[name]
end
@@cache[name]
end
|
.find_by_realm_id_and_function_id(realm_id, function_id) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/sakai-info/authz.rb', line 72
def self.find_by_realm_id_and_function_id(realm_id, function_id)
roles = []
DB.connect.fetch("select role_key, role_name from " +
"sakai_realm_role where role_key in " +
"(select role_key from sakai_realm_rl_fn " +
"where realm_key=? and function_key=?) " +
"order by role_name", realm_id, function_id) do |row|
role_id = row[:role_key].to_i.to_s
role_name = row[:role_name]
roles << AuthzRole.new(role_id, role_name)
end
roles
end
|
Instance Method Details
#to_s ⇒ Object
21
22
23
|
# File 'lib/sakai-info/authz.rb', line 21
def to_s
name
end
|