introspective_grape 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.travis.yml +16 -3
  4. data/CHANGELOG.md +16 -8
  5. data/README.md +6 -6
  6. data/gemfiles/2.0.0-Gemfile +1 -1
  7. data/gemfiles/Gemfile.rails.3.2.22 +1 -1
  8. data/gemfiles/Gemfile.rails.4.1.13 +1 -1
  9. data/gemfiles/Gemfile.rails.4.2.7.1 +1 -1
  10. data/gemfiles/Gemfile.rails.4.2.7.1.new.swagger +1 -1
  11. data/gemfiles/Gemfile.rails.4.2.8 +1 -1
  12. data/gemfiles/Gemfile.rails.5.0.1 +1 -1
  13. data/gemfiles/Gemfile.rails.master +1 -1
  14. data/introspective_grape.gemspec +2 -2
  15. data/lib/introspective_grape/api.rb +16 -16
  16. data/lib/introspective_grape/camel_snake.rb +5 -4
  17. data/lib/introspective_grape/filters.rb +2 -2
  18. data/lib/introspective_grape/formatter/camel_json.rb +12 -9
  19. data/lib/introspective_grape/helpers.rb +3 -3
  20. data/lib/introspective_grape/snake_params.rb +2 -1
  21. data/lib/introspective_grape/traversal.rb +5 -5
  22. data/lib/introspective_grape/validators.rb +1 -1
  23. data/lib/introspective_grape/version.rb +1 -1
  24. data/spec/dummy/app/api/dummy/chat_api.rb +4 -4
  25. data/spec/dummy/app/api/dummy/company_api.rb +1 -1
  26. data/spec/dummy/app/api/dummy/location_api.rb +2 -2
  27. data/spec/dummy/app/api/dummy/project_api.rb +1 -1
  28. data/spec/dummy/app/api/dummy/sessions.rb +3 -3
  29. data/spec/dummy/app/api/dummy/user_api.rb +1 -1
  30. data/spec/dummy/app/api/dummy_api.rb +0 -3
  31. data/spec/dummy/app/api/error_handlers.rb +2 -2
  32. data/spec/dummy/app/models/admin_user.rb +1 -1
  33. data/spec/dummy/app/models/chat.rb +1 -1
  34. data/spec/dummy/app/models/chat_message.rb +1 -1
  35. data/spec/dummy/app/models/chat_user.rb +1 -1
  36. data/spec/dummy/app/models/company.rb +1 -1
  37. data/spec/dummy/app/models/image.rb +1 -1
  38. data/spec/dummy/app/models/project.rb +1 -1
  39. data/spec/dummy/app/models/user.rb +1 -1
  40. data/spec/dummy/app/models/user/chatter.rb +4 -4
  41. data/spec/dummy/app/models/user_location.rb +4 -4
  42. data/spec/dummy/app/policies/location_policy.rb +1 -1
  43. data/spec/dummy/app/policies/project_policy.rb +5 -5
  44. data/spec/dummy/app/policies/role_policy.rb +2 -2
  45. data/spec/dummy/app/policies/user_policy.rb +1 -1
  46. data/spec/dummy/db/migrate/20150414213154_add_user_authentication_token.rb +1 -1
  47. data/spec/dummy/db/migrate/20150601212924_create_location_beacons.rb +1 -1
  48. data/spec/dummy/db/migrate/20150616205336_add_role_user_constraint.rb +1 -1
  49. data/spec/dummy/db/migrate/20150727214950_add_confirmable_to_devise.rb +1 -1
  50. data/spec/dummy/db/migrate/20150820190524_add_user_names.rb +2 -2
  51. data/spec/models/project_spec.rb +3 -3
  52. data/spec/models/role_spec.rb +6 -6
  53. data/spec/models/team_spec.rb +2 -2
  54. data/spec/models/team_user_spec.rb +4 -4
  55. data/spec/models/user_location_spec.rb +1 -1
  56. data/spec/models/user_project_job_spec.rb +2 -2
  57. data/spec/models/user_spec.rb +10 -10
  58. data/spec/requests/chat_api_spec.rb +7 -7
  59. data/spec/requests/company_api_spec.rb +4 -4
  60. data/spec/requests/location_api_spec.rb +10 -10
  61. data/spec/requests/project_api_spec.rb +18 -18
  62. data/spec/requests/role_api_spec.rb +1 -1
  63. data/spec/requests/sessions_api_spec.rb +3 -3
  64. data/spec/requests/swagger_spec.rb +1 -1
  65. data/spec/requests/user_api_spec.rb +13 -13
  66. data/spec/support/blueprints.rb +10 -10
  67. data/spec/support/location_helper.rb +6 -6
  68. data/spec/support/request_helpers.rb +4 -3
  69. metadata +6 -10
  70. data/lib/.DS_Store +0 -0
  71. data/spec/.DS_Store +0 -0
  72. data/spec/dummy/app/api/.DS_Store +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57d3bb5f544d03ed3ac7db371114203c93d9b2a8
