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]


71
72
73
74
75
76
77
78
79
# File 'lib/pundit.rb', line 71

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



60
61
62
63
64
65
66
67
# File 'lib/pundit.rb', line 60

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]


92
93
94
# File 'lib/pundit.rb', line 92

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!]


97
98
99
# File 'lib/pundit.rb', line 97

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]


82
83
84
# File 'lib/pundit.rb', line 82

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!]


87
88
89
# File 'lib/pundit.rb', line 87

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