introspective_grape 0.6.1 → 0.7.0

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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +85 -84
  3. data/.ruby-version +1 -1
  4. data/CHANGELOG.md +10 -0
  5. data/Gemfile +38 -22
  6. data/README.md +13 -20
  7. data/introspective_grape.gemspec +41 -64
  8. data/lib/introspective_grape/api.rb +469 -461
  9. data/lib/introspective_grape/camel_snake.rb +3 -3
  10. data/lib/introspective_grape/create_helpers.rb +25 -25
  11. data/lib/introspective_grape/filters.rb +5 -3
  12. data/lib/introspective_grape/route.rb +11 -0
  13. data/lib/introspective_grape/traversal.rb +56 -56
  14. data/lib/introspective_grape/validators.rb +37 -36
  15. data/lib/introspective_grape/version.rb +5 -5
  16. data/lib/introspective_grape.rb +1 -0
  17. data/spec/dummy/Gemfile +24 -23
  18. data/spec/dummy/app/api/{api_helpers.rb → authentication_helper.rb} +38 -38
  19. data/spec/dummy/app/api/dummy/chat_api.rb +1 -1
  20. data/spec/dummy/app/api/dummy/company_api.rb +1 -1
  21. data/spec/dummy/app/api/dummy/location_api.rb +1 -1
  22. data/spec/dummy/app/api/dummy/project_api.rb +2 -2
  23. data/spec/dummy/app/api/dummy/role_api.rb +1 -1
  24. data/spec/dummy/app/api/dummy/sessions.rb +2 -2
  25. data/spec/dummy/app/api/dummy/user_api.rb +1 -1
  26. data/spec/dummy/app/api/dummy_api.rb +60 -61
  27. data/spec/dummy/app/api/error_handlers.rb +6 -6
  28. data/spec/dummy/app/api/permissions_helper.rb +7 -7
  29. data/spec/dummy/app/helpers/current.rb +3 -3
  30. data/spec/dummy/app/models/abstract_adapter.rb +11 -8
  31. data/spec/dummy/app/models/chat_message.rb +34 -34
  32. data/spec/dummy/app/models/chat_user.rb +16 -16
  33. data/spec/dummy/app/models/company.rb +3 -2
  34. data/spec/dummy/app/models/location.rb +26 -26
  35. data/spec/dummy/app/models/role.rb +30 -30
  36. data/spec/dummy/app/models/team.rb +14 -14
  37. data/spec/dummy/app/models/user/chatter.rb +79 -79
  38. data/spec/dummy/app/models/user.rb +2 -0
  39. data/spec/dummy/bin/bundle +3 -3
  40. data/spec/dummy/bin/rails +4 -4
  41. data/spec/dummy/bin/setup +36 -36
  42. data/spec/dummy/bin/update +31 -31
  43. data/spec/dummy/bin/yarn +11 -11
  44. data/spec/dummy/config/application.rb +30 -30
  45. data/spec/dummy/config/boot.rb +3 -3
  46. data/spec/dummy/config/environment.rb +5 -5
  47. data/spec/dummy/config/environments/development.rb +54 -54
  48. data/spec/dummy/config/environments/production.rb +81 -81
  49. data/spec/dummy/config/environments/test.rb +47 -47
  50. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -8
  51. data/spec/dummy/config/initializers/assets.rb +14 -14
  52. data/spec/dummy/config/initializers/content_security_policy.rb +25 -25
  53. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -5
  54. data/spec/dummy/config/initializers/new_framework_defaults_5_2.rb +38 -38
  55. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  56. data/spec/dummy/config/locales/en.yml +33 -33
  57. data/spec/dummy/config/routes.rb +1 -1
  58. data/spec/dummy/config/storage.yml +34 -34
  59. data/spec/models/image_spec.rb +10 -10
  60. data/spec/rails_helper.rb +1 -2
  61. data/spec/requests/chat_api_spec.rb +1 -1
  62. data/spec/requests/company_api_spec.rb +1 -1
  63. data/spec/requests/location_api_spec.rb +1 -1
  64. data/spec/requests/project_api_spec.rb +185 -185
  65. data/spec/requests/role_api_spec.rb +1 -1
  66. data/spec/requests/user_api_spec.rb +221 -221
  67. data/spec/support/request_helpers.rb +22 -22
  68. metadata +9 -192
  69. data/spec/dummy/.ruby-version +0 -1
  70. data/spec/dummy/config/initializers/inflections.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2a07edad73a2ac601dfb2743775e01047ad725471d30694f3dec9579a0f0450
