Class: SakaiInfo::AuthzFunction

Inherits:
SakaiObject show all
Defined in:
lib/sakai-info/authz.rb

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, descendants, #object_type_serialization, #serialize, #shell_serialization, #summary_serialization, #to_csv, #to_json, #to_yaml

Constructor Details

#initialize(dbrow) ⇒ AuthzFunction

Returns a new instance of AuthzFunction.



106
107
108
109
110
111
# File 'lib/sakai-info/authz.rb', line 106

def initialize(dbrow)
  @dbrow = dbrow

  @id = @dbrow[:function_key].to_i
  @name = @dbrow[:function_name]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



99
100
101
# File 'lib/sakai-info/authz.rb', line 99

def name
  @name
end

Class Method Details

.clear_cacheObject



101
102
103
# File 'lib/sakai-info/authz.rb', line 101

def self.clear_cache
  @@cache = {}
end

.count_by_realm_id_and_role_id(realm_id, role_id) ⇒ Object



166
167
168
# File 'lib/sakai-info/authz.rb', line 166

def self.count_by_realm_id_and_role_id(realm_id, role_id)
  AuthzFunction.query_by_realm_id_and_role_id(realm_id, role_id).count
end

.find(id_or_name) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/sakai-info/authz.rb', line 145

def self.find(id_or_name)
  id_or_name = id_or_name.to_s
  function = nil
  begin
    function = AuthzFunction.find_by_name(id_or_name)
  rescue ObjectNotFoundException
    # just in case
    function = AuthzFunction.find_by_id(id_or_name)
  end
  if function.nil?
    raise ObjectNotFoundException.new(AuthzFunction, id_or_name)
  end
  function
end

.find_by_id(id) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/sakai-info/authz.rb', line 117

def self.find_by_id(id)
  id = id.to_s
  if @@cache[id].nil?
    row = DB.connect[:sakai_realm_function].where(:function_key => id.to_i).first
    if row.nil?
      raise ObjectNotFoundException.new(AuthzFunction, id)
    end
    @@cache[id] = AuthzFunction.new(row)
    @@cache[@@cache[id].name] = @@cache[id]
  end
  @@cache[id]
end

.find_by_name(name) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/sakai-info/authz.rb', line 130

def self.find_by_name(name)
  if name.nil?
    raise ObjectNotFoundException.new(AuthzFunction, "")
  end
  if @@cache[name].nil?
    row = DB.connect[:sakai_realm_function].where(:function_name => name).first
    if row.nil?
      raise ObjectNotFoundException.new(AuthzFunction, name)
    end
    @@cache[name] = AuthzFunction.new(row)
    @@cache[@@cache[name].id] = @@cache[name]
  end
  @@cache[name]
end

.find_by_realm_id_and_role_id(realm_id, role_id) ⇒ Object



170
171
172
173
# File 'lib/sakai-info/authz.rb', line 170

def self.find_by_realm_id_and_role_id(realm_id, role_id)
  AuthzFunction.query_by_realm_id_and_role_id(realm_id, role_id).
    order(:function_name).all.collect { |row| AuthzFunction.new(row) }
end

.query_by_realm_id_and_role_id(realm_id, role_id) ⇒ Object



160
161
162
163
164
# File 'lib/sakai-info/authz.rb', line 160

def self.query_by_realm_id_and_role_id(realm_id, role_id)
  DB.connect[:sakai_realm_function].
    where(:function_key => DB.connect[:sakai_realm_rl_fn].select(:function_key).
          where(:realm_key => realm_id, :role_key => role_id))
end

Instance Method Details

#default_serializationObject



175
176
177
178
179
180
# File 'lib/sakai-info/authz.rb', line 175

def default_serialization
  {
    "id" => self.id,
    "name" => self.name,
  }
end

#to_sObject



113
114
115
# File 'lib/sakai-info/authz.rb', line 113

def to_s
  name
end