Class: Permit::PermitRule
- Inherits:
-
Object
- Object
- Permit::PermitRule
- Includes:
- Support
- Defined in:
- lib/permit/permit_rule.rb
Overview
Defines an authorization rule to match against.
Constant Summary
- VALID_OPTION_KEYS =
[:who, :that, :of, :on, :if, :unless]
- BUILTIN_ROLES =
[:person, :guest, :everyone]
Instance Attribute Summary (collapse)
-
- (Object) if
readonly
Returns the value of attribute if.
-
- (Object) method
readonly
Returns the value of attribute method.
-
- (Object) roles
readonly
Returns the value of attribute roles.
-
- (Object) target_vars
readonly
Returns the value of attribute target_vars.
-
- (Object) unless
readonly
Returns the value of attribute unless.
Instance Method Summary (collapse)
-
- (PermitRule) initialize(roles, options = {})
constructor
Creates a new PermitRule.
-
- (Boolean) matches?(person, context_binding)
Determine if the passed in person matches this rule.
Methods included from Support
#authorization_conditions, #get_role, #get_roles, #permit_arrayify, #resource_conditions, #role_condition
Constructor Details
- (PermitRule) initialize(roles, options = {})
Creates a new PermitRule.
:if and :unless conditions may be evaluated for static, dynamic, and named authorizations. They are evaluated after the other rule checks are applied, and only if the rule still matches. The conditionals may make a matching rule not match, but will not make an unmatched rule match. If both :if and :unless are given the :if condition is run first, and if the rule still matches the :unless will be run.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/permit/permit_rule.rb', line 61 def initialize(roles, = {}) .assert_valid_keys *VALID_OPTION_KEYS @roles = validate_roles(roles).freeze @method = [:who] || [:that] @target_vars = permit_arrayify([:of] || [:on]).uniq.freeze @if = [:if] @unless = [:unless] end |
Instance Attribute Details
- (Object) if (readonly)
Returns the value of attribute if
9 10 11 |
# File 'lib/permit/permit_rule.rb', line 9 def if @if end |
- (Object) method (readonly)
Returns the value of attribute method
9 10 11 |
# File 'lib/permit/permit_rule.rb', line 9 def method @method end |
- (Object) roles (readonly)
Returns the value of attribute roles
9 10 11 |
# File 'lib/permit/permit_rule.rb', line 9 def roles @roles end |
- (Object) target_vars (readonly)
Returns the value of attribute target_vars
9 10 11 |
# File 'lib/permit/permit_rule.rb', line 9 def target_vars @target_vars end |
- (Object) unless (readonly)
Returns the value of attribute unless
9 10 11 |
# File 'lib/permit/permit_rule.rb', line 9 def unless @unless end |
Instance Method Details
- (Boolean) matches?(person, context_binding)
Determine if the passed in person matches this rule.
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/permit/permit_rule.rb', line 83 def matches?(person, context_binding) matched = if BUILTIN_ROLES.include? @roles[0] person, context_binding else person, context_binding end passed_conditionals = matched ? passes_conditionals?(person, context_binding) : false passed = matched && passed_conditionals return passed end |