introspective_grape 0.3.9 → 0.4.3

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
- SHA1:
3
- metadata.gz: 1effbc66aaa2ba49bd62f0e7605095c7e827bf83
4
- data.tar.gz: baebbb68b35036a66a2ff041f80c17b2d47decd1
2
+ SHA256:
3
+ metadata.gz: dd8453af52e6616722a7899ace0e7b79c9e4129dea63565c99f8f7ba94f77ee9
4
+ data.tar.gz: 0e2c0a47ab78f79d37d9a9fec9c861c82421303205084b9168eff6f3a239af2a
5
5
  SHA512:
6
- metadata.gz: 65d0d34c627d73ecdf3a082bc45f6597f9ae22aa066c0fa0eaea379d04ff4e38d9eca6bd5a8ef4fdfe03c44da3869bda89b7814e5a84cac8b9c0144416ead2de
7
- data.tar.gz: 3733b34a24eb28826f9ae455b3975b6a96b5796ca78d75486bd4ee18a761370ce2fa847c6dae080e8486b79d062c2f0fbbc60f33e9781b871d676e7edf3da927
6
+ metadata.gz: b51e598d1078c423c809c68f75cb52079920ac06f4d4cc634814575c8f24af28296e05bc0de1e77383ece29ef30f03ce90c14d203dda51c6ad510a1fafadb7a3
7
+ data.tar.gz: d2916cb32f455dba2f083661c6c90a9190c54b9c10b8f5c8dc1c159f11a1a4227ae54c6b9878beb39a4cca7631095fc1539c4c0437dfc89a239880c854671dae
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ 0.4.1 10/20/2020
2
+ ================
3
+
4
+ We can't expect to ever release a 1.0 if the configuration object doesn't actually persist from the initializer.
5
+
6
+ 0.4.0 10/20/2020
7
+ ================
8
+
9
+ Add an `IntrospectiveGrape.config.skip_object_reload = true` option.
1
10
 
2
11
  0.3.9 04/01/2019
3
12
  ================
data/README.md CHANGED
@@ -49,6 +49,8 @@ And bundle install.
49
49
 
50
50
  ## Grape Configuration
51
51
 
52
+ ### Camelization
53
+
52
54
  IntrospectiveGrape's default behavior is to camelize all outputs and snake case all inputs. To camel case all your json output you'll need to use its formatter in your API:
53
55
 
54
56
  ```
@@ -61,6 +63,18 @@ You can disable this behavior by setting `IntrospectiveGrape.config.camelize_par
61
63
 
62
64
  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.
63
65
 
