apiql 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -0
- data/apiql.gemspec +1 -1
- data/assets/javascripts/apiql.js +1 -1
- data/lib/apiql.rb +5 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f103af812fb631ddf00a34acc478436d42d39fd1a66de8e2b0ee32a7023d159c
|
4
|
+
data.tar.gz: 2cf523c953d6ba31d3017183fe09353546a9d627869972e325342e732c7f1f6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 765875ac74538f510065377ffe052d0e5a75ed2b331b9883e142be064b57f76c74c9398afe4c001e3e9674a94d7844aa8e940d819f336c0589e0e13038ed7020
|
7
|
+
data.tar.gz: 4d82c9d04123de11ae47da1eaca5b0d2ecce4d212b1e828ec6b19a35f6a75e0332fae273a4c9368a9eb28494a9a64d2bceb1bf04230a7ac6899ead8d2343c035
|
data/README.md
CHANGED
@@ -110,6 +110,10 @@ config/initializers/apiql.rb:
|
|
110
110
|
class APIQL
|
111
111
|
delegate :authorize!, to: :@context
|
112
112
|
|
113
|
+
class Entity
|
114
|
+
delegate :authorize!, to: :@context
|
115
|
+
end
|
116
|
+
|
113
117
|
class Context
|
114
118
|
def authorize!(*args)
|
115
119
|
ability.authorize!(*args)
|
@@ -122,4 +126,22 @@ class APIQL
|
|
122
126
|
end
|
123
127
|
end
|
124
128
|
end
|
129
|
+
|
130
|
+
and authorize access to every entity:
|
131
|
+
|
132
|
+
class ApplicationRecord < ActiveRecord::Base
|
133
|
+
class BaseEntity < APIQL::Entity
|
134
|
+
def initialize(object, context)
|
135
|
+
context.authorize! :read, object
|
136
|
+
super(object, context)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
class User < ApplicationRecord
|
142
|
+
class Entity < BaseEntity
|
143
|
+
...
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
125
147
|
```
|
data/apiql.gemspec
CHANGED
data/assets/javascripts/apiql.js
CHANGED
data/lib/apiql.rb
CHANGED
@@ -313,7 +313,11 @@ class APIQL
|
|
313
313
|
elsif APIQL::simple_class?(value)
|
314
314
|
value
|
315
315
|
else
|
316
|
-
|
316
|
+
begin
|
317
|
+
"#{value.class.name}::Entity".constantize.new(value, self).render(schema)
|
318
|
+
rescue StandardError
|
319
|
+
nil
|
320
|
+
end
|
317
321
|
end
|
318
322
|
end
|
319
323
|
end
|