introspective_grape 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +13 -37
- data/CHANGELOG.md +7 -0
- data/gemfiles/2.2.0-Gemfile +1 -1
- data/gemfiles/Gemfile.rails.4.2.10 +12 -0
- data/gemfiles/Gemfile.rails.4.2.7.1 +1 -0
- data/gemfiles/Gemfile.rails.4.2.7.1.new.swagger +1 -0
- data/gemfiles/Gemfile.rails.4.2.8 +2 -0
- data/gemfiles/Gemfile.rails.5.0.0 +13 -0
- data/gemfiles/Gemfile.rails.5.0.1 +1 -1
- data/gemfiles/Gemfile.rails.5.1.0 +13 -0
- data/gemfiles/Gemfile.rails.5.2.0 +13 -0
- data/gemfiles/Gemfile.rails.6.0.0.beta1 +13 -0
- data/gemfiles/Gemfile.rails.master +1 -1
- data/introspective_grape.gemspec +11 -11
- data/lib/introspective_grape/api.rb +28 -29
- data/lib/introspective_grape/camel_snake.rb +30 -31
- data/lib/introspective_grape/create_helpers.rb +2 -2
- data/lib/introspective_grape/version.rb +1 -1
- data/spec/dummy/Gemfile +6 -4
- data/spec/dummy/app/models/role.rb +1 -1
- data/spec/dummy/app/models/user.rb +2 -2
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/environments/development.rb +3 -3
- data/spec/dummy/config/initializers/paperclip_adapter.rb +1 -1
- data/spec/requests/chat_api_spec.rb +26 -26
- data/spec/requests/company_api_spec.rb +15 -15
- data/spec/requests/location_api_spec.rb +18 -18
- data/spec/requests/project_api_spec.rb +20 -20
- data/spec/requests/role_api_spec.rb +4 -4
- data/spec/requests/sessions_api_spec.rb +10 -10
- data/spec/requests/swagger_spec.rb +1 -1
- data/spec/requests/user_api_spec.rb +34 -36
- metadata +29 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daa5779c5e6121c36862f5c3158c1b8d5cf5ebdd
|
4
|
+
data.tar.gz: d48b10b855364975e10bb605ef4a005cd9231dac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b96dcd7acfecfbc9e84b05560f878bbbbab5eecf7c2deb5072551449ccb64dea6c5171585782ebf5274915c71bc95288984d9cf496979cd864466f78d326dfd1
|
7
|
+
data.tar.gz: 9d73edaf90c44038289bae9dd5f8391519830f9646cbef922d4a0a28a9b0d425c1b29cf6ca2a685eddc0ce0c10eef4f941fec39963b09d6d0e9f6e56e9c4742f
|
data/.travis.yml
CHANGED
@@ -1,77 +1,53 @@
|
|
1
1
|
language: ruby
|
2
2
|
before_install:
|
3
|
-
- gem install bundler
|
3
|
+
- gem install bundler -v 1.17.3
|
4
4
|
install: bundle install --jobs=1 --retry=1
|
5
5
|
script:
|
6
6
|
- bundle install
|
7
7
|
- bundle exec rspec
|
8
8
|
|
9
9
|
rvm:
|
10
|
-
- 2.0.0
|
11
|
-
- 2.1.0
|
12
|
-
- 2.2.
|
13
|
-
- 2.
|
14
|
-
- 2.3.0
|
10
|
+
# - 2.0.0
|
11
|
+
# - 2.1.0
|
12
|
+
- 2.2.2
|
13
|
+
- 2.3.1
|
15
14
|
- 2.4.0
|
16
15
|
- ruby-head
|
17
16
|
- jruby-head
|
18
17
|
gemfile:
|
19
18
|
# - gemfiles/Gemfile.rails.3.2.22
|
20
19
|
# - gemfiles/Gemfile.rails.4.1.13
|
21
|
-
- gemfiles/Gemfile.rails.4.2.7.1
|
22
|
-
- gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
23
|
-
- gemfiles/Gemfile.rails.4.2.8
|
20
|
+
# - gemfiles/Gemfile.rails.4.2.7.1
|
21
|
+
# - gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
22
|
+
# - gemfiles/Gemfile.rails.4.2.8
|
23
|
+
# - gemfiles/Gemfile.rails.5.0.0
|
24
24
|
- gemfiles/Gemfile.rails.5.0.1
|
25
|
+
- gemfiles/Gemfile.rails.5.1.0
|
26
|
+
- gemfiles/Gemfile.rails.5.2.0
|
25
27
|
- gemfiles/Gemfile.rails.master
|
28
|
+
- gemfiles/Gemfile.6.0.0.beta
|
26
29
|
|
27
30
|
matrix:
|
28
31
|
exclude:
|
29
32
|
# We'll have to back up to grape-swagger 0.11 for earlier rubies.
|
30
|
-
- rvm: 2.0.0
|
31
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
32
|
-
- rvm: 2.0.0
|
33
|
-
gemfile: gemfiles/Gemfile.rails.4.2.8
|
34
33
|
- rvm: 2.0.0
|
35
34
|
gemfile: gemfiles/Gemfile.rails.5.0.1
|
36
35
|
- rvm: 2.0.0
|
37
36
|
gemfile: gemfiles/Gemfile.rails.master
|
38
|
-
- rvm: 2.1.0
|
39
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
40
|
-
- rvm: 2.1.0
|
41
|
-
gemfile: gemfiles/Gemfile.rails.4.2.8
|
42
37
|
- rvm: 2.1.0
|
43
38
|
gemfile: gemfiles/Gemfile.rails.5.0.1
|
44
39
|
- rvm: 2.1.0
|
45
40
|
gemfile: gemfiles/Gemfile.rails.master
|
46
|
-
- rvm: 2.2.0
|
47
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
48
|
-
- rvm: 2.2.0
|
49
|
-
gemfile: gemfiles/Gemfile.rails.4.2.8
|
50
41
|
- rvm: 2.2.0
|
51
42
|
gemfile: gemfiles/Gemfile.rails.5.0.1
|
52
43
|
- rvm: 2.2.0
|
53
44
|
gemfile: gemfiles/Gemfile.rails.master
|
54
|
-
- rvm: 2.4.0
|
55
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1
|
56
|
-
- rvm: 2.4.0
|
57
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
58
|
-
- rvm: jruby-9.0.4.0
|
59
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
60
|
-
- rvm: jruby-9.0.4.0
|
61
|
-
gemfile: gemfiles/Gemfile.rails.4.2.8
|
62
45
|
- rvm: jruby-9.0.4.0
|
63
46
|
gemfile: gemfiles/Gemfile.rails.5.0.1
|
64
47
|
- rvm: jruby-9.0.4.0
|
65
48
|
gemfile: gemfiles/Gemfile.rails.master
|
66
|
-
- rvm: ruby-head
|
67
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1
|
68
|
-
- rvm: ruby-head
|
69
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
70
|
-
- rvm: jruby-head
|
71
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1
|
72
|
-
- rvm: jruby-head
|
73
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
74
49
|
allow_failures:
|
50
|
+
- gemfile: gemfiles/Gemfile.6.0.0.beta1
|
75
51
|
- rvm: ruby-head
|
76
52
|
- rvm: jruby-head
|
77
53
|
|
data/CHANGELOG.md
CHANGED
data/gemfiles/2.2.0-Gemfile
CHANGED
data/introspective_grape.gemspec
CHANGED
@@ -18,25 +18,25 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.files = `git ls-files`.split("\n").sort
|
19
19
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
20
20
|
|
21
|
-
s.required_ruby_version = '~> 2.
|
21
|
+
s.required_ruby_version = '~> 2.1'
|
22
22
|
|
23
|
-
|
24
|
-
s.add_dependency "rails", '>= 3.0.0', '<5.0'
|
23
|
+
s.add_dependency "rails", '> 5.0.0'
|
25
24
|
|
26
|
-
|
27
|
-
s.add_dependency 'grape
|
28
|
-
s.add_dependency 'grape-
|
29
|
-
s.add_dependency '
|
25
|
+
# grape 1.0.0 breaks the pagination solution
|
26
|
+
s.add_dependency 'grape', '< 1.0.0'
|
27
|
+
s.add_dependency 'grape-entity'
|
28
|
+
s.add_dependency 'grape-swagger'
|
29
|
+
s.add_dependency 'kaminari', '< 1.0' # version 1.0.0 breaks
|
30
30
|
s.add_dependency 'grape-kaminari'
|
31
31
|
# Pundit 2.0 mysteriously made authorize a protected method...
|
32
|
-
s.add_dependency 'pundit'
|
32
|
+
s.add_dependency 'pundit' #, '<2.0'
|
33
33
|
s.add_dependency 'camel_snake_keys', '>0.0.4'
|
34
34
|
|
35
35
|
if RUBY_PLATFORM == 'java'
|
36
36
|
#s.add_development_dependency "jdbc-sqlite3"
|
37
37
|
s.add_development_dependency "activerecord-jdbcsqlite3-adapter"
|
38
38
|
else
|
39
|
-
s.add_development_dependency "sqlite3"
|
39
|
+
s.add_development_dependency "sqlite3", '<1.4.0' #'< 1.3.14'
|
40
40
|
end
|
41
41
|
|
42
42
|
#s.add_development_dependency "byebug"
|
@@ -44,8 +44,8 @@ Gem::Specification.new do |s|
|
|
44
44
|
s.add_development_dependency "rspec-rails", '>= 3.0'
|
45
45
|
s.add_development_dependency 'devise'
|
46
46
|
#s.add_development_dependency 'devise-async'
|
47
|
-
s.add_development_dependency 'paperclip', '< 5.0'
|
48
|
-
s.add_development_dependency '
|
47
|
+
s.add_development_dependency 'paperclip', ">= 5.2.0" #'< 5.0'
|
48
|
+
s.add_development_dependency 'machinist_redux'
|
49
49
|
s.add_development_dependency 'simplecov'
|
50
50
|
s.add_development_dependency 'rufus-mnemo'
|
51
51
|
|
@@ -125,6 +125,34 @@ module IntrospectiveGrape
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
+
def convert_nested_params_hash(dsl, routes)
|
129
|
+
root = routes.first
|
130
|
+
klass = root.klass
|
131
|
+
dsl.after_validation do
|
132
|
+
# After Grape validates its parameters:
|
133
|
+
# 1) Find the root model instance for the API if its passed (implicitly either
|
134
|
+
# an update/destroy on the root node or it's a nested route
|
135
|
+
# 2) For nested endpoints convert the params hash into Rails-compliant nested
|
136
|
+
# attributes, to be passed to the root instance for update. This keeps
|
137
|
+
# behavior consistent between bulk and single record updates.
|
138
|
+
|
139
|
+
if params[root.key]
|
140
|
+
@model = root.model.includes( klass.default_includes(root.model) ).find(params[root.key])
|
141
|
+
end
|
142
|
+
|
143
|
+
if routes.size > 1
|
144
|
+
nested_attributes = klass.build_nested_attributes(routes[1..-1], params.except(root.key,:api_key) )
|
145
|
+
@params.merge!( nested_attributes ) if nested_attributes.kind_of?(Hash)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def define_restful_api(dsl, routes, model, api_params)
|
151
|
+
# declare index, show, update, create, and destroy methods:
|
152
|
+
API_ACTIONS.each do |action|
|
153
|
+
send("define_#{action}", dsl, routes, model, api_params) unless exclude_actions(model).include?(action)
|
154
|
+
end
|
155
|
+
end
|
128
156
|
|
129
157
|
def define_endpoints(routes,api_params)
|
130
158
|
# De-reference these as local variables from their class scope, or when we make
|
@@ -145,13 +173,6 @@ module IntrospectiveGrape
|
|
145
173
|
end
|
146
174
|
end
|
147
175
|
|
148
|
-
def define_restful_api(dsl, routes, model, api_params)
|
149
|
-
# declare index, show, update, create, and destroy methods:
|
150
|
-
API_ACTIONS.each do |action|
|
151
|
-
send("define_#{action}", dsl, routes, model, api_params) unless exclude_actions(model).include?(action)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
176
|
def define_index(dsl, routes, model, api_params)
|
156
177
|
include Grape::Kaminari
|
157
178
|
root = routes.first
|
@@ -244,28 +265,6 @@ module IntrospectiveGrape
|
|
244
265
|
end
|
245
266
|
end
|
246
267
|
|
247
|
-
def convert_nested_params_hash(dsl, routes)
|
248
|
-
root = routes.first
|
249
|
-
klass = root.klass
|
250
|
-
dsl.after_validation do
|
251
|
-
# After Grape validates its parameters:
|
252
|
-
# 1) Find the root model instance for the API if its passed (implicitly either
|
253
|
-
# an update/destroy on the root node or it's a nested route
|
254
|
-
# 2) For nested endpoints convert the params hash into Rails-compliant nested
|
255
|
-
# attributes, to be passed to the root instance for update. This keeps
|
256
|
-
# behavior consistent between bulk and single record updates.
|
257
|
-
|
258
|
-
if params[root.key]
|
259
|
-
@model = root.model.includes( klass.default_includes(root.model) ).find(params[root.key])
|
260
|
-
end
|
261
|
-
|
262
|
-
if routes.size > 1
|
263
|
-
nested_attributes = klass.build_nested_attributes(routes[1..-1], params.except(root.key,:api_key) )
|
264
|
-
@params.merge!( nested_attributes ) if nested_attributes.kind_of?(Hash)
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
268
|
|
270
269
|
def build_routes(routes, model, reflection_name=nil)
|
271
270
|
routes = routes.clone
|
@@ -5,49 +5,48 @@ require 'active_support/inflector/methods'
|
|
5
5
|
if IntrospectiveGrape.config.camelize_parameters
|
6
6
|
# Camelize the parameters in the swagger documentation.
|
7
7
|
if Gem::Version.new( GrapeSwagger::VERSION ) <= Gem::Version.new('0.11.0')
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
.camelize(:lower)
|
20
|
-
.gsub(/Destroy/,'_destroy')
|
21
|
-
end
|
22
|
-
parsed_params
|
23
|
-
end
|
8
|
+
module ParseParamsWithCamelized
|
9
|
+
def parse_params(params, path, method, _options = {})
|
10
|
+
parsed_params = parse_params_without_camelized(params, path, method)
|
11
|
+
parsed_params.each_with_index do |param|
|
12
|
+
param[:name] = param[:name]
|
13
|
+
.camelize(:lower)
|
14
|
+
.gsub(/Destroy/,'_destroy')
|
15
|
+
end
|
16
|
+
super(params, path, method, _options = {})
|
17
|
+
end
|
18
|
+
end
|
24
19
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
module CreateCamelizedDocumentationClass
|
21
|
+
private
|
22
|
+
def create_documentation_class
|
23
|
+
doc = super
|
24
|
+
doc.class_eval do
|
25
|
+
doc.singleton_class.send(:prepend, ParseParamsWithCamelized)
|
29
26
|
end
|
30
|
-
|
27
|
+
doc
|
31
28
|
end
|
32
29
|
end
|
30
|
+
|
31
|
+
Grape::API.singleton_class.send(:prepend, CreateCamelizedDocumentationClass)
|
33
32
|
else
|
33
|
+
module CallWithCamelized
|
34
|
+
def call(*args)
|
35
|
+
param = super(*args)
|
36
|
+
param[:name] = param[:name].camelize(:lower).gsub(/Destroy/, '_destroy')
|
37
|
+
param
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
GrapeSwagger::DocMethods::ParseParams.singleton_class.send(:prepend, CallWithCamelized)
|
34
42
|
module GrapeSwagger
|
35
43
|
module DocMethods
|
36
44
|
def self.extended(mod)
|
37
45
|
# Do not camelize the grape-swagger documentation endpoints.
|
38
46
|
mod.formatter :json, Grape::Formatter::Json
|
39
47
|
end
|
40
|
-
class ParseParams
|
41
|
-
class << self
|
42
|
-
def call_with_camelized(*args)
|
43
|
-
param = call_without_camelized(*args)
|
44
|
-
param[:name] = param[:name].camelize(:lower).gsub(/Destroy/, '_destroy')
|
45
|
-
param
|
46
|
-
end
|
47
|
-
alias_method_chain :call, :camelized
|
48
|
-
end
|
49
|
-
end
|
50
48
|
end
|
51
49
|
end
|
52
50
|
end
|
51
|
+
|
53
52
|
end
|