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.



17
18
19
# File 'lib/graphql-pundit.rb', line 17

def initialize(raise_unauthorized)
  @raise_unauthorized = raise_unauthorized
end

Instance Attribute Details

#raise_unauthorizedObject (readonly)

Returns the value of attribute raise_unauthorized.



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

def raise_unauthorized
  @raise_unauthorized
end

Instance Method Details

#call(defn, *args, policy: nil, record: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/graphql-pundit.rb', line 21

def call(defn, *args, policy: nil, record: nil)
  query = args[0] || defn.name
  opts = {record: record,
          query: query,
          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