Class: Shamu::Security::PolicyRefinement
- Inherits:
-
Object
- Object
- Shamu::Security::PolicyRefinement
- Defined in:
- lib/shamu/security/policy_refinement.rb
Overview
Defines how an ActiveRecord::Relation is refined for an ActiveRecordPolicy.
Instance Method Summary collapse
-
#apply(relation, additional_context) ⇒ ActiveRecord::Relation
Apply the refinement to the relation.
-
#initialize(actions, model_class, block) ⇒ PolicyRefinement
constructor
A new instance of PolicyRefinement.
-
#match?(action, relation, additional_context) ⇒ Boolean
Determines if the refinement matches the request action permission on the given relation.
Constructor Details
#initialize(actions, model_class, block) ⇒ PolicyRefinement
Returns a new instance of PolicyRefinement.
8 9 10 11 12 |
# File 'lib/shamu/security/policy_refinement.rb', line 8 def initialize( actions, model_class, block ) @actions = actions @model_class = model_class @block = block end |
Instance Method Details
#apply(relation, additional_context) ⇒ ActiveRecord::Relation
Apply the refinement to the relation.
34 35 36 |
# File 'lib/shamu/security/policy_refinement.rb', line 34 def apply( relation, additional_context ) ( block && block.call( relation, additional_context ) ) || relation end |
#match?(action, relation, additional_context) ⇒ Boolean
Determines if the refinement matches the request action permission on the given relation.
23 24 25 26 27 28 |
# File 'lib/shamu/security/policy_refinement.rb', line 23 def match?( action, relation, additional_context ) return false unless actions.include? action return false unless model_class_match?( relation ) true end |