lib/pundit.rb in pundit-0.2.1 vs lib/pundit.rb in pundit-0.2.2

- old
+ new

@@ -10,21 +10,21 @@ extend ActiveSupport::Concern class << self def policy_scope(user, scope) - policy = PolicyFinder.new(scope).scope - policy.new(user, scope).resolve if policy + policy_scope = PolicyFinder.new(scope).scope + policy_scope.new(user, scope).resolve if policy_scope end def policy_scope!(user, scope) PolicyFinder.new(scope).scope!.new(user, scope).resolve end def policy(user, record) - scope = PolicyFinder.new(record).policy - scope.new(user, record) if scope + policy = PolicyFinder.new(record).policy + policy.new(user, record) if policy end def policy!(user, record) PolicyFinder.new(record).policy!.new(user, record) end @@ -32,15 +32,17 @@ included do if respond_to?(:helper_method) helper_method :policy_scope helper_method :policy + helper_method :pundit_user end if respond_to?(:hide_action) hide_action :authorize hide_action :verify_authorized hide_action :verify_policy_scoped + hide_action :pundit_user end end def verify_authorized raise NotAuthorizedError unless @_policy_authorized @@ -59,12 +61,18 @@ true end def policy_scope(scope) @_policy_scoped = true - Pundit.policy_scope!(current_user, scope) + @policy_scope or Pundit.policy_scope!(pundit_user, scope) end + attr_writer :policy_scope def policy(record) - Pundit.policy!(current_user, record) + @policy or Pundit.policy!(pundit_user, record) + end + attr_writer :policy + + def pundit_user + current_user end end