Module: Pundit

Defined in:
lib/pundit.rb,
lib/pundit/rspec.rb,
lib/pundit/context.rb,
lib/pundit/version.rb,
lib/pundit/authorization.rb,
lib/pundit/policy_finder.rb,
lib/pundit/cache_store/null_store.rb,
lib/pundit/cache_store/legacy_store.rb,
lib/generators/pundit/policy/policy_generator.rb,
lib/generators/pundit/install/install_generator.rb

Defined Under Namespace

Classes: AuthorizationNotPerformedError, InvalidConstructorError, NotAuthorizedError, NotDefinedError, PolicyFinder, PolicyScopingNotPerformedError

Constant Summary collapse

SUFFIX =
"Policy"

Class Method Summary collapse

Class Method Details

.authorize(user, record, query, policy_class: nil, cache: nil) ⇒ Object

See Also:

  • [Pundit[Pundit::Context[Pundit::Context#authorize]


74
75
76
77
78
79
80
81
82
# File 'lib/pundit.rb', line 74

def authorize(user, record, query, policy_class: nil, cache: nil)
  context = if cache
    Context.new(user: user, policy_cache: cache)
  else
    Context.new(user: user)
  end

  context.authorize(record, query: query, policy_class: policy_class)
end

.included(base) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/pundit.rb', line 63

def self.included(base)
  location = caller_locations(1, 1).first
  warn <<~WARNING
    'include Pundit' is deprecated. Please use 'include Pundit::Authorization' instead.
     (called from #{location.label} at #{location.path}:#{location.lineno})
  WARNING
  base.include Authorization
end

.policy(user, *args, **kwargs, &block) ⇒ Object

See Also:

  • [Pundit[Pundit::Context[Pundit::Context#policy]


95
96
97
# File 'lib/pundit.rb', line 95

def policy(user, *args, **kwargs, &block)
  Context.new(user: user).policy(*args, **kwargs, &block)
end

.policy!(user, *args, **kwargs, &block) ⇒ Object

See Also:

  • [Pundit[Pundit::Context[Pundit::Context#policy!]


100
101
102
# File 'lib/pundit.rb', line 100

def policy!(user, *args, **kwargs, &block)
  Context.new(user: user).policy!(*args, **kwargs, &block)
end

.policy_scope(user, *args, **kwargs, &block) ⇒ Object

See Also:

  • [Pundit[Pundit::Context[Pundit::Context#policy_scope]


85
86
87
# File 'lib/pundit.rb', line 85

def policy_scope(user, *args, **kwargs, &block)
  Context.new(user: user).policy_scope(*args, **kwargs, &block)
end

.policy_scope!(user, *args, **kwargs, &block) ⇒ Object

See Also:

  • [Pundit[Pundit::Context[Pundit::Context#policy_scope!]


90
91
92
# File 'lib/pundit.rb', line 90

def policy_scope!(user, *args, **kwargs, &block)
  Context.new(user: user).policy_scope!(*args, **kwargs, &block)
end