introspective_grape 0.5.0 → 0.5.2

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
2
  SHA256:
3
- metadata.gz: d15f31a850811633ad737c414309293b36b8cacb15508468e5155a5b6aec2bed
4
- data.tar.gz: 17b3a773228928342af7c692f2ac62352cd1bcdda2695351cae9cf56c449fc82
3
+ metadata.gz: 1221cfb7bde9b3896a0c11c595c685198a10a88120cb7ad0711baca8b954e7a0
4
+ data.tar.gz: 18ef790d77cc390818ea413f04c3ffe0f87a60350a5a7157bb73e66ab9693360
5
5
  SHA512:
6
- metadata.gz: acf6d1def5d4df6c3438e67d1743c6dfe86a00b44044ce8b709e7800bca20096180084a0bb994b77535c4a956997df25c4dde8349f63b7831d17fe494e900c04
7
- data.tar.gz: 509de38fd9a074d493caf0389bdb10d8bfad3fe4a145e3f1c2a9ff30b33d2efc2fbfa466f6e743d081fa678035f05214b8c71f6305562f34a65faac530f1c96b
6
+ metadata.gz: fdc88a2e154ab024c70c978e553533d79d67b31194ae47e1fa6b923ffa83df585b317aabc2c5159ff9ef63881d235df0ca2cbd9ce28d303213029f6284f8288c
7
+ data.tar.gz: f95cddc2dfe36efb3cf54f572d977c10573d658410a876dcf2adba43fb82ea066c1eea53582fa659079ff3211a638edcb0682b156abf040f8a4469bdd330bf87
@@ -0,0 +1,32 @@
1
+ name: security
2
+ on: push
3
+ jobs:
4
+ security:
5
+ name: Security
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - name: Checkout Repository
9
+ uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.6.2
14
+ - name: Cache Ruby Gems
15
+ uses: actions/cache@v2
16
+ with:
17
+ path: vendor/bundle
18
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
19
+ restore-keys: |
20
+ ${{ runner.os }}-gems-
21
+ - name: Bundle Install
22
+ run: |
23
+ gem install bundler
24
+ bundle config path vendor/bundle
25
+ bundle install --jobs 4 --retry 3
26
+ - name: Security Checks
27
+ run: |
28
+ bundle exec brakeman -z
29
+ gem install bundle-audit
30
+ bundle-audit update
31
+ bundle-audit
32
+
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+
2
+ 0.5.2 02/07/2022
3
+ ================
4
+
5
+ Lock down compatible Grape version to 1.6.0, as the next version has breaking changes for classes inheriting from Grape::Validator::Base.
6
+
7
+ 0.5.1 02/07/2022
8
+ ================
9
+
10
+ Removed stray require of 'byebug'.
11
+
1
12
  0.5.0 10/20/2021
2
13
  ================
3
14
 
data/README.md CHANGED
@@ -305,8 +305,7 @@ myself, but would be trivial to make more atomistic.
305
305
  ## Documenting Endpoints
306
306
 
307
307
  If you wish to provide additional documentation for end points you can define
308
- `self.<index,show,update,create,destroy>_documentation` class methods in the API class (or extend them
309
- from a documentation module, which would be preferable).
308
+ `self.<index,show,update,create,destroy>_documentation(name)` class methods in the API class (or extend them from a documentation module, which would be preferable).
310
309
 
311
310
  ## Grape Hooks - The Precedence of Declaration Matters
312
311
 
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.add_runtime_dependency 'schema_validations'
29
29
  s.add_runtime_dependency 'rack'
30
30
 
31
- s.add_runtime_dependency 'grape'
31
+ s.add_runtime_dependency 'grape', '1.6.0'
32
32
  s.add_runtime_dependency 'dry-types'
33
33
  s.add_runtime_dependency 'grape-entity'
34
34
  s.add_runtime_dependency 'grape-swagger'
@@ -1,6 +1,6 @@
1
1
  require 'action_controller'
2
2
  require 'kaminari'
3
- require 'byebug'
3
+ #require 'byebug'
4
4
  require 'grape-kaminari'
