Class: Shamu::Security::PolicyRule
- Inherits:
-
Object
- Object
- Shamu::Security::PolicyRule
- Defined in:
- lib/shamu/security/policy_rule.rb
Overview
A rule capturing the permitted actions and resources for Policy permissions.
Attributes collapse
-
#result ⇒ Object
The value to return as the result of a Shamu::Security::Policy#permit? call if the rule matches the request.
Instance Method Summary collapse
-
#initialize(actions, resource, result, block) ⇒ PolicyRule
constructor
A new instance of PolicyRule.
-
#match?(action, resource, additional_context) ⇒ Boolean
Determines if the rule matches the request action permission on the given resource.
Constructor Details
#initialize(actions, resource, result, block) ⇒ PolicyRule
Returns a new instance of PolicyRule.
20 21 22 23 24 25 |
# File 'lib/shamu/security/policy_rule.rb', line 20 def initialize( actions, resource, result, block ) @actions = actions @resource = resource @result = result @block = block end |
Instance Attribute Details
#result ⇒ Object
Returns the value to return as the result of a Shamu::Security::Policy#permit? call if the rule matches the request.
15 16 17 |
# File 'lib/shamu/security/policy_rule.rb', line 15 def result @result end |
Instance Method Details
#match?(action, resource, additional_context) ⇒ Boolean
Determines if the rule matches the request action permission on the given resource.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/shamu/security/policy_rule.rb', line 35 def match?( action, resource, additional_context ) return true if actions.include? :any return false unless actions.include? action return false unless resource_match?( resource ) if block && !resource.is_a?( Module ) block.call( resource, additional_context ) else true end end |