4
- data.tar.gz: 6db4149759fe421ccc157124f2c4f5b5edc757b79646efff20ab6726f7f378f0
3
+ metadata.gz: 6ec4b919395ffd2b409a4a4b93f223aa10406fef2886f33cc5b8d9ec89e3822b
4
+ data.tar.gz: 7269f346109569e44df72beed6f00a5b2c62cf1f50efb657b43764a5304e8860
5
5
  SHA512:
6
- metadata.gz: bebc8fc3eb3e95e6c26a4b751485c666cd79cf485d8604d011bdcbfcc210c8d7a9411a976d28be5a012504d1a34dce68a872c33149ec76066ac57eddcff00e39
7
- data.tar.gz: 1ae975dfdcbb9992981809c2ada02a5d04ab1453be6c136bcd523711b9e362fbee7e3e1cad726f5e12a92c38e5e44e2d003f6db0706be127ad6c9c9ec6ba79f2
6
+ metadata.gz: 27141bf2c3082bef253ef90f838fc272600ef87e9c6767bd93acf7f2007beaa97c9e995d0a7e563ee2595945eb38e1ff93fbe3a445d6cb0182cfdcbf7b092885
7
+ data.tar.gz: 91c5267b99ce330cd04c09843822085c8c3917fb718537d516d769be75f23c3a40618442037e55800f57d6139df95ec4e12a647c3e100d7d6244a9e9c84bd893
data/.rubocop.yml CHANGED
@@ -1,84 +1,85 @@
1
- AllCops:
2
- NewCops: enable
3
- Exclude:
4
- - 'spec/**/*'
5
- - 'db/**/*'
6
- - 'Gemfile'
7
- - 'vendor/**/*' # or vendor/bundle/**/*
8
-
9
- Gemspec/OrderedDependencies:
10
- Enabled: false # I like to group them, so what?
11
-
12
- Metrics/BlockLength:
13
- Max: 30
14
-
15
- Metrics/MethodLength:
16
- Max: 30
17
-
18
- Metrics/AbcSize:
19
- Max: 20
20
-
21
- Metrics/PerceivedComplexity:
22
- Max: 12
23
-
24
- Metrics/CyclomaticComplexity:
25
- Max: 12
26
-
27
- Layout/EndOfLine:
28
- Enabled: false
29
-
30
- Layout/ExtraSpacing:
31
- Enabled: false
32
-
33
- Layout/HashAlignment:
34
- Enabled: false
35
-
36
- Layout/LineLength:
37
- Enabled: false
38
-
39
- Layout/SpaceAroundEqualsInParameterDefault:
40
- # I like to space repeated grammars out tabulated, defund these cops
41
- Enabled: false
42
-
43
- Layout/EmptyLinesAroundExceptionHandlingKeywords:
44
- Enabled: false
45
-
46
- Layout/SpaceInsideBlockBraces:
47
- Enabled: false
48
-
49
- Layout/SpaceInsideParens:
50
- Enabled: false
51
-
52
- Layout/SpaceAroundOperators:
53
- Enabled: false
54
-
55
- Lint/EmptyBlock:
56
- Enabled: false
57
-
58
- Style/BlockDelimiters:
59
- Enabled: false
60
-
61
- Style/FrozenStringLiteralComment:
62
- Enabled: false
63
-
64
- Style/Documentation:
65
- Enabled: false
66
-
67
- Style/RaiseArgs:
68
- Enabled: false
69
-
70
- Style/RedundantBegin:
71
- Enabled: false
72
-
73
- Style/RescueModifier:
74
- Enabled: false
75
-
76
- Style/OptionalBooleanParameter:
77
- Enabled: false
78
-
79
- Style/PercentLiteralDelimiters:
80
- # the cops change this preference every version of ruby, but who cares in the first place?
81
- Enabled: false
82
-
83
- Style/MultilineBlockChain:
84
- Enabled: false
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+ NewCops: enable
4
+ Exclude:
5
+ - 'spec/**/*'
6
+ - 'db/**/*'
7
+ - 'Gemfile'
8
+ - 'vendor/**/*' # or vendor/bundle/**/*
9
+
10
+ Gemspec/OrderedDependencies:
11
+ Enabled: false # I like to group them, so what?
12
+
13
+ Metrics/BlockLength:
14
+ Max: 30
15
+
16
+ Metrics/MethodLength:
17
+ Max: 30
18
+
19
+ Metrics/AbcSize:
20
+ Max: 20
21
+
22
+ Metrics/PerceivedComplexity:
23
+ Max: 12
24
+
25
+ Metrics/CyclomaticComplexity:
26
+ Max: 12
27
+
28
+ Layout/EndOfLine:
29
+ Enabled: false
30
+
31
+ Layout/ExtraSpacing:
32
+ Enabled: false
33
+
34
+ Layout/HashAlignment:
35
+ Enabled: false
36
+
37
+ Layout/LineLength:
38
+ Enabled: false
39
+
40
+ Layout/SpaceAroundEqualsInParameterDefault:
41
+ # I like to space repeated grammars out tabulated, defund these cops
42
+ Enabled: false
43
+
44
+ Layout/EmptyLinesAroundExceptionHandlingKeywords:
45
+ Enabled: false
46
+
47
+ Layout/SpaceInsideBlockBraces:
48
+ Enabled: false
49
+
50
+ Layout/SpaceInsideParens:
51
+ Enabled: false
52
+
53
+ Layout/SpaceAroundOperators:
54
+ Enabled: false
55
+
56
+ Lint/EmptyBlock:
57
+ Enabled: false
58
+
59
+ Style/BlockDelimiters:
60
+ Enabled: false
61
+
62
+ Style/FrozenStringLiteralComment:
63
+ Enabled: false
64
+
65
+ Style/Documentation:
66
+ Enabled: false
67
+
68
+ Style/RaiseArgs:
69
+ Enabled: false
70
+
71
+ Style/RedundantBegin:
72
+ Enabled: false
73
+
74
+ Style/RescueModifier:
75
+ Enabled: false
76
+
77
+ Style/OptionalBooleanParameter:
78
+ Enabled: false
79
+
80
+ Style/PercentLiteralDelimiters:
81
+ # the cops change this preference every version of ruby, but who cares in the first place?
82
+ Enabled: false
83
+
84
+ Style/MultilineBlockChain:
85
+ Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.3
1
+ 3.3.1
data/CHANGELOG.md CHANGED
@@ -1,4 +1,14 @@
1
1
 
2
+ 0.7.0 08/27/2025
3
+ ================
4
+
5
+ Support for Ruby > 3, Rails 7.2+.
6
+
7
+ 0.6.0 07/21/2022
8
+ ================
9
+
10
+ Support for Rails >6.
11
+
2
12
  0.5.7 03/10/2022
3
13
  ================
4
14
 
data/Gemfile CHANGED
@@ -1,22 +1,38 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- gem 'devise'
5
- gem 'grape-entity'
6
- gem 'grape-swagger'
7
-
8
- # Declare your gem's dependencies in introspective_grape.gemspec.
9
- # Bundler will treat runtime dependencies like base dependencies, and
10
- # development dependencies will be added by default to the :development group.
11
-
12
-
13
- # Declare any dependencies that are still in development here instead of in
14
- # your gemspec. These might include edge Rails or gems from your path or
15
- # Git. Remember to move these dependencies to your gemspec before releasing
16
- # your gem to rubygems.org.
17
-
18
- group :development, :test do
19
- gem 'byebug'
20
- gem 'rb-readline'
21
- gem 'coveralls_reborn', require: false
22
- end
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'devise'
5
+ gem 'grape-entity'
6
+ gem 'grape-swagger'
7
+ gem 'validates_by_schema'
8
+
9
+ # Declare your gem's dependencies in introspective_grape.gemspec.
10
+ # Bundler will treat runtime dependencies like base dependencies, and
11
+ # development dependencies will be added by default to the :development group.
12
+
13
+
14
+ # Declare any dependencies that are still in development here instead of in
15
+ # your gemspec. These might include edge Rails or gems from your path or
16
+ # Git. Remember to move these dependencies to your gemspec before releasing
17
+ # your gem to rubygems.org.
18
+
19
+
20
+ group :development, :test do
21
+ # testing
22
+ gem 'brakeman'
23
+ gem 'bundler-audit'
24
+ gem 'byebug'
25
+ gem 'coveralls_reborn', require: false
26
+ gem 'machinist_redux'
27
+ gem 'rb-readline'
28
+ gem 'rspec-rails', '>= 3.0'
29
+ gem 'rubocop'
30
+ gem 'simplecov'
31
+
32
+ # dummy app dependencies
33
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
34
+ gem 'devise'
35
+ gem 'kt-paperclip'
36
+ gem 'rufus-mnemo'
37
+ gem 'sqlite3', platforms: :ruby
38
+ end
data/README.md CHANGED
@@ -15,21 +15,18 @@
15
15
 
16
16
  IntrospectiveGrape is a rails plugin for DRYing up
17
17
  [Grape APIs](https://github.com/ruby-grape/grape) by laying out simple
18
- (or, if you like, very complex) RESTful defaults based on the introspection of your database by
19
- [SchemaPlusValidations](https://github.com/SchemaPlus/schema_validations).
18
+ (or, if you like, very complex) RESTful defaults based on your database schema.
20
19
 
21
20
  IntrospectiveGrape provides handling for deeply nested relations according to the models'
22
21
  `accepts_nested_attributes_for` declarations, generating all the necessary
23
- boilerplate for flexible and consistent bulk endpoints on plural associations,
24
- and building nested routes for the same.
22
+ boilerplate for flexible and consistent bulk endpoints on plural associations
23
+ and building the deeply nested routes for acting upon individual records.
25
24
 
26
25
  It relies on [Kaminari](https://github.com/kaminari/kaminari) for pagination and [Pundit](https://github.com/varvet/pundit) for authorization, both of which are semi-optional.
27
26
 
28
- To facilitate idiomatic ruby and javascript, respectively, it also makes it easy to snakecase incoming parameters and camelize outputs, all the way through to your swagger docs.
29
-
30
- NOTE: SchemaPlus is not currently being maintained and is unavailable for Rails > 2.5, and thus so is
31
- IntrospectiveGrape. Which is too bad! I don't know how anybody with a relational database gets by
32
- without it. We're working on it when we get the chance.
27
+ To facilitate idiomatic ruby and javascript, respectively, it makes it trivial to snakecase
28
+ incoming parameters and camelize outputs, all the way through to your automatically generated
29
+ swagger documentation.
33
30
 
34
31
  ## Documentation
35
32
 
@@ -54,11 +51,9 @@ class MyAPI < Grape::API
54
51
  end
55
52
  ```
56
53
 
57
- This also monkey patches Grape::Swagger to camelize your API's self-documentation, while snakecasing parameters passed to your API.
58
-
59
- 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.
54
+ This also monkey-patches Grape::Swagger to camelize your API's self-documentation, while snakecasing parameters passed to your API.
60
55
 
61
- If you need to disable all camel-snake transliteration set `IntrospectiveGrape.config.camelize_parameters = false` down in `config/initializers` and do not `require` or `formatter` those patches.
56
+ If you prefer to disable all camel-snake transliterations set `IntrospectiveGrape.config.camelize_parameters = false` down in `config/initializers`.
62
57
 
63
58
  ## Authentication and authorization
64
59
 
@@ -70,7 +65,7 @@ IntrospectiveGrape::API.authentication_method = "whatever!"
70
65
 
71
66
  Pundit authorization is invoked against index?, show?, update?, create?, and destroy? methods with the model instance in question (or a new instance in the case of index).
72
67
 
73
- The joke goes that you may find you need to allow an unauthenticated user to attempt a log in, which can be handled with something like:
68
+ The joke goes that you may find you need to allow an unauthenticated user to attempt a log in, which can be handled by authorizing non-users at that endpoint with something like:
74
69
 
75
70
  ```
76
71
  def authorize!
@@ -90,10 +85,10 @@ IntrospectiveGrape's parameterization of a model begins with the `restful` decla
90
85
  The simplest app/api/v1/my_model_api.rb with the broadest functionality would look like:
91
86
 
92
87
  ```
93
- class MyModelAPI < IntrospectiveGrape::API
88
+ class MyModelApi < IntrospectiveGrape::API
94
89
  filter_on :all
95
90
 
96
- restful MyModel, [:strong, :param, :fields, :and, { nested_model_attributes: [:nested,:fields, :_destroy] }]
91
+ restful MyModel, [:strong, :param, :fields, :and, { nested_model_attributes: [:nested, :fields, :_destroy] }]
97
92
 
98
93
  class <NestedModel>Entity < Grape::Entity
99
94
  expose :id, :attribute
@@ -109,9 +104,9 @@ end
109
104
 
110
105
  This would set up all the basic RESTFUL actions with nested routes for the associated model and its association, providing a good deal of flexibility for API consumers out of the box.
111
106
 
112
- IntrospectiveGrape looks in the MyModelAPI class for grape-entity definitions. If you prefer to define your entities elsewhere you could inherit them here instead.
107
+ IntrospectiveGrape looks in the `MyModelApi` class for grape-entity definitions. If you prefer to define your entities elsewhere you can import them here instead.
113
108
 
114
- NOTE: Nested entities must be defined before their parents, inside-out, or you'll run into loading errors.
109
+ NOTE: Nested entities defined in the mounted API classes must be defined before their parents, inside-out, or you'll run into load errors.
115
110
 
116
111
  ## Customizing End Points
117
112
 
@@ -146,8 +141,6 @@ class MyModelAPI < IntrospectiveGrape::API
146
141
  end
147
142
  ```
148
143
 
149
- Please note, again, that the nested Grape::Entity is declared before its parent.
150
-
151
144
  ## Skipping a Presence Validation for a Required Field
152
145
 
153
146
  If a model has, say, a procedurally generated default for a not-null field in the database
@@ -1,64 +1,41 @@
1
- $LOAD_PATH.push File.expand_path('lib', __dir__)
2
-
3
- # Maintain your gem's version:
4
- require 'introspective_grape/version'
5
-
6
- # Describe your gem and declare its dependencies:
7
- Gem::Specification.new do |s|
8
- s.name = 'introspective_grape'
9
- s.version = IntrospectiveGrape::VERSION
10
- s.authors = ['Josh Buermann']
11
- s.email = ['buermann@gmail.com']
12
- s.homepage = 'https://github.com/buermann/introspective_grape'
13
- s.summary = 'Quickly configure Grape APIs around your database schema and models.'
14
- s.description = <<-DESC
15
- IntrospectiveGrape provides handling for deeply nested relations according to the models'
16
- `accepts_nested_attributes_for` declarations, generating all the necessary
17
- boilerplate for flexible and consistent bulk endpoints on plural associations,
18
- and building nested routes for the same.
19
- DESC
20
- s.license = 'MIT'
21
- s.metadata = { "rubygems_mfa_required" => "true" }
22
-
23
- s.files = `git ls-files`.split("\n").sort
24
-
25
- s.required_ruby_version = '> 2.5' # rubocop:disable Gemspec/RequiredRubyVersion
26
-
27
- s.add_runtime_dependency 'rails' # , '6.1' #, '> 5.2'
28
- s.add_runtime_dependency 'schema_validations'
29
- s.add_runtime_dependency 'rack'
30
-
31
- s.add_runtime_dependency 'grape' # , '1.6.0'
32
- s.add_runtime_dependency 'dry-types'
33
- s.add_runtime_dependency 'grape-entity'
34
- s.add_runtime_dependency 'grape-swagger'
35
-
36
- s.add_runtime_dependency 'kaminari'
37
- s.add_runtime_dependency 'grape-kaminari'
38
-
39
- s.add_runtime_dependency 'pundit'
40
-
41
- s.add_runtime_dependency 'camel_snake_keys', '>0.0.4'
42
-
43
- if RUBY_PLATFORM == 'java'
44
- s.add_development_dependency 'activerecord-jdbcsqlite3-adapter'
45
- else
46
- s.add_development_dependency 'sqlite3'
47
- end
48
-
49
- # testing gems
50
- s.add_development_dependency 'rspec-rails', '>= 3.0'
51
- s.add_development_dependency 'coveralls_reborn'
52
- s.add_development_dependency 'simplecov'
53
- s.add_development_dependency 'bundler-audit'
54
- s.add_development_dependency 'brakeman'
55
- s.add_development_dependency 'rubocop'
56
- s.add_development_dependency 'byebug'
57
- s.add_development_dependency 'machinist_redux'
58
-
59
- # dummy app dependencies
60
- s.add_development_dependency 'kt-paperclip'
61
- s.add_development_dependency 'rufus-mnemo'
62
- s.add_development_dependency 'devise'
63
- s.metadata['rubygems_mfa_required'] = 'true'
64
- end
1
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
2
+
3
+ # Maintain your gem's version:
4
+ require 'introspective_grape/version'
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = 'introspective_grape'
9
+ s.version = IntrospectiveGrape::VERSION
10
+ s.authors = ['Josh Buermann']
11
+ s.email = ['buermann@gmail.com']
12
+ s.homepage = 'https://github.com/buermann/introspective_grape'
13
+ s.summary = 'Quickly configure Grape APIs around your database schema and models.'
14
+ s.description = <<-DESC
15
+ IntrospectiveGrape provides handling for deeply nested relations according to the models'
16
+ `accepts_nested_attributes_for` declarations, generating all the necessary
17
+ boilerplate for flexible and consistent bulk endpoints on plural associations,
18
+ and building nested routes for the same.
19
+ DESC
20
+ s.license = 'MIT'
21
+ s.metadata = { 'rubygems_mfa_required' => 'true' }
22
+
23
+ s.files = `git ls-files`.split("\n").sort
24
+
25
+ s.required_ruby_version = '>= 3.1'
26
+
27
+ s.add_dependency 'rails' # , '6.1' #, '> 5.2'
28
+ s.add_dependency 'rack'
29
+
30
+ s.add_dependency 'grape' # , '1.6.0'
31
+ s.add_dependency 'dry-types'
32
+ s.add_dependency 'grape-entity'
33
+ s.add_dependency 'grape-swagger'
34
+
35
+ s.add_dependency 'kaminari'
36
+ s.add_dependency 'grape-kaminari'
37
+
38
+ s.add_dependency 'pundit'
39
+
40
+ s.add_dependency 'camel_snake_keys'
41
+ end