Module: AnnotationSecurity::Resource::ClassMethods

Defined in:
lib/annotation_security/includes/resource.rb

Overview

Provides class side methods for resource classes.

Instance Method Summary collapse

Instance Method Details

#get_resource(arg) ⇒ Object

If required, overwrite this method to return a resource object identified by the argument.

This might be necessary if you change the to_param method of an ActiveRecord class.

class Course < ActiveRecord::Base
  ...
  # each course has a unique name --> make better urls
  def to_param
    name
  end

  def self.get_resource(name)
    find_by_name(name)
  end

Raises:

  • (NoMethodError)


60
61
62
# File 'lib/annotation_security/includes/resource.rb', line 60

def get_resource(arg)
  raise NoMethodError, "#{self} does not implement #get_resource"
end

#policy_for(user, obj = nil) ⇒ Object

:nodoc:



39
40
41
# File 'lib/annotation_security/includes/resource.rb', line 39

def policy_for(user,obj=nil) # :nodoc:
  policy_factory.create_policy(user,obj)
end

#resource_typeObject

:nodoc:



35
36
37
# File 'lib/annotation_security/includes/resource.rb', line 35

def resource_type # :nodoc:
  @resource_type || (self.resource_type = name.underscore.to_sym)
end

#resource_type=(symbol) ⇒ Object

Registers the class as a resource.



29
30
31
32
33
# File 'lib/annotation_security/includes/resource.rb', line 29

def resource_type=(symbol)
  @resource_type = symbol
  AnnotationSecurity::ResourceManager.add_resource_class(symbol,self)
  symbol
end