graphql-pundit 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ce932c3e90158e8692934bac208942e9a10faa9
4
- data.tar.gz: 87858e55cab3ec052e5756b66ebb5fa2285e4dc8
3
+ metadata.gz: 4d29e967add746973f9b8b17927d9cb4929e01a3
4
+ data.tar.gz: 345db8210f01ccde612dab0e6d46138e6320e2ee
5
5
  SHA512:
6
- metadata.gz: 5fd1f0da13f241e13bcf145adadb710f256a36418049b93c56674c1d10dc3cf1d3fc3bf75773eb49fd3b72ff0d1057ec2949d3fd1b5bfebbdb6279641fcbe67a
7
- data.tar.gz: 86d4a7a066b99752538caf1e60f554939e514af4a7fe86138ac6d85c5a2a389aef2bb0486f756b90972eb5140e4088854fc682173645b0276ac02f10ed29c077
6
+ metadata.gz: 421f7515bad6de63018207fc5a8c0efc0b8e1450f2aef126ee4103d9fcba00a936183a2c6d89091349c57953b4b83da254e7a8596dbfd4a65b6187c100dc177c
7
+ data.tar.gz: f79f667733fb0c4515ac9917dee32220a8df70cc0c52c38911525face5421e39c17edd3f6aa6e48cfd80bd759f1b1db952996a837182ea980dd5e6b24338387f
data/README.md CHANGED
@@ -112,6 +112,15 @@ field :posts
112
112
  end
113
113
  ```
114
114
 
115
+ In case you only want to specify the Policy class containing the Scope explicitly, you can pass the Policy class explicitly:
116
+
117
+ ```ruby
118
+ field :posts
119
+ scope PostablePolicy
120
+ resolve ...
121
+ end
122
+ ```
123
+
115
124
  ## Development
116
125
 
117
126
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -23,16 +23,6 @@ module GraphQL
23
23
  scoped_field = scope_instrumenter.instrument(type, field)
24
24
  authorization_instrumenter.instrument(type, scoped_field)
25
25
  end
26
-
27
- def authorize(current_user, obj, args, ctx, options)
28
- if options[:proc]
29
- options[:proc].call(obj, args, ctx)
30
- else
31
- ::Pundit.authorize(ctx[current_user],
32
- options[:record] || obj,
33
- options[:query].to_s + '?')
34
- end
35
- end
36
26
  end
37
27
  end
38
28
  end
@@ -25,6 +25,10 @@ module GraphQL
25
25
  old_resolve = field.resolve_proc
26
26
 
27
27
  scope_proc = lambda do |obj, _args, ctx|
28
+ unless inferred?(scope)
29
+ obj.define_singleton_method(:policy_class) { scope }
30
+ end
31
+
28
32
  ::Pundit.policy_scope!(ctx[current_user], obj)
29
33
  end
30
34
  scope_proc = scope if proc?(scope)
@@ -40,7 +44,7 @@ module GraphQL
40
44
  private
41
45
 
42
46
  def valid_value?(value)
43
- inferred?(value) || proc?(value)
47
+ value.is_a?(Class) || inferred?(value) || proc?(value)
44
48
  end
45
49
 
46
50
  def proc?(value)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module Pundit
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-pundit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ontohub Core Developers