introspective_grape 0.3.3 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/introspective_grape.gemspec +4 -2
- data/lib/introspective_grape/api.rb +5 -3
- data/lib/introspective_grape/create_helpers.rb +6 -1
- data/lib/introspective_grape/version.rb +1 -1
- data/spec/dummy/app/models/image.rb +1 -1
- data/spec/requests/user_api_spec.rb +2 -0
- metadata +13 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a3c90f61cd6c0cfcc681b4c4c37f1b888bfe7fd
|
4
|
+
data.tar.gz: 26e6dcb9a96899eaaf5c298d9ffe7c48e6d43ea4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a11bec2f1cde26753b08898c14ba54339f6a984be48f1eea1090c4f585146d2db4c35980481852f02b4f1c1a78090a7ff0da25238dd4b27da76281c1ae0e9080
|
7
|
+
data.tar.gz: d1e1a33bbab8952ca376c1ebc52a9c55c379405698c2479af8898500ff924437578fedb37b1743dc3494674fa5fc6b81d8486d7dfbbcb2637515afe05c2e51e2
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
|
2
|
+
0.3.5 09/14/2018
|
3
|
+
================
|
4
|
+
|
5
|
+
Restrict IntrospectiveGrape to Rails <5.0 and Pundit <2.0. We aren't Rails 5 compat until either schema_plus is or we find an alternative. Pundit 2.0 very strangely makes 'authorize' a protected method and we haven't made time to investigate.
|
6
|
+
|
7
|
+
The big update in 0.3 is that the PUT/POST actions used to reload the model on presentation (hooks elsewhere may leave a model that's been updated out of sync with the database, so the overhead seems to be necessary) without using the default_includes for eager loading, causing some N+1 problems that could be alleviated.
|
8
|
+
|
9
|
+
The general strategy of passing the params of a nested endpoint to the root model and then reloading it and burrowing down to the leaf for presentation, while simpler to implement, was really not optimal and creates a lot of unnecessary overhead like that.
|
10
|
+
|
11
|
+
|
2
12
|
0.2.9 04/06/2017
|
3
13
|
================
|
4
14
|
|
data/introspective_grape.gemspec
CHANGED
@@ -20,14 +20,16 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
s.required_ruby_version = '~> 2.0'
|
22
22
|
|
23
|
-
|
23
|
+
# not yet 5+ compatible
|
24
|
+
s.add_dependency "rails", '>= 3.0.0', '<5.0'
|
24
25
|
|
25
26
|
s.add_dependency 'grape' #, '~> 0.16.2'
|
26
27
|
s.add_dependency 'grape-entity' #, '< 0.5.0'
|
27
28
|
s.add_dependency 'grape-swagger' #, '~>0.11.0'
|
28
29
|
s.add_dependency 'kaminari', '< 1.0' # There's a version 1.0.0 out there that breaks everything
|
29
30
|
s.add_dependency 'grape-kaminari'
|
30
|
-
|
31
|
+
# Pundit 2.0 mysteriously made authorize a protected method...
|
32
|
+
s.add_dependency 'pundit', '<2.0'
|
31
33
|
s.add_dependency 'camel_snake_keys', '>0.0.4'
|
32
34
|
|
33
35
|
if RUBY_PLATFORM == 'java'
|
@@ -225,8 +225,10 @@ module IntrospectiveGrape
|
|
225
225
|
authorize @model, :update?
|
226
226
|
|
227
227
|
@model.update_attributes!( safe_params(params).permit(klass.whitelist) )
|
228
|
+
|
229
|
+
default_includes = routes.first.klass.default_includes(routes.first.model)
|
228
230
|
|
229
|
-
present klass.find_leaf(routes, @model.
|
231
|
+
present klass.find_leaf(routes, @model.class.includes(default_includes).find(@model.id), params), with: "#{klass}::#{model}Entity".constantize
|
230
232
|
end
|
231
233
|
end
|
232
234
|
|
@@ -252,9 +254,9 @@ module IntrospectiveGrape
|
|
252
254
|
# 2) For nested endpoints convert the params hash into Rails-compliant nested
|
253
255
|
# attributes, to be passed to the root instance for update. This keeps
|
254
256
|
# behavior consistent between bulk and single record updates.
|
257
|
+
|
255
258
|
if params[root.key]
|
256
|
-
|
257
|
-
@model = root.model.includes( default_includes ).find(params[root.key])
|
259
|
+
@model = root.model.includes( klass.default_includes(root.model) ).find(params[root.key])
|
258
260
|
end
|
259
261
|
|
260
262
|
if routes.size > 1
|
@@ -15,7 +15,12 @@ module IntrospectiveGrape
|
|
15
15
|
model = routes.first.model.new( dsl.send(:safe_params,params).permit(whitelist) )
|
16
16
|
dsl.authorize model, :create?
|
17
17
|
model.save!
|
18
|
-
|
18
|
+
|
19
|
+
# reload the model with eager loading
|
20
|
+
default_includes = routes.first.klass.default_includes(routes.first.model)
|
21
|
+
model = model.class.includes(default_includes).find(model.id) if model.persisted?
|
22
|
+
|
23
|
+
find_leaves(routes, model, params)
|
19
24
|
end
|
20
25
|
|
21
26
|
end
|
@@ -3,7 +3,7 @@ require 'paperclip'
|
|
3
3
|
class Image < ActiveRecord::Base
|
4
4
|
belongs_to :imageable, polymorphic: true
|
5
5
|
|
6
|
-
has_attached_file :file, styles: {medium: "300x300>", thumb: "100x100"},
|
6
|
+
has_attached_file :file, #styles: {medium: "300x300>", thumb: "100x100"},
|
7
7
|
url: "/system/:imageable_type/:imageable_id/:id/:style/:filename"
|
8
8
|
|
9
9
|
validates_attachment :file, content_type: {content_type: ["image/jpeg", "image/png", "image/gif"]}
|
@@ -156,6 +156,7 @@ describe Dummy::UserAPI, type: :request do
|
|
156
156
|
|
157
157
|
put "/api/v1/users/#{user.id}", params
|
158
158
|
|
159
|
+
p response.body
|
159
160
|
response.should be_success
|
160
161
|
json['avatar_url'].should eq Image.last.file.url(:medium)
|
161
162
|
user.avatar.should eq Image.last
|
@@ -167,6 +168,7 @@ describe Dummy::UserAPI, type: :request do
|
|
167
168
|
|
168
169
|
post "/api/v1/users/#{user.id}/avatars", params
|
169
170
|
|
171
|
+
p response.body
|
170
172
|
response.should be_success
|
171
173
|
user.avatar.should == Image.last
|
172
174
|
user.avatar_url.should == Image.last.file.url(:medium)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: introspective_grape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Buermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 3.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: grape
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,16 +104,16 @@ dependencies:
|
|
98
104
|
name: pundit
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
100
106
|
requirements:
|
101
|
-
- - "
|
107
|
+
- - "<"
|
102
108
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
109
|
+
version: '2.0'
|
104
110
|
type: :runtime
|
105
111
|
prerelease: false
|
106
112
|
version_requirements: !ruby/object:Gem::Requirement
|
107
113
|
requirements:
|
108
|
-
- - "
|
114
|
+
- - "<"
|
109
115
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
116
|
+
version: '2.0'
|
111
117
|
- !ruby/object:Gem::Dependency
|
112
118
|
name: camel_snake_keys
|
113
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -431,7 +437,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
431
437
|
version: '0'
|
432
438
|
requirements: []
|
433
439
|
rubyforge_project:
|
434
|
-
rubygems_version: 2.
|
440
|
+
rubygems_version: 2.5.1
|
435
441
|
signing_key:
|
436
442
|
specification_version: 4
|
437
443
|
summary: Introspectively configure deeply nested RESTful Grape APIs for ActiveRecord
|