class Pragma::Policy::Pundit
Provides a simple way for Pragma
policies to delegate to Pundit
policies/scopes.
@example
class API::V1::Article::Policy < Pragma::Policy::Pundit # The default would be ArticlePolicy. self.pundit_klass = CustomArticlePolicy end
Attributes
pundit_klass[W]
Public Class Methods
inherited(base)
click to toggle source
# File lib/pragma/policy/pundit.rb, line 20 def inherited(base) base.class_eval <<~RUBY, __FILE__, __LINE__ + 1 class Scope < Pragma::Policy::Scope def initialize(user, scope) super @pundit_scope = pundit_scope_klass.new(user, scope) end def resolve @pundit_scope.resolve end private def pundit_scope_klass policy_klass.pundit_klass.const_get('Scope') end end RUBY end
new(user, record)
click to toggle source
Calls superclass method
Pragma::Policy::Base::new
# File lib/pragma/policy/pundit.rb, line 42 def initialize(user, record) super @pundit_policy = self.class.pundit_klass.new(user, record) end
pundit_klass()
click to toggle source
# File lib/pragma/policy/pundit.rb, line 16 def pundit_klass @pundit_klass ||= Object.const_get("#{self.class.name.split('::')[-2]}Policy") end
Public Instance Methods
method_missing(method_name, *args, &block)
click to toggle source
Calls superclass method
Pragma::Policy::Base#method_missing
# File lib/pragma/policy/pundit.rb, line 51 def method_missing(method_name, *args, &block) return super unless @pundit_policy.respond_to?(method_name) @pundit_policy.send(method_name, *args, &block) end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
Pragma::Policy::Base#respond_to_missing?
# File lib/pragma/policy/pundit.rb, line 47 def respond_to_missing?(method_name, include_private = false) super || @pundit_policy.respond_to?("#{method_name[0..-2]}?", include_private) end