Module: WellFormed::Pundit
- Defined in:
- lib/well_formed/pundit.rb,
lib/well_formed/pundit/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Method Summary collapse
-
#authorize!(record_or_query, query = nil) ⇒ Object
Raises Pundit::NotAuthorizedError if the user is not authorized for the given query.
-
#policy(record = resource) ⇒ Object
Returns the Pundit policy instance for the given record (defaults to resource).
-
#policy_scope(collection) ⇒ Object
Returns the scoped collection for the current user.
Instance Method Details
#authorize!(record_or_query, query = nil) ⇒ Object
Raises Pundit::NotAuthorizedError if the user is not authorized for the given query. Optionally pass an explicit record as the first argument; defaults to resource.
17 18 19 20 21 22 23 |
# File 'lib/well_formed/pundit.rb', line 17 def (record_or_query, query = nil) if query.nil? ::Pundit.(user, resource, record_or_query) else ::Pundit.(user, record_or_query, query) end end |
#policy(record = resource) ⇒ Object
Returns the Pundit policy instance for the given record (defaults to resource).
6 7 8 |
# File 'lib/well_formed/pundit.rb', line 6 def policy(record = resource) ::Pundit::PolicyFinder.new(record).policy!.new(user, record) end |
#policy_scope(collection) ⇒ Object
Returns the scoped collection for the current user.
11 12 13 |
# File 'lib/well_formed/pundit.rb', line 11 def policy_scope(collection) ::Pundit::PolicyFinder.new(collection).scope!.new(user, collection).resolve end |