Nested class definition in concern

768 views Asked by At

I have pundit policy class which declares another class inside:

class PaymentPolicy < ApplicationPolicy
  class Scope < Scope
    def resolve
      return scope.all if user.root?
      scope.where(user: user)
    end
  end
end

Now I want to use this same inner Scope class in another place. One way is to define it in superclass and override, but to do that I have to create another class class NewClass < ApplicationPolicy and inherit PaymentPolicy from it. But I like ActiveSupport::Concern and don't know how to put a class definition inside concern module. This

module UserAllowed
  extend ActiveSupport::Concern
  included do
    class Scope < Scope
      def resolve
        return scope.all if user.root?
        scope.where(user: user)
      end
    end
  end
end

doesn't work. Neither this:

   module UserAllowed
      extend ActiveSupport::Concern
      class Scope < Scope
        def resolve
          return scope.all if user.root?
          scope.where(user: user
        end
      end
    end

How can I put nested class definition inside concern module?

0

There are 0 answers