Class: Permit::PermitRules
- Inherits:
-
Object
- Object
- Permit::PermitRules
- Includes:
- Support
- Defined in:
- lib/permit/permit_rules.rb
Overview
Collection of PermitRule objects defining authorization.
Instance Attribute Summary (collapse)
-
- (Object) action_allow_rules
Returns the value of attribute action_allow_rules.
-
- (Object) action_deny_rules
Returns the value of attribute action_deny_rules.
-
- (Object) logger
Returns the value of attribute logger.
-
- (Object) options
Returns the value of attribute options.
Instance Method Summary (collapse)
-
- (PermitRule) allow(roles, options = {})
Adds an allow rule for the given actions to the collection.
-
- (PermitRule) deny(roles, options = {})
Adds an deny rule for the given actions to the collection.
-
- (PermitRules) initialize(logger, options = {})
constructor
A new instance of PermitRules.
-
- (true, false) permitted?(person, action, context_binding)
Determines if the person is permitted on the specified action by first evaluating deny rules, and then allow rules.
Methods included from Support
#authorization_conditions, #get_role, #get_roles, #permit_arrayify, #resource_conditions, #role_condition
Constructor Details
- (PermitRules) initialize(logger, options = {})
A new instance of PermitRules
13 14 15 16 17 18 |
# File 'lib/permit/permit_rules.rb', line 13 def initialize(logger, = {}) @action_deny_rules = {} @action_allow_rules = {} @logger = logger @options = end |
Instance Attribute Details
- (Object) action_allow_rules
Returns the value of attribute action_allow_rules
6 7 8 |
# File 'lib/permit/permit_rules.rb', line 6 def action_allow_rules @action_allow_rules end |
- (Object) action_deny_rules
Returns the value of attribute action_deny_rules
6 7 8 |
# File 'lib/permit/permit_rules.rb', line 6 def action_deny_rules @action_deny_rules end |
- (Object) logger
Returns the value of attribute logger
6 7 8 |
# File 'lib/permit/permit_rules.rb', line 6 def logger @logger end |
- (Object) options
Returns the value of attribute options
6 7 8 |
# File 'lib/permit/permit_rules.rb', line 6 def @options end |
Instance Method Details
- (PermitRule) allow(roles, options = {})
Adds an allow rule for the given actions to the collection.
82 83 84 85 86 87 |
# File 'lib/permit/permit_rules.rb', line 82 def allow(roles, = {}) actions = .delete(:to) rule = PermitRule.new(roles, ) index_rule_by_actions @action_allow_rules, actions, rule return rule end |
- (PermitRule) deny(roles, options = {})
Adds an deny rule for the given actions to the collection.
123 124 125 126 127 128 |
# File 'lib/permit/permit_rules.rb', line 123 def deny(roles, = {}) actions = .delete(:from) rule = PermitRule.new(roles, ) index_rule_by_actions @action_deny_rules, actions, rule return rule end |
- (true, false) permitted?(person, action, context_binding)
Determines if the person is permitted on the specified action by first evaluating deny rules, and then allow rules. If the :default_access option is set then its value will be used instead of the value from Permit::Config#default_access.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/permit/permit_rules.rb', line 33 def permitted?(person, action, context_binding) # Denial takes priority over allow return false if has_action_rule_match?(:deny, @action_deny_rules, person, action, context_binding) return true if has_action_rule_match?(:allow, @action_allow_rules, person, action, context_binding) # Default to no access if no rules match default_access = (@options[:default_access] || Permit::Config.default_access) return (default_access == :allow ? true : false) end |