4
- data.tar.gz: 919fa9c7f054138822c4344ece5c7e22c332725c
3
+ metadata.gz: de6a41c1400168ecda38b06734cdd3678071328a
4
+ data.tar.gz: ce20e1fc247df07463068dade8bc7e6ccfeb4e7c
5
5
  SHA512:
6
- metadata.gz: 8066cb3b5cb96688504e947c0d3e283a328a319604dc26c8ae437b53e9181ea9e73e24a9226d4a8c0ed7e3acb8234943fd9a3b41c4f9f66d1e7cd02579c7fa00
7
- data.tar.gz: 5e00569a882143326e36dc1dd1e2794fa520dc47280a888200476dedf4b4d2428b8b6891cd5381dbc6cdc1e0ac596feb453f4116e37475c780e2a18ac6ada5eb
6
+ metadata.gz: 6cd190fef2c67c05f7e6f472458686d347f1e70d64960f3909439203b032627e899ecdce9966a81046e08eb164007b91cf13a35b62555cf144c43e3d3b9f2c0e
7
+ data.tar.gz: 256ae7c47d140a34431bdb400b24ae703d25a48ded09e8639c54a4ca5cacf7f3f5ea50602226b8bb2510f15013df90763a9d56e141f9fcef1683d944b30e99be
data/.rubocop.yml CHANGED
@@ -23,7 +23,7 @@ Lint/AssignmentInCondition:
23
23
  Enabled: true
24
24
  Exclude:
25
25
  - 'bin/spring'
26
-
26
+
27
27
  Lint/BlockAlignment:
28
28
  Description: 'Align block ends correctly.'
29
29
  Enabled: true
data/.travis.yml CHANGED
@@ -12,11 +12,12 @@ rvm:
12
12
  - 2.2.0
13
13
  - 2.2.6
14
14
  - 2.3.0
15
+ - 2.4.0
15
16
  - ruby-head
16
17
  - jruby-head
17
18
  gemfile:
18
- # - gemfiles/Gemfile.rails.3.2.22
19
- #- gemfiles/Gemfile.rails.4.1.13
19
+ # - gemfiles/Gemfile.rails.3.2.22
20
+ # - gemfiles/Gemfile.rails.4.1.13
20
21
  - gemfiles/Gemfile.rails.4.2.7.1
21
22
  - gemfiles/Gemfile.rails.4.2.7.1.new.swagger
22
23
  - gemfiles/Gemfile.rails.4.2.8
@@ -50,6 +51,10 @@ matrix:
50
51
  gemfile: gemfiles/Gemfile.rails.5.0.1
51
52
  - rvm: 2.2.0
52
53
  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
53
58
  - rvm: jruby-9.0.4.0
54
59
  gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
55
60
  - rvm: jruby-9.0.4.0
