Module: ActiveAcl::Acts::AccessObject::InstanceMethods

Defined in:
lib/active_acl/acts_as_access_object.rb

Instance Method Summary collapse

Instance Method Details

#active_acl_cached_2d!Object



97
98
99
# File 'lib/active_acl/acts_as_access_object.rb', line 97

def active_acl_cached_2d!
  active_acl_instance_cache[:prefetched_2d]=true
end

#active_acl_cached_2d?Boolean

returns if the 2d acls are already cached

Returns:

  • (Boolean)


94
95
96
# File 'lib/active_acl/acts_as_access_object.rb', line 94

def active_acl_cached_2d?
  !!active_acl_instance_cache[:prefetched_2d]
end

#active_acl_clear_cache!Object



101
102
103
104
# File 'lib/active_acl/acts_as_access_object.rb', line 101

def active_acl_clear_cache!
  @active_acl_instance_cache ={}         #clear the lokal cache
  active_acl_handler.delete_cached(self) #clear the 2 level cache
end

#active_acl_descriptionObject

override this to customize the description in the interface



106
107
108
# File 'lib/active_acl/acts_as_access_object.rb', line 106

def active_acl_description
  to_s
end

#active_acl_handlerObject



86
87
88
# File 'lib/active_acl/acts_as_access_object.rb', line 86

def active_acl_handler
  ActiveAcl::ACCESS_CLASSES[self.class.name]
end

#active_acl_instance_cacheObject

returns a key value store



90
91
92
# File 'lib/active_acl/acts_as_access_object.rb', line 90

def active_acl_instance_cache
  @active_acl_instance_cache ||= active_acl_handler.get_instance_cache(self)
end

#has_privilege?(privilege, options = {}) ⇒ Boolean

checks if the user has a certain privilege, optionally on the given object. Option :on defines the target object.

Returns:

  • (Boolean)


77
78
79
80
81
82
83
84
85
# File 'lib/active_acl/acts_as_access_object.rb', line 77

def has_privilege?(privilege, options = {})
  target = options[:on] #TODO: add error handling if not a hash
  # no need to check anything if privilege is not a Privilege
  raise "first Argument has to be a Privilege" unless privilege.is_a?(Privilege)
  # no need to check anything if target is no Access Object
  raise "target hast to be an AccessObject" if target and !(target.class.respond_to?(:base_class) and ActiveAcl::ACCESS_CLASSES.has_key?(target.class.base_class.name))
  
  active_acl_handler.has_privilege?(self,privilege,target)
end