Class: ObjectRole

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/object_role.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_all_by_object(object) ⇒ Object

What ObjectRoles does this object have associated?



12
13
14
15
16
17
18
19
20
# File 'app/models/object_role.rb', line 12

def self.find_all_by_object(object)
  raise "Can only operate on ActiveRecord::Base objects." unless object.is_a?(ActiveRecord::Base)
  raise "Can only operate on saved objects" if object.new_record?

  klazz_name = object.class.to_s
  object_reference = object.id

  ObjectRole.find(:all, :conditions => { :klazz_name => klazz_name, :object_reference => object_reference } )
end

.rolesObject

class methods



7
8
9
# File 'app/models/object_role.rb', line 7

def self.roles
  [ "owner" ]
end

Instance Method Details

#descriptionObject

instance methods



44
45
46
# File 'app/models/object_role.rb', line 44

def description
  "#{self.klazz_name} #{self.object_reference}"
end

#objectObject



48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/object_role.rb', line 48

def object
  obj = nil

  begin
    klazz = eval(self.klazz_name)
    obj = klazz.find(self.object_reference)
  rescue
  end

  obj
end