@@ -58,6 +63,14 @@ matrix:
58
63
  gemfile: gemfiles/Gemfile.rails.5.0.1
59
64
  - rvm: jruby-9.0.4.0
60
65
  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
61
74
  allow_failures:
62
75
  - rvm: ruby-head
63
76
  - rvm: jruby-head
@@ -67,7 +80,7 @@ env:
67
80
  - JRUBY_OPTS="-J-Xmx1024m --debug"
68
81
 
69
82
  notifications:
70
- email:
83
+ email:
71
84
  recipients:
72
85
  - buermann@gmail.com
73
86
  on_success: change
data/CHANGELOG.md CHANGED
@@ -1,17 +1,25 @@
1
1
 
2
+ 0.2.9 04/06/2017
3
+ ================
4
+
5
+ Update to camel_snake_json >=0.0.5, which switches from monkey patching everything that includes Enumerable to using refinements, like a good neighbor. Use the class methods instead so we can continue to ostensibly support JRuby, like a good neighbor.
6
+
7
+ Simplify the logic in the CamelJson formatter for determining whether to parse the json representation of the object before camelizing it.
8
+
9
+
2
10
  0.2.8 01/22/2017
3
- ==============
11
+ ================
4
12
 
5
13
  Nested endpoints for creating new associations will now return only the newly created records.
6
14
 
7
15
  0.2.7 01/18/2017
8
- ==============
16
+ ================
9
17
 
10
18
  Add support for Swagger 2+, we can now support the latest versions of grape and other dependencies.
11
19
 
12
20
 
13
21
  0.2.6 11/01/2016
14
- ==============
22
+ ================
15
23
 
16
24
  Change the Model.attribute_param_types class method lookup (for specifying custom param types attributes on a model) to "grape_param_types" to make it clearer that the method is used in the API.
17
25
 
@@ -23,14 +31,14 @@ Add custom validators to verify that JSON strings parse as a JSON object, an arr
23
31
 
24
32
 
25
33
  0.2.5 10/28/2016
26
- ==============
34
+ ================
27
35
 
28
36
  ### Bug Fix
29
37
 
30
38
  Include the nested model IDs in the swagger doc.
31
39
 
32
40
  0.2.4 10/26/2016
33
- ==============
41
+ ================
34
42
 
35
43
  ### Bug Fix
36
44
 
@@ -85,11 +93,11 @@ class MyModel
85
93
  def my_filter(filter=false)
86
94
  filter ? my_scope : where(nil)
87
95
  end
88
-
96
+
89
97
  def my_field=(parameters)
90
98
  # parse the passed parameters in some fancy way and return a query scope
91
99
  end
92
- end
100
+ end
93
101
  end
94
102
 
95
103
  0.1.9 9/27/2016
@@ -136,7 +144,7 @@ Added an include_actions declaration as the inverse of exclude_actions.
136
144
 
137
145
  ### Features
138
146
 
139
- Stop monkey patching Grape's json formatter and instead use Grape's "formatter"
147
+ Stop monkey patching Grape's json formatter and instead use Grape's "formatter"
140
148
  with our own CamelJson module.
141
149
 
142
150
  0.1.0 5/8/2016
data/README.md CHANGED
@@ -58,7 +58,7 @@ It also defaults to monkey patching Grape::Swagger to camelize the API's paramet
58
58
 
59
59
  You can disable this behavior by setting `IntrospectiveGrape.config.camelize_parameters = false`.
60
60
 
61
- To include this behavior in your test coverage you need to either access the API's params hash or you can format the response body to `JSON.parse(response.body).with_snake_keys` in a helper method.
61
+ To include this behavior in your test coverage you need to either access the API's params hash or you can format the response body to `JSON.parse(response.body).with_snake_keys` in a helper method with the `using CamelSnakeKeys` refinement.
62
62
 
63
63
  ## Authentication and authorization
64
64
 
