Class: GraphQR::Policies::PunditProvider
- Inherits:
-
Object
- Object
- GraphQR::Policies::PunditProvider
- Defined in:
- lib/graphqr/policies/pundit_provider.rb
Overview
TODO: add documentation
Instance Attribute Summary collapse
-
#policy_context ⇒ Object
readonly
Returns the value of attribute policy_context.
Instance Method Summary collapse
- #allowed?(action:, record:, policy_class: nil) ⇒ Boolean
- #authorized_records(records:) ⇒ Object
-
#initialize(policy_context:) ⇒ PunditProvider
constructor
A new instance of PunditProvider.
- #permitted_field?(record:, field_name:) ⇒ Boolean
Constructor Details
#initialize(policy_context:) ⇒ PunditProvider
Returns a new instance of PunditProvider.
12 13 14 |
# File 'lib/graphqr/policies/pundit_provider.rb', line 12 def initialize(policy_context:) @policy_context = policy_context end |
Instance Attribute Details
#policy_context ⇒ Object (readonly)
Returns the value of attribute policy_context.
10 11 12 |
# File 'lib/graphqr/policies/pundit_provider.rb', line 10 def policy_context @policy_context end |
Instance Method Details
#allowed?(action:, record:, policy_class: nil) ⇒ Boolean
16 17 18 19 20 |
# File 'lib/graphqr/policies/pundit_provider.rb', line 16 def allowed?(action:, record:, policy_class: nil) policy = policy_for(record: record, policy_class: policy_class) policy.apply(action) end |
#authorized_records(records:) ⇒ Object
22 23 24 |
# File 'lib/graphqr/policies/pundit_provider.rb', line 22 def (records:) Pundit.policy_scope(policy_context, records) end |
#permitted_field?(record:, field_name:) ⇒ Boolean
26 27 28 29 30 |
# File 'lib/graphqr/policies/pundit_provider.rb', line 26 def permitted_field?(record:, field_name:) policy = policy_for(record: record) policy.permitted_fields.include?(field_name) end |