5
5
  require 'introspective_grape/validators'
6
6
 
@@ -408,7 +408,7 @@ module IntrospectiveGrape
408
408
  # Check if it's a file attachment, look for an override class from the model,
409
409
  # check PG2RUBY, use the database type, or fail over to a String:
410
410
  uploaded_file?(model, field) ||
411
- check_model_for_type(model, field) ||
411
+ check_model_for_type(model, field) ||
412
412
  PG2RUBY[db_type] ||
413
413
  db_type_constant(db_type) ||
414
414
  String # default to String if nothing else works
@@ -1,56 +1,56 @@
1
- module IntrospectiveGrape
2
- module Traversal
3
- # For deeply nested endpoints we want to present the record being affected, these
4
- # methods traverse down from the parent instance to the child model associations
5
- # of the deeply nested route.
6
-
7
- def find_leaves(routes, record, params)
8
- # Traverse down our route and find the leaf's siblings from its parent, e.g.
9
- # project/#/teams/#/team_users ~> project.find.teams.find.team_users
10
- # (the traversal of the intermediate nodes occurs in find_leaf())
11
- return record if routes.size < 2 # the leaf is the root
12
-
13
- record = find_leaf(routes, record, params) || return
14
-
15
- assoc = routes.last
16
- if assoc.many?
17
- leaves = record.send( assoc.reflection.name ).includes( default_includes(assoc.model) )
18
- verify_records_found(leaves, routes)
19
- leaves
20
- else
21
- # has_one associations don't return a CollectionProxy and so don't support
22
- # eager loading.
23
- record.send( assoc.reflection.name )
24
- end
25
- end
26
-
27
- def verify_records_found(leaves, routes)
28
- return if (leaves.map(&:class) - [routes.last.model]).empty?
29
-
30
- raise ActiveRecord::RecordNotFound.new("Records contain the wrong models, they should all be #{routes.last.model.name}, found #{records.map(&:class).map(&:name).join(',')}")
31
- end
32
-
33
- def find_leaf(routes, record, params)
34
- return record unless routes.size > 1
35
-
36
- # For deeply nested routes we need to search from the root of the API to the leaf
37
- # of its nested associations in order to guarantee the validity of the relationship,
38
- # the authorization on the parent model, and the sanity of passed parameters.
39
- routes[1..-1].each do |r|
40
- if record && params[r.key]
41
- ref = r.reflection
42
- record = record.send(ref.name).where( id: params[r.key] ).first if ref
43
- end
44
- end
45
-
46
- verify_record_found(routes, params, record)
47
- record
48
- end
49
-
50
- def verify_record_found(routes, params, record)
51
- return unless params[routes.last.key] && record.class != routes.last.model
52
-
53
- raise ActiveRecord::RecordNotFound.new("No #{routes.last.model.name} with ID '#{params[routes.last.key]}'")
54
- end
55
- end
56
- end
1
+ module IntrospectiveGrape
2
+ module Traversal
3
+ # For deeply nested endpoints we want to present the record being affected, these
4
+ # methods traverse down from the parent instance to the child model associations
5
+ # of the deeply nested route.
6
+
7
+ def find_leaves(routes, record, params)
8
+ # Traverse down our route and find the leaf's siblings from its parent, e.g.
9
+ # project/#/teams/#/team_users ~> project.find.teams.find.team_users
10
+ # (the traversal of the intermediate nodes occurs in find_leaf())
11
+ return record if routes.size < 2 # the leaf is the root
12
+
13
+ record = find_leaf(routes, record, params) || return
14
+
15
+ assoc = routes.last
16
+ if assoc.many?
17
+ leaves = record.send( assoc.reflection.name ).includes( default_includes(assoc.model) )
18
+ verify_records_found(leaves, routes)
19
+ leaves
20
+ else
21
+ # has_one associations don't return a CollectionProxy and so don't support
22
+ # eager loading.
23
+ record.send( assoc.reflection.name )
24
+ end
25
+ end
26
+
27
+ def verify_records_found(leaves, routes)
28
+ return if (leaves.map(&:class) - [routes.last.model]).empty?
29
+
30
+ raise ActiveRecord::RecordNotFound.new("Records contain the wrong models, they should all be #{routes.last.model.name}, found #{records.map(&:class).map(&:name).join(',')}")
31
+ end
32
+
33
+ def find_leaf(routes, record, params)
34
+ return record unless routes.size > 1
35
+
36
+ # For deeply nested routes we need to search from the root of the API to the leaf
37
+ # of its nested associations in order to guarantee the validity of the relationship,
38
+ # the authorization on the parent model, and the sanity of passed parameters.
39
+ routes[1..-1].each do |r|
40
+ if record && params[r.key]
41
+ ref = r.reflection
42
+ record = record.send(ref.name).where( id: params[r.key] ).first if ref
43
+ end
44
+ end
45
+
46
+ verify_record_found(routes, params, record)
47
+ record
48
+ end
49
+
50
+ def verify_record_found(routes, params, record)
51
+ return unless params[routes.last.key] && record.class != routes.last.model
52
+
53
+ raise ActiveRecord::RecordNotFound.new("No #{routes.last.model.name} with ID '#{params[routes.last.key]}'")
54
+ end
55
+ end
56
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IntrospectiveGrape
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.2'
5
5
  end