@@ -131,7 +131,7 @@ class MyModelAPI < IntrospectiveGrape::API
131
131
  restful MyModel, [:strong, :param, :fields, :and, { nested_model_attributes: [:nested,:fields, :_destroy] }] do
132
132
  # Add additional end points to the model's namespace
133
133
  end
134
-
134
+
135
135
  class <NestedModel>Entity < Grape::Entity
136
136
  expose :id, :attribute
137
137
  end
@@ -170,7 +170,7 @@ The index action by default will not be paginated, simply declared `paginate` be
170
170
  To define a Grape param type for a virtual attribute or override the defaut param
171
171
  type from database introspection, define a class method in the model with the param
172
172
  types for the attributes specified in a hash, e.g.:
173
-
173
+
174
174
  ```
175
175
  def self.grape_param_types
176
176
  { "<attribute name 1>" => String,
@@ -185,8 +185,8 @@ class method ("grape_validations") that will be applied to that field's param de
185
185
  ```
186
186
  def self.grape_validations
187
187
  { field1: { values: %w(red blue green) },
188
- field2: { json_array: true },
189
- field3: { regexp: /\w+/ }
188
+ field2: { json_array: true },
189
+ field3: { regexp: /\w+/ }
190
190
  end
191
191
  ```
192
192
 
@@ -196,7 +196,7 @@ IntrospectiveGrape provides the following custom grape validators for JSON strin
196
196
 
197
197
  ```
198
198
  json: true # validates that the JSON string parses
199
- json_array: true # validates that the JSON string parses and returns an Array
199
+ json_array: true # validates that the JSON string parses and returns an Array
200
200
  json_hash: true # validates that the JSON string parses and returns a Hash
201
201
  ```
202
202
 
@@ -17,6 +17,6 @@ gem 'coveralls', require: false
17
17
  # your gem to rubygems.org.
18
18
 
19
19
  group :development,:test do
20
- gem 'rspec'
20
+ gem 'rspec'
21
21
  # gem 'byebug'
22
22
  end
@@ -9,5 +9,5 @@ gem 'nokogiri', '< 1.6.9'
9
9
  gem 'coveralls', require: false
10
10
 
11
11
  group :development,:test do
12
- gem 'rspec'
12
+ gem 'rspec'
13
13
  end
@@ -9,5 +9,5 @@ gem 'nokogiri', '< 1.6.9'
9
9
  gem 'coveralls', require: false
10
10
 
11
11
  group :development,:test do
12
- gem 'rspec'
12
+ gem 'rspec'
13
13
  end
@@ -9,5 +9,5 @@ gem 'nokogiri', '< 1.6.9'
9
9
  gem 'coveralls', require: false
10
10
 
11
11
  group :development,:test do
12
- gem 'rspec'
12
+ gem 'rspec'
13
13
  end
@@ -8,5 +8,5 @@ gem 'grape-swagger', '> 0.12.0'
8
8
  gem 'coveralls', require: false
9
9
 
10
10
  group :development,:test do
11
- gem 'rspec'
11
+ gem 'rspec'
12
12
  end
@@ -8,5 +8,5 @@ gem 'grape-swagger', '> 0.12.0'
8
8
  gem 'coveralls', require: false
9
9
 
10
10
  group :development,:test do
11
- gem 'rspec'
11
+ gem 'rspec'
12
12
  end
@@ -9,5 +9,5 @@ gem 'nokogiri'
9
9
  gem 'coveralls', require: false
10
10
 
11
11
  group :development,:test do
12
- gem 'rspec'
12
+ gem 'rspec'
13
13
  end
@@ -9,5 +9,5 @@ gem 'nokogiri'
9
9
  gem 'coveralls', require: false
10
10
 
11
11
  group :development,:test do
12
- gem 'rspec'
12
+ gem 'rspec'
13
13
  end
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.required_ruby_version = '~> 2.0'
22
22
 
23
- s.add_dependency "rails", '>= 3.0.0'
23
+ s.add_dependency "rails", '>= 3.0.0'
24
24
 
25
25
  s.add_dependency 'grape' #, '~> 0.16.2'
26
26
  s.add_dependency 'grape-entity' #, '< 0.5.0'
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.add_dependency 'kaminari', '< 1.0' # There's a version 1.0.0 out there that breaks everything
29
29
  s.add_dependency 'grape-kaminari'
30
30
  s.add_dependency 'pundit'
31
- s.add_dependency 'camel_snake_keys'
31
+ s.add_dependency 'camel_snake_keys', '>0.0.4'
32
32
 
33
33
  if RUBY_PLATFORM == 'java'
34
34
  #s.add_development_dependency "jdbc-sqlite3"
@@ -76,7 +76,7 @@ module IntrospectiveGrape
76
76
  # model: the model class for the API
77
77
  # whitelist: a list of fields in Rail's strong params structure, also used to
78
78
  # generate grape's permitted params.
79
- # routes: An array of OpenStruct representations of a nested route's ancestors
79
+ # routes: An array of OpenStruct representations of a nested route's ancestors
80
80
  #
81
81
 
82
82
  # Defining the api will break pending migrations during db:migrate, so bail:
@@ -91,7 +91,7 @@ module IntrospectiveGrape
91
91
  # when routes are nested
92
92
  whitelist = whitelist( strong_params )
93
93
 
94
- # As routes are nested keep track of the routes, we are preventing siblings from
94
+ # As routes are nested keep track of the routes, we are preventing siblings from
95
95
  # appending to the routes array here:
96
96
  routes = build_routes(routes, model)
97
97
  define_routes(routes, whitelist)
@@ -99,7 +99,7 @@ module IntrospectiveGrape
99
99
  # Top level declaration of the Grape::API namespace for the resource:
100
100
  resource routes.first.name.pluralize do
101
101
  # yield to append additional routes under the root namespace
102
- yield if block_given?
102
+ yield if block_given?
103
103
  end
104
104
  end
105
105
 
@@ -114,7 +114,7 @@ module IntrospectiveGrape
114
114
  # Look at model.reflections to find the association's class name:
115
115
  reflection_name = r.to_s.sub(/_attributes$/,'')
116
116
  begin
117
- relation = model.reflections[reflection_name].class_name.constantize
117
+ relation = model.reflections[reflection_name].class_name.constantize
118
118
  rescue
119
119
  Rails.logger.fatal "Can't find associated model for #{r} on #{model}"
120
120
  end
@@ -145,7 +145,7 @@ module IntrospectiveGrape
145
145
  end
146
146
  end
147
147
 
148
- def define_restful_api(dsl, routes, model, api_params)
148
+ def define_restful_api(dsl, routes, model, api_params)
149
149
  # declare index, show, update, create, and destroy methods:
150
150
  API_ACTIONS.each do |action|
151
151
  send("define_#{action}", dsl, routes, model, api_params) unless exclude_actions(model).include?(action)
@@ -270,7 +270,7 @@ module IntrospectiveGrape
270
270
  # routes: the existing routes array passed from the parent
271
271
  # model: the model being manipulated in this leaf
272
272
  # reflection_name: the association name from the original strong_params declaration
273
- #
273
+ #
274
274
  # Constructs an array representation of the route's models and their associations,
275
275
  # a /root/:rootId/branch/:branchId/leaf/:leafId path would have flat array like
276
276
  # [root,branch,leaf] representing the path structure and its models, used to
@@ -287,7 +287,7 @@ module IntrospectiveGrape
287
287
  end
288
288
 
289
289
 
290
- def build_nested_attributes(routes,hash)
290
+ def build_nested_attributes(routes,hash)
291
291
  # Recursively re-express the flat attributes hash from nested routes as nested
292
292
  # attributes that can be used to perform an update on the root model.
293
293
 
@@ -299,12 +299,12 @@ module IntrospectiveGrape
299
299
  id = hash.delete route.key
300
300
  attributes = id ? { id: id } : {}
301
301
 
302
- attributes.merge!( hash ) if routes.blank? # assign param values to the last reference
302
+ attributes.merge!( hash ) if routes.blank? # assign param values to the last reference
303
303
 
304
304
  if route.many? # nest it in an array if it is a has_many association
305
- { route.param => [attributes.merge( build_nested_attributes(routes, hash) )] }
306
- else
307
- { route.param => attributes.merge( build_nested_attributes(routes, hash) ) }
305
+ { route.param => [attributes.merge( build_nested_attributes(routes, hash) )] }
306
+ else
307
+ { route.param => attributes.merge( build_nested_attributes(routes, hash) ) }
308
308
  end
309
309
  end
310
310
 
@@ -354,7 +354,7 @@ module IntrospectiveGrape
354
354
  # Handle Carrierwave file upload fields
355
355
  s = [:filename, :type, :name, :tempfile, :head]-v
356
356
  if s.present?
357
- Rails.logger.warn "Missing required file upload parameters #{s} for uploader field #{r}"
357
+ Rails.logger.warn "Missing required file upload parameters #{s} for uploader field #{r}"
358
358
  end
359
359
  elsif PLURAL_REFLECTIONS.include?( model.reflections[reflection].class )
360
360
  # In case you need a refresher on how these work:
@@ -377,8 +377,8 @@ module IntrospectiveGrape
377
377
  end
378
378
 
379
379
  def is_file_attachment?(model,field)
380
- model.try(:uploaders) && model.uploaders[field.to_sym] || # carrierwave
381
- (model.try(:attachment_definitions) && model.attachment_definitions[field.to_sym]) ||
380
+ model.respond_to?(:uploaders) && model.uploaders[field.to_sym] || # carrierwave
381
+ (model.respond_to?(:attachment_definitions) && model.attachment_definitions[field.to_sym]) ||
382
382
  defined?(Paperclip::Attachment) && model.send(:new).try(field).kind_of?(Paperclip::Attachment)
383
383
  end
384
384
 
@@ -389,8 +389,8 @@ module IntrospectiveGrape
389
389
 
390
390
  # Check if it's a file attachment, look for an override class from the model,
391
391
  # check Pg2Ruby, use the database type, or fail over to a String:
392
- ( is_file_attachment?(model,f) && Rack::Multipart::UploadedFile ) ||
393
- (model.try(:grape_param_types)||{}).with_indifferent_access[f] ||
392
+ ( is_file_attachment?(model,f) && Rack::Multipart::UploadedFile ) ||
393
+ (model.try(:grape_param_types)||{}).with_indifferent_access[f] ||
394
394
  Pg2Ruby[db_type] ||
395
395
  begin db_type.to_s.camelize.constantize rescue nil end ||
396
396
  String
@@ -1,10 +1,11 @@
1
1
  require 'grape-swagger'
2
- require 'active_support' #/core_ext/module/aliasing'
3
- require 'camel_snake_keys'
4
- if IntrospectiveGrape.config.camelize_parameters
2
+ require 'active_support/core_ext/module/aliasing'
3
+ require 'active_support/inflector/methods'
4
+
5
+ if IntrospectiveGrape.config.camelize_parameters
5
6
  # Camelize the parameters in the swagger documentation.
6
7
  if Gem::Version.new( GrapeSwagger::VERSION ) <= Gem::Version.new('0.11.0')
7
- Grape::API.class_eval do
8
+ Grape::API.class_eval do
8
9
  class << self
9
10
  private
10
11
  def create_documentation_class_with_camelized
@@ -29,7 +29,7 @@ module IntrospectiveGrape::Filters
29
29
  end
30
30
 
31
31
  def simple_filters(klass, model, api_params)
32
- @simple_filters ||= api_params.select {|p| p.is_a? Symbol }.select {|field|
32
+ @simple_filters ||= api_params.select {|p| p.is_a? Symbol }.select {|field|
33
33
  filters.include?(:all) || filters.include?(field)
34
34
  }.map { |field|
35
35
  (klass.param_type(model,field) == DateTime ? ["#{field}_start", "#{field}_end"] : field.to_s)
@@ -58,7 +58,7 @@ module IntrospectiveGrape::Filters
58
58
  # timestamp, a Start and an End, to apply a date range.
59
59
  simple_filters(klass, model, api_params).each do |field|
60
60
  if timestamp_filter(klass,model,field)
61
- terminal = field.ends_with?("_start") ? "initial" : "terminal"
61
+ terminal = field.ends_with?("_start") ? "initial" : "terminal"
62
62
  dsl.optional field, type: klass.param_type(model,field), description: "Constrain #{field} by #{terminal} date."
63
63
  elsif identifier_filter(klass,model,field)
64
64
  dsl.optional field, type: Array[Integer], coerce_with: ->(val) { val.split(',') }, description: "Filter by a comma separated list of integers."
@@ -4,17 +4,20 @@ require 'grape/formatter/json'
4
4
  module IntrospectiveGrape
5
5
  module Formatter
6
6
  module CamelJson
7
- def self.call(object, _env)
8
- if object.respond_to?(:to_json) && !object.respond_to?(:with_camel_keys) &&
9
- (parsed_object = JSON.parse(object.to_json)).respond_to?(:with_camel_keys)
10
- object = parsed_object
11
- elsif object.kind_of?(Array) && object.first.kind_of?(Grape::Entity)
12
- # Force arrays of Grape::Entities into their hash representations before camelizing
13
- object = JSON.parse(object.to_json)
7
+ class << self
8
+ def transform_to_camel_keys(object)
9
+ # We only need to parse(object.to_json) like this if it isn't already
10
+ # a native hash (or array of them), i.e. we have to parse Grape::Entities
11
+ # and other formatter facades:
12
+ unless (object.is_a?(Array) && object.first.is_a?(Hash)) || object.is_a?(Hash)
13
+ object = JSON.parse(object.to_json) if object.respond_to?(:to_json)
14
+ end
15
+ CamelSnakeKeys.camel_keys(object)
14
16
  end
15
- object = object.with_camel_keys if object.respond_to?(:with_camel_keys)
16
17
 
17
- Grape::Formatter::Json.call(object, _env)
18
+ def call(object, env)
19
+ Grape::Formatter::Json.call(transform_to_camel_keys(object), env)
20
+ end
18
21
  end
19
22
  end
20
23
  end
@@ -7,7 +7,7 @@ module IntrospectiveGrape::Helpers
7
7
 
8
8
  def authentication_method(context)
9
9
  # Default to "authenticate!" or as grape docs once suggested, "authorize!"
10
- if @authentication_method
10
+ if @authentication_method
11
11
  @authentication_method
12
12
  elsif context.respond_to?('authenticate!')
13
13
  'authenticate!'
@@ -27,7 +27,7 @@ module IntrospectiveGrape::Helpers
27
27
  def exclude_actions(model, *args)
28
28
  @exclude_actions ||= {}; @exclude_actions[model.name] ||= []
29
29
  args.flatten!
30
- args = API_ACTIONS if args.include?(:all)
30
+ args = API_ACTIONS if args.include?(:all)
31
31
  args = [] if args.include?(:none)
32
32
 
33
33
  undefined_actions = args.compact-API_ACTIONS
@@ -46,7 +46,7 @@ module IntrospectiveGrape::Helpers
46
46
  @default_includes ||= {}
47
47
  @default_includes[model.name] = args.present? ? args.flatten : @default_includes[model.name] || []
48
48
  end
49
-
49
+
50
50
  def whitelist(whitelist=nil)
51
51
  return @whitelist if !whitelist
52
52
  @whitelist = whitelist