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.
63 64 65 66 67 |
# File 'lib/zuul/active_record.rb', line 63 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
130 131 132 |
# File 'lib/zuul/active_record.rb', line 130 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 |
# File 'lib/zuul/active_record.rb', line 24 def (args={}, &block) include AuthorizationMethods unless ancestors.include?(AuthorizationMethods) auth_config = Zuul.configuration.clone.configure(args, &block) @auth_scopes ||= {} @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.
45 46 47 48 49 |
# File 'lib/zuul/active_record.rb', line 45 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
125 126 127 |
# File 'lib/zuul/active_record.rb', line 125 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.
72 73 74 75 |
# File 'lib/zuul/active_record.rb', line 72 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.
80 81 82 83 |
# File 'lib/zuul/active_record.rb', line 80 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.
36 37 38 39 40 |
# File 'lib/zuul/active_record.rb', line 36 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
120 121 122 |
# File 'lib/zuul/active_record.rb', line 120 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.
88 89 90 91 |
# File 'lib/zuul/active_record.rb', line 88 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.
54 55 56 57 58 |
# File 'lib/zuul/active_record.rb', line 54 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
135 136 137 |
# File 'lib/zuul/active_record.rb', line 135 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.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/zuul/active_record.rb', line 96 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 |