Class: SakaiInfo::AuthzRole
- Inherits:
-
SakaiObject
- Object
- SakaiObject
- SakaiInfo::AuthzRole
- Defined in:
- lib/sakai-info/authz.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from SakaiObject
Class Method Summary collapse
- .clear_cache ⇒ Object
- .count_by_realm_id_and_function_id(realm_id, function_id) ⇒ Object
- .find(id_or_name) ⇒ Object
- .find_by_id(id) ⇒ Object
- .find_by_name(name) ⇒ Object
- .find_by_realm_id_and_function_id(realm_id, function_id) ⇒ Object
- .query_by_realm_id_and_function_id(realm_id, function_id) ⇒ Object
Instance Method Summary collapse
- #default_serialization ⇒ Object
-
#initialize(dbrow) ⇒ AuthzRole
constructor
A new instance of AuthzRole.
- #to_s ⇒ Object
Methods inherited from SakaiObject
all_serializations, #dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #summary_serialization, #to_csv, #to_json, #to_yaml
Constructor Details
#initialize(dbrow) ⇒ AuthzRole
Returns a new instance of AuthzRole.
21 22 23 24 25 26 |
# File 'lib/sakai-info/authz.rb', line 21 def initialize(dbrow) @dbrow = dbrow @id = @dbrow[:role_key].to_i @name = @dbrow[:role_name] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/sakai-info/authz.rb', line 14 def name @name end |
Class Method Details
.clear_cache ⇒ Object
16 17 18 |
# File 'lib/sakai-info/authz.rb', line 16 def self.clear_cache @@cache = {} end |
.count_by_realm_id_and_function_id(realm_id, function_id) ⇒ Object
81 82 83 |
# File 'lib/sakai-info/authz.rb', line 81 def self.count_by_realm_id_and_function_id(realm_id, function_id) AuthzRole.query_by_realm_id_and_function_id(realm_id, function_id).count end |
.find(id_or_name) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sakai-info/authz.rb', line 60 def self.find(id_or_name) id_or_name = id_or_name.to_s role = nil begin role = AuthzRole.find_by_name(id_or_name) rescue ObjectNotFoundException # just in case role = AuthzRole.find_by_id(id_or_name) end if role.nil? raise ObjectNotFoundException.new(AuthzRole, id_or_name) end role end |
.find_by_id(id) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sakai-info/authz.rb', line 32 def self.find_by_id(id) id = id.to_s if @@cache[id].nil? row = DB.connect[:sakai_realm_role].where(:role_key => id.to_i).first if row.nil? raise ObjectNotFoundException.new(AuthzRole, id) end @@cache[id] = AuthzRole.new(row) @@cache[@@cache[id].name] = @@cache[id] end @@cache[id] end |
.find_by_name(name) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sakai-info/authz.rb', line 45 def self.find_by_name(name) if name.nil? raise ObjectNotFoundException.new(AuthzRole, "") end if @@cache[name].nil? row = DB.connect[:sakai_realm_role].where(:role_name => name).first if row.nil? raise ObjectNotFoundException.new(AuthzRole, name) end @@cache[name] = AuthzRole.new(row) @@cache[@@cache[name].id] = @@cache[name] end @@cache[name] end |
.find_by_realm_id_and_function_id(realm_id, function_id) ⇒ Object
85 86 87 88 |
# File 'lib/sakai-info/authz.rb', line 85 def self.find_by_realm_id_and_function_id(realm_id, function_id) AuthzRole.query_by_realm_id_and_function_id(realm_id, function_id). order(:role_name).all.collect { |row| AuthzRole.new(row) } end |
.query_by_realm_id_and_function_id(realm_id, function_id) ⇒ Object
75 76 77 78 79 |
# File 'lib/sakai-info/authz.rb', line 75 def self.query_by_realm_id_and_function_id(realm_id, function_id) DB.connect[:sakai_realm_role]. where(:role_key => DB.connect[:sakai_realm_rl_fn].select(:role_key). where(:realm_key => realm_id, :function_key => function_id)) end |
Instance Method Details
#default_serialization ⇒ Object
90 91 92 93 94 95 |
# File 'lib/sakai-info/authz.rb', line 90 def default_serialization { "id" => self.id, "name" => self.name, } end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/sakai-info/authz.rb', line 28 def to_s name end |