66
+ ### Reloading an object after an update request
67
+
68
+ By default the gem reloads the object instance before presenting the updated model, a lazy but
69
+ effective workaround to updates that may not propagate in the working instance due to actions
70
+ a user may take in hooks, or some updates to has_many :through associations. We want to put up
71
+ APIs with haste rather than digging our way out of tricky minutae that can be handled later as
72
+ technical debt.
73
+
74
+ This behavior can be disabled by setting `IntrospectiveGrape.config.skip_object_reload = true`,
75
+ when you have time for technical debt you can toggle it and work on fixing broken tests (you
76
+ did take the time to write comprehensive test coverage, didn't you?).
77
+
64
78
  ## Authentication and authorization
65
79
 
66
80
  Authentication and authorization are presently enforced on every endpoint. If you have named the authentication helper method in Grape something other than "authenticate!" or "authorize!" you can set it with:
@@ -20,17 +20,16 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.required_ruby_version = '>= 2.3'
22
22
 
23
- s.add_dependency "rails", '> 5.0.0'
24
-
25
- # grape 1.0.0 breaks the pagination solution
26
- s.add_dependency 'grape', '~> 1.2.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
23
+ s.add_runtime_dependency "rails", '> 5.0.0'
24
+ s.add_runtime_dependency "rack", '< 2.0.9' # grape < 1.3.0 is incompatible with rack 2.1.0
25
+ s.add_runtime_dependency 'grape', ['~> 1.2.0', '< 1.2.5']
26
+ s.add_runtime_dependency 'grape-entity'
27
+ s.add_runtime_dependency 'grape-swagger'
28
+ s.add_runtime_dependency 'kaminari' #, '< 1.0' # version 1.0.0 breaks
30
29
  #s.add_dependency 'grape-kaminari', :github => 'alexey-klimuk/grape-kaminari'
31
30
  # Pundit 2.0 mysteriously made authorize a protected method...
32
- s.add_dependency 'pundit' #, '<2.0'
33
- s.add_dependency 'camel_snake_keys', '>0.0.4'
31
+ s.add_runtime_dependency 'pundit' #, '<2.0'
32
+ s.add_runtime_dependency 'camel_snake_keys', '>0.0.4'
34
33
 
35
34
  if RUBY_PLATFORM == 'java'
36
35
  #s.add_development_dependency "jdbc-sqlite3"
@@ -1,6 +1,8 @@
1
+ require 'introspective_grape/configuration'
1
2
  module IntrospectiveGrape
2
3
  autoload :API, 'introspective_grape/api'
3
4
  autoload :CamelSnake, 'introspective_grape/camel_snake'
5
+ autoload :Configure, 'introspective_grape/configuration'
4
6
  autoload :CreateHelpers, 'introspective_grape/create_helpers'
5
7
  autoload :Doc, 'introspective_grape/doc'
6
8
  autoload :Filters, 'introspective_grape/filters'
@@ -13,6 +15,6 @@ module IntrospectiveGrape
13
15
  end
14
16
 
15
17
  def self.config
16
- @config = OpenStruct.new(camelize_parameters: true)
18
+ @config ||= Configuration.new
17
19
  end
18
20
  end
@@ -248,9 +248,12 @@ module IntrospectiveGrape
248
248
 
249
249
  @model.update_attributes!( safe_params(params).permit(klass.whitelist) )
250
250
 
251
- default_includes = routes.first.klass.default_includes(routes.first.model)
252
-
253
- present klass.find_leaf(routes, @model.class.includes(default_includes).find(@model.id), params), with: "#{klass}::#{model}Entity".constantize
251
+ if IntrospectiveGrape.config.skip_object_reload
252
+ present klass.find_leaf(routes, @model, params), with: "#{klass}::#{model}Entity".constantize
253
+ else
254
+ default_includes = routes.first.klass.default_includes(routes.first.model)
255
+ present klass.find_leaf(routes, @model.class.includes(default_includes).find(@model.id), params), with: "#{klass}::#{model}Entity".constantize
256
+ end
254
257
  end
255
258
  end
256
259
 
@@ -0,0 +1,15 @@
1
+ module IntrospectiveGrape
2
+ def self.configure
3
+ self.config ||= Configuration.new
4
+ yield config
5
+ end
6
+
7
+ class Configuration
8
+ attr_accessor :camelize_parameters, :skip_object_reload
9
+
10
+ def initialize
11
+ @camelize_parameters = true
12
+ @skip_object_reload = false
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module IntrospectiveGrape
2
- VERSION = "0.3.9".freeze
2
+ VERSION = "0.4.3".freeze
3
3
  end
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.9
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Buermann
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-03 00:00:00.000000000 Z
11
+ date: 2021-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 5.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.9
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "<"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.9
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: grape
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -31,6 +45,9 @@ dependencies:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
47
  version: 1.2.0
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: 1.2.5
34
51
  type: :runtime
35
52
  prerelease: false
36
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +55,9 @@ dependencies:
38
55
  - - "~>"
39
56
  - !ruby/object:Gem::Version
40
57
  version: 1.2.0
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: 1.2.5
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: grape-entity
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -241,6 +261,7 @@ files:
241
261
  - lib/introspective_grape.rb
242
262
  - lib/introspective_grape/api.rb
243
263
  - lib/introspective_grape/camel_snake.rb
264
+ - lib/introspective_grape/configuration.rb
244
265
  - lib/introspective_grape/create_helpers.rb
245
266
  - lib/introspective_grape/doc.rb
246
267
  - lib/introspective_grape/filters.rb
@@ -398,7 +419,7 @@ homepage: https://github.com/buermann/introspective_grape
398
419
  licenses:
399
420
  - MIT
400
421
  metadata: {}
401
- post_install_message:
422
+ post_install_message:
402
423
  rdoc_options: []
403
424
  require_paths:
404
425
  - lib
@@ -413,9 +434,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
413
434
  - !ruby/object:Gem::Version
414
435
  version: '0'
415
436
  requirements: []
416
- rubyforge_project:
417
- rubygems_version: 2.5.1
418
- signing_key:
437
+ rubygems_version: 3.1.2
438
+ signing_key:
419
439
  specification_version: 4
420
440
  summary: Introspectively configure deeply nested RESTful Grape APIs for ActiveRecord
421
441
  models.