Class: AnnotationSecurity::PolicyManager
- Defined in:
- lib/annotation_security/manager/policy_manager.rb
Overview
AnnotationSecurity::PolicyManager
Manages loading and creation of all policy classes.
Class Method Summary collapse
-
.add_file(f, ext) ⇒ Object
Adds a file that contains security configurations *
f
file name *ext
‘yml’ or ‘rb’. -
.config_files ⇒ Object
:nodoc:.
-
.create_policy(resource_type, *args) ⇒ Object
Creates a policy object for a user and a resource type.
-
.policy_class(resource_class) ⇒ Object
:nodoc:.
-
.policy_factory(resource_type) ⇒ Object
Get the policy factory for a resource class.
- .reset ⇒ Object
Class Method Details
.add_file(f, ext) ⇒ Object
Adds a file that contains security configurations
-
f
file name -
ext
‘yml’ or ‘rb’
40 41 42 43 44 45 |
# File 'lib/annotation_security/manager/policy_manager.rb', line 40 def self.add_file(f,ext) # :nodoc: unless config_files.include? [f,ext] config_files.push [f,ext] load_file(f,ext) end end |
.config_files ⇒ Object
:nodoc:
33 34 35 |
# File 'lib/annotation_security/manager/policy_manager.rb', line 33 def self.config_files # :nodoc: @files ||= [] end |
.create_policy(resource_type, *args) ⇒ Object
Creates a policy object for a user and a resource type
Example
picture = Picture.find_by_id(params[:picture])
policy = PolicyManager.get_policy(:picture,@current_user)
policy.allowed? :show, picture # => true or false
25 26 27 |
# File 'lib/annotation_security/manager/policy_manager.rb', line 25 def self.create_policy(resource_type,*args) policy_factory(resource_type).create_policy(*args) end |
.policy_class(resource_class) ⇒ Object
:nodoc:
29 30 31 |
# File 'lib/annotation_security/manager/policy_manager.rb', line 29 def self.policy_class(resource_class) # :nodoc: policy_factory(resource_class).policy_class end |
.policy_factory(resource_type) ⇒ Object
Get the policy factory for a resource class
13 14 15 |
# File 'lib/annotation_security/manager/policy_manager.rb', line 13 def self.policy_factory(resource_type) # :nodoc: policy_factories[resource_type.to_sym] end |
.reset ⇒ Object
47 48 49 50 |
# File 'lib/annotation_security/manager/policy_manager.rb', line 47 def self.reset policy_factories.each_value(&:reset) config_files.each { |f,ext| load_file(f,ext) } end |