lib/pragma/policy/base.rb in pragma-policy-2.0.0 vs lib/pragma/policy/base.rb in pragma-policy-2.1.0

- old
+ new

@@ -5,50 +5,20 @@ # This is the base policy class that all your record-specific policies should inherit from. # # A policy provides predicate methods for determining whether a user can perform a specific # action on a record. # - # @author Alessandro Desantis - # # @abstract Subclass and implement action methods to create a policy. class Base - # Authorizes AR scopes and other relations by only returning the records accessible by the - # current user. Used, for instance, in index operations. - # - # @author Alessandro Desantis - class Scope - # @!attribute [r] user - # @return [Object] the user accessing the records - # - # @!attribute [r] scope - # @return [Object] the relation to use as a base - attr_reader :user, :scope + Scope = ::Pragma::Policy::Scope - # Initializes the scope. - # - # @param user [Object] the user accessing the records - # @param scope [Object] the relation to use as a base - def initialize(user, scope) - @user = user - @scope = scope - end - - # Returns the records accessible by the given user. - # - # @return [Object] - # - # @abstract Override to implement retrieving the accessible records - def resolve - fail NotImplementedError - end - end - # @!attribute [r] user # @return [Object] the user operating on the record # # @!attribute [r] record # @return [Object] the record being operated on attr_reader :user, :record + alias context user # Initializes the policy. # # @param user [Object] the user operating on the record # @param record [Object] the record being operated on