Module: Pundit
- Defined in:
- lib/pundit.rb,
lib/pundit/error.rb,
lib/pundit/rspec.rb,
lib/pundit/helper.rb,
lib/pundit/context.rb,
lib/pundit/railtie.rb,
lib/pundit/version.rb,
lib/pundit/cache_store.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
Overview
Hello? Yes, this is Pundit.
Defined Under Namespace
Modules: Authorization, CacheStore, Generators, Helper, RSpec
Classes: AuthorizationNotPerformedError, Context, Error, InvalidConstructorError, NotAuthorizedError, NotDefinedError, PolicyFinder, PolicyScopingNotPerformedError, Railtie
Constant Summary
collapse
- SUFFIX =
This constant is part of a private API.
You should avoid using this constant if possible, as it may be removed or be changed in the future.
Pundit::PolicyFinder::SUFFIX
- VERSION =
The current version of Pundit.
"2.5.2"
Class Method Summary
collapse
-
.authorize(user, record, query, policy_class: nil, cache: nil) ⇒ Object
-
.included(base) ⇒ Object
-
.policy(user, *args, **kwargs, &block) ⇒ Object
-
.policy!(user, *args, **kwargs, &block) ⇒ Object
-
.policy_scope(user, *args, **kwargs, &block) ⇒ Object
-
.policy_scope!(user, *args, **kwargs, &block) ⇒ Object
Class Method Details
.authorize(user, record, query, policy_class: nil, cache: nil) ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/pundit.rb', line 42
def authorize(user, record, query, policy_class: nil, cache: nil)
context = if cache
policy_cache = CacheStore::LegacyStore.new(cache)
Context.new(user: user, policy_cache: policy_cache)
else
Context.new(user: user)
end
context.authorize(record, query: query, policy_class: policy_class)
end
|
.included(base) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/pundit.rb', line 30
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
67
68
69
|
# File 'lib/pundit.rb', line 67
def policy(user, *args, **kwargs, &block)
Context.new(user: user).policy(*args, **kwargs, &block)
end
|
.policy!(user, *args, **kwargs, &block) ⇒ Object
73
74
75
|
# File 'lib/pundit.rb', line 73
def policy!(user, *args, **kwargs, &block)
Context.new(user: user).policy!(*args, **kwargs, &block)
end
|
.policy_scope(user, *args, **kwargs, &block) ⇒ Object
55
56
57
|
# File 'lib/pundit.rb', line 55
def policy_scope(user, *args, **kwargs, &block)
Context.new(user: user).policy_scope(*args, **kwargs, &block)
end
|
.policy_scope!(user, *args, **kwargs, &block) ⇒ Object
61
62
63
|
# File 'lib/pundit.rb', line 61
def policy_scope!(user, *args, **kwargs, &block)
Context.new(user: user).policy_scope!(*args, **kwargs, &block)
end
|