Module: Zuul::ActiveRecord::ClassMethods
- Defined in:
- lib/zuul/active_record.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#acts_as_authorization_context(args = {}, &block) ⇒ Object
Configure the model to act as a zuul authorization context (or resource).
-
#acts_as_authorization_context? ⇒ Boolean
Checks if the model is setup to act as a zuul authorization context/resource.
-
#acts_as_authorization_model(args = {}, &block) ⇒ Object
Includes auth methods into the model and configures auth options and scopes.
-
#acts_as_authorization_permission(args = {}, &block) ⇒ Object
Configure the model to act as a zuul authorization permission.
-
#acts_as_authorization_permission? ⇒ Boolean
Checks if the model is setup to act as a zuul authorization permission.
-
#acts_as_authorization_permission_role(args = {}, &block) ⇒ Object
Configure the model to act as a zuul joining model for roles and subjects.
-
#acts_as_authorization_permission_subject(args = {}, &block) ⇒ Object
Configure the model to act as a zuul joining model for roles and subjects.
-
#acts_as_authorization_role(args = {}, &block) ⇒ Object
Configure the model to act as a zuul authorization role.
-
#acts_as_authorization_role? ⇒ Boolean
Checks if the model is setup to act as a zuul authorization role.
-
#acts_as_authorization_role_subject(args = {}, &block) ⇒ Object
Configure the model to act as a zuul joining model for roles and subjects.
-
#acts_as_authorization_subject(args = {}, &block) ⇒ Object
Configure the model to act as a zuul authorization subject.
-
#acts_as_authorization_subject? ⇒ Boolean
Checks if the model is setup to act as a zuul authorization subject.
-
#prepare_join_classes(scope) ⇒ Object
Sets up the join models for a newly defined scope.
Class Method Details
.extended(base) ⇒ Object
18 19 |
# File 'lib/zuul/active_record.rb', line 18 def self.extended(base) end |
Instance Method Details
#acts_as_authorization_context(args = {}, &block) ⇒ Object
Configure the model to act as a zuul authorization context (or resource)
The args parameter is an optional hash of configuration options.
64 65 66 67 68 |
# File 'lib/zuul/active_record.rb', line 64 def (args={}, &block) scope = (args, &block) prepare_join_classes scope.name include Context end |
#acts_as_authorization_context? ⇒ Boolean
Checks if the model is setup to act as a zuul authorization context/resource
131 132 133 |
# File 'lib/zuul/active_record.rb', line 131 def ancestors.include?(Zuul::ActiveRecord::Context) end |
#acts_as_authorization_model(args = {}, &block) ⇒ Object
Includes auth methods into the model and configures auth options and scopes
The args parameter is an optional hash of configuration options.
24 25 26 27 28 29 30 31 32 |
# File 'lib/zuul/active_record.rb', line 24 def (args={}, &block) include AuthorizationMethods auth_config = Zuul.configuration.clone.configure(args, &block) @auth_scopes ||= {} raise "Scope already in use: #{auth_config.scope}" if @auth_scopes.has_key?(auth_config.scope) @auth_scopes[auth_config.scope] = Scope.new(auth_config) @auth_scopes[:default] ||= @auth_scopes[auth_config.scope] @auth_scopes[auth_config.scope] end |
#acts_as_authorization_permission(args = {}, &block) ⇒ Object
Configure the model to act as a zuul authorization permission
The args parameter is an optional hash of configuration options.
46 47 48 49 50 |
# File 'lib/zuul/active_record.rb', line 46 def (args={}, &block) scope = (args.merge({:permission_class => self.name}), &block) prepare_join_classes scope.name include Permission end |
#acts_as_authorization_permission? ⇒ Boolean
Checks if the model is setup to act as a zuul authorization permission
126 127 128 |
# File 'lib/zuul/active_record.rb', line 126 def ancestors.include?(Zuul::ActiveRecord::Permission) end |
#acts_as_authorization_permission_role(args = {}, &block) ⇒ Object
Configure the model to act as a zuul joining model for roles and subjects
The args parameter is an optional hash of configuration options.
73 74 75 76 |
# File 'lib/zuul/active_record.rb', line 73 def (args={}, &block) scope = (args.merge({:permission_role_class => self.name}), &block) include PermissionRole end |
#acts_as_authorization_permission_subject(args = {}, &block) ⇒ Object
Configure the model to act as a zuul joining model for roles and subjects
The args parameter is an optional hash of configuration options.
81 82 83 84 |
# File 'lib/zuul/active_record.rb', line 81 def (args={}, &block) scope = (args.merge({:permission_subject_class => self.name}), &block) include PermissionSubject end |
#acts_as_authorization_role(args = {}, &block) ⇒ Object
Configure the model to act as a zuul authorization role
The args parameter is an optional hash of configuration options.
37 38 39 40 41 |
# File 'lib/zuul/active_record.rb', line 37 def (args={}, &block) scope = (args.merge({:role_class => self.name}), &block) prepare_join_classes scope.name include Role end |
#acts_as_authorization_role? ⇒ Boolean
Checks if the model is setup to act as a zuul authorization role
121 122 123 |
# File 'lib/zuul/active_record.rb', line 121 def ancestors.include?(Zuul::ActiveRecord::Role) end |
#acts_as_authorization_role_subject(args = {}, &block) ⇒ Object
Configure the model to act as a zuul joining model for roles and subjects
The args parameter is an optional hash of configuration options.
89 90 91 92 |
# File 'lib/zuul/active_record.rb', line 89 def (args={}, &block) scope = (args.merge({:role_subject_class => self.name}), &block) include RoleSubject end |
#acts_as_authorization_subject(args = {}, &block) ⇒ Object
Configure the model to act as a zuul authorization subject
The args parameter is an optional hash of configuration options.
55 56 57 58 59 |
# File 'lib/zuul/active_record.rb', line 55 def (args={}, &block) scope = (args.merge({:subject_class => self.name}), &block) prepare_join_classes scope.name include Subject end |
#acts_as_authorization_subject? ⇒ Boolean
Checks if the model is setup to act as a zuul authorization subject
136 137 138 |
# File 'lib/zuul/active_record.rb', line 136 def ancestors.include?(Zuul::ActiveRecord::Subject) end |
#prepare_join_classes(scope) ⇒ Object
Sets up the join models for a newly defined scope.
This is similar the the acts_as_authorization_* methods, but it handles all the joining models for a scope.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/zuul/active_record.rb', line 97 def prepare_join_classes(scope) scope_config = auth_scope(scope).config unless auth_scope(scope).role_subject_class.ancestors.include?(RoleSubject) auth_scope(scope).role_subject_class.instance_eval do (scope_config.to_h) end end if auth_scope(scope).config. unless auth_scope(scope)..ancestors.include?(PermissionSubject) auth_scope(scope)..instance_eval do (scope_config.to_h) end end unless auth_scope(scope)..ancestors.include?(PermissionRole) auth_scope(scope)..instance_eval do (scope_config.to_h) end end end end |