@@ -0,0 +1 @@
1
+ 2.6.0
@@ -14,6 +14,15 @@ class Dummy::CompanyAPI < IntrospectiveGrape::API
14
14
  present params
15
15
  end
16
16
 
17
+ desc "Test kaminari pagination in a custom index"
18
+ params do
19
+ use :pagination
20
+ end
21
+ get '/paginated/list' do
22
+ authorize Company.new, :index?
23
+ companies = Company.all
24
+ present paginate(companies), using: CompanyEntity
25
+ end
17
26
  end
18
27
 
19
28
  class CompanyEntity < Grape::Entity
@@ -27,6 +27,15 @@ describe Dummy::CompanyAPI, type: :request do
27
27
  json.first['id'].should eq Company.first.id
28
28
  response.headers.slice("X-Total", "X-Total-Pages", "X-Per-Page", "X-Page", "X-Next-Page", "X-Prev-Page", "X-Offset").values.should eq ["30", "2", "25", "1", "2", "", "0"]
29
29
  end
30
+
31
+ it "should allow pagination in a custom index" do
32
+ Company.destroy_all
33
+ 30.times { Company.make! }
34
+
35
+ get '/api/v1/companies/paginated/list'
36
+ response.should be_successful
37
+ response.headers.slice("X-Total", "X-Total-Pages", "X-Per-Page", "X-Page", "X-Next-Page", "X-Prev-Page", "X-Offset").values.should eq ["30", "2", "25", "1", "2", "", "0"]
38
+ end
30
39
  end
31
40
 
32
41
  before :all do
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.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Buermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-27 00:00:00.000000000 Z
11
+ date: 2022-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: grape
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.6.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.6.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: dry-types
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -344,6 +344,7 @@ extensions: []
344
344
  extra_rdoc_files: []
345
345
  files:
346
346
  - ".github/workflows/lint.yml"
347
+ - ".github/workflows/security.yml"
347
348
  - ".github/workflows/test.yml"
348
349
  - ".gitignore"
349
350
  - ".rubocop.yml"
@@ -375,6 +376,7 @@ files:
375
376
  - lib/introspective_grape/validators.rb
376
377
  - lib/introspective_grape/version.rb
377
378
  - lib/tasks/introspective_grape_tasks.rake
379
+ - spec/dummy/.ruby-version
378
380
  - spec/dummy/Gemfile
379
381
  - spec/dummy/README.rdoc
380
382
  - spec/dummy/Rakefile
@@ -544,6 +546,7 @@ signing_key:
544
546
  specification_version: 4
545
547
  summary: Quickly configure Grape APIs around your database schema and models.
546
548
  test_files:
549
+ - spec/dummy/.ruby-version
547
550
  - spec/dummy/Gemfile
548
551
  - spec/dummy/README.rdoc
549
552
  - spec/dummy/Rakefile