Class: GraphQL::AuthorizationHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql-pundit.rb

Overview

Defines ‘authorize` and `authorize!` helpers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raise_unauthorized) ⇒ AuthorizationHelper

Returns a new instance of AuthorizationHelper.



14
15
16
# File 'lib/graphql-pundit.rb', line 14

def initialize(raise_unauthorized)
  @raise_unauthorized = raise_unauthorized
end

Instance Attribute Details

#raise_unauthorizedObject (readonly)

Returns the value of attribute raise_unauthorized.



12
13
14
# File 'lib/graphql-pundit.rb', line 12

def raise_unauthorized
  @raise_unauthorized
end

Instance Method Details

#call(defn, query = nil, policy: nil, record: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/graphql-pundit.rb', line 18

def call(defn, query = nil, policy: nil, record: nil)
  opts = {record: record,
          query: query || defn.name,
          policy: policy,
          raise: raise_unauthorized}
  if query.respond_to?(:call)
    opts = {proc: query, raise: raise_unauthorized}
  end
  Define::InstanceDefinable::AssignMetadataKey.new(:authorize).
    call(defn, opts)
end