grape-utils 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +25 -1
- data/README.md +1 -1
- data/grape-utils-0.1.2.gem +0 -0
- data/lib/grape_utils/helpers.rb +5 -0
- data/lib/grape_utils/templates/create.rb +2 -2
- data/lib/grape_utils/templates/crud.rb +5 -1
- data/lib/grape_utils/templates/delete.rb +2 -1
- data/lib/grape_utils/templates/index.rb +1 -3
- data/lib/grape_utils/templates/show.rb +2 -1
- data/lib/grape_utils/templates/update.rb +2 -1
- data/lib/grape_utils/version.rb +1 -1
- metadata +7 -7
- data/grape-utils.gemspec +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56f2704d0f802aa4a8916b0785558f18b98e2d4177ad065375ce5cc78e93e002
|
4
|
+
data.tar.gz: 787016613713840721824e1fbed84597cb25130e3b71bc36ceeff56b22faa0c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50035d9d19c2d8b8cb6ac341867d01d3fd64df15f68d55f2005646918be5d80c1313aa92a46e7775b539ae35bc93bc53d665072e946f3d47502e30b237f54901
|
7
|
+
data.tar.gz: 836f7914eca85a16ab5e7ffef11400ec4ca9e6b00b887ad304accb4f700d212528434b46694dd6dd5624d584c14ac455f17279f44716f646d69308aaa697baf8
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grape-utils (0.1.
|
4
|
+
grape-utils (0.1.3)
|
5
5
|
grape
|
6
6
|
grape-entity
|
7
7
|
grape-kaminari
|
@@ -14,10 +14,18 @@ GEM
|
|
14
14
|
i18n (>= 1.6, < 2)
|
15
15
|
minitest (>= 5.1)
|
16
16
|
tzinfo (~> 2.0)
|
17
|
+
airborne (0.3.7)
|
18
|
+
activesupport
|
19
|
+
rack
|
20
|
+
rack-test (>= 1.1.0, < 2.0)
|
21
|
+
rest-client (>= 2.0.2, < 3.0)
|
22
|
+
rspec (~> 3.8)
|
17
23
|
ast (2.4.2)
|
18
24
|
builder (3.2.4)
|
19
25
|
concurrent-ruby (1.2.2)
|
20
26
|
diff-lcs (1.5.0)
|
27
|
+
domain_name (0.5.20190701)
|
28
|
+
unf (>= 0.0.5, < 1.0.0)
|
21
29
|
dry-core (1.0.1)
|
22
30
|
concurrent-ruby (~> 1.0)
|
23
31
|
zeitwerk (~> 2.6)
|
@@ -45,6 +53,9 @@ GEM
|
|
45
53
|
grape-kaminari (0.4.5)
|
46
54
|
grape (>= 1.6.1)
|
47
55
|
kaminari-grape
|
56
|
+
http-accept (1.7.0)
|
57
|
+
http-cookie (1.0.5)
|
58
|
+
domain_name (~> 0.5)
|
48
59
|
i18n (1.14.1)
|
49
60
|
concurrent-ruby (~> 1.0)
|
50
61
|
json (2.6.3)
|
@@ -53,12 +64,16 @@ GEM
|
|
53
64
|
grape
|
54
65
|
kaminari-core (~> 1.0)
|
55
66
|
language_server-protocol (3.17.0.3)
|
67
|
+
mime-types (3.4.1)
|
68
|
+
mime-types-data (~> 3.2015)
|
69
|
+
mime-types-data (3.2022.0105)
|
56
70
|
minitest (5.20.0)
|
57
71
|
multi_json (1.15.0)
|
58
72
|
mustermann (3.0.0)
|
59
73
|
ruby2_keywords (~> 0.0.1)
|
60
74
|
mustermann-grape (1.0.2)
|
61
75
|
mustermann (>= 1.0.0)
|
76
|
+
netrc (0.11.0)
|
62
77
|
parallel (1.23.0)
|
63
78
|
parser (3.2.2.4)
|
64
79
|
ast (~> 2.4.1)
|
@@ -72,6 +87,11 @@ GEM
|
|
72
87
|
rainbow (3.1.1)
|
73
88
|
rake (13.1.0)
|
74
89
|
regexp_parser (2.8.2)
|
90
|
+
rest-client (2.1.0)
|
91
|
+
http-accept (>= 1.7.0, < 2.0)
|
92
|
+
http-cookie (>= 1.0.2, < 2.0)
|
93
|
+
mime-types (>= 1.16, < 4.0)
|
94
|
+
netrc (~> 0.8)
|
75
95
|
rexml (3.2.6)
|
76
96
|
rspec (3.12.0)
|
77
97
|
rspec-core (~> 3.12.0)
|
@@ -103,6 +123,9 @@ GEM
|
|
103
123
|
ruby2_keywords (0.0.5)
|
104
124
|
tzinfo (2.0.6)
|
105
125
|
concurrent-ruby (~> 1.0)
|
126
|
+
unf (0.1.4)
|
127
|
+
unf_ext
|
128
|
+
unf_ext (0.0.8.2)
|
106
129
|
unicode-display_width (2.5.0)
|
107
130
|
zeitwerk (2.6.12)
|
108
131
|
|
@@ -110,6 +133,7 @@ PLATFORMS
|
|
110
133
|
x86_64-linux
|
111
134
|
|
112
135
|
DEPENDENCIES
|
136
|
+
airborne
|
113
137
|
grape
|
114
138
|
grape-entity
|
115
139
|
grape-kaminari
|
data/README.md
CHANGED
@@ -48,7 +48,7 @@ module AwesomeAPI
|
|
48
48
|
class Foo < Base
|
49
49
|
|
50
50
|
resource :foos do
|
51
|
-
mount Grape::Utils::Templates::Index, with: { model: Foo,
|
51
|
+
mount Grape::Utils::Templates::Index, with: { model: Foo, scope: Foo.all, entity: Entities::Foo }
|
52
52
|
mount Grape::Utils::Templates::Show, with: { model: Foo, entity: Entities::Foo }
|
53
53
|
mount Grape::Utils::Templates::Create, with: { model: Foo, entity: Entities::Foo}
|
54
54
|
mount Grape::Utils::Templates::Update, with: { model: Foo.all, entity: Entities::Foo }
|
Binary file
|
data/lib/grape_utils/helpers.rb
CHANGED
@@ -6,6 +6,11 @@ module Grape
|
|
6
6
|
def permitted_params
|
7
7
|
@permitted_params ||= declared(params, include_missing: false)
|
8
8
|
end
|
9
|
+
|
10
|
+
def calculate_scope(scope:, model:)
|
11
|
+
initial_scope = scope.is_a?(Proc) ? instance_eval(&scope) : scope
|
12
|
+
initial_scope || model.all
|
13
|
+
end
|
9
14
|
end
|
10
15
|
end
|
11
16
|
end
|
@@ -14,8 +14,8 @@ module Grape
|
|
14
14
|
using: configuration[:entity].documentation
|
15
15
|
end
|
16
16
|
post do
|
17
|
-
|
18
|
-
|
17
|
+
default_params = configuration[:default_params] || {}
|
18
|
+
resource = configuration[:model].create!(default_params.merge(permitted_params))
|
19
19
|
present resource, with: configuration[:entity]
|
20
20
|
end
|
21
21
|
end
|
@@ -7,22 +7,26 @@ module Grape
|
|
7
7
|
class Crud < ::Grape::API
|
8
8
|
mounted do
|
9
9
|
mount Templates::Index, with: { model: configuration[:model],
|
10
|
-
|
10
|
+
scope: configuration[:scope],
|
11
11
|
entity: configuration[:entity] }
|
12
12
|
|
13
13
|
mount Templates::Create, with: { model: configuration[:model],
|
14
|
+
scope: configuration[:scope],
|
14
15
|
entity: configuration[:entity],
|
15
16
|
required_params: configuration[:required_params] }
|
16
17
|
|
17
18
|
mount Templates::Show, with: { model: configuration[:model],
|
19
|
+
scope: configuration[:scope],
|
18
20
|
entity: configuration[:entity],
|
19
21
|
column_id: configuration[:column_id] }
|
20
22
|
|
21
23
|
mount Templates::Update, with: { model: configuration[:model],
|
24
|
+
scope: configuration[:scope],
|
22
25
|
entity: configuration[:entity],
|
23
26
|
column_id: configuration[:column_id] }
|
24
27
|
|
25
28
|
mount Templates::Delete, with: { model: configuration[:model],
|
29
|
+
scope: configuration[:scope],
|
26
30
|
entity: configuration[:entity],
|
27
31
|
column_id: configuration[:column_id] }
|
28
32
|
end
|
@@ -11,7 +11,8 @@ module Grape
|
|
11
11
|
route_param :id, type: String do
|
12
12
|
desc "Deletes an instances of #{configuration[:model].name}"
|
13
13
|
delete do
|
14
|
-
|
14
|
+
scope = calculate_scope(scope: configuration[:scope], model: configuration[:model])
|
15
|
+
resource = scope.find_by!((configuration[:column_id] || :id) => params[:id])
|
15
16
|
resource.destroy!
|
16
17
|
|
17
18
|
status(204)
|
@@ -16,9 +16,7 @@ module Grape
|
|
16
16
|
use :pagination, per_page: 10, max_per_page: 30
|
17
17
|
end
|
18
18
|
get do
|
19
|
-
|
20
|
-
|
21
|
-
list = index.is_a?(Proc) ? instance_eval(&index) : index
|
19
|
+
list = calculate_scope(scope: configuration[:scope], model: configuration[:model])
|
22
20
|
|
23
21
|
present list, with: configuration[:entity]
|
24
22
|
end
|
@@ -11,7 +11,8 @@ module Grape
|
|
11
11
|
route_param :id, type: String do
|
12
12
|
desc "Details of a #{configuration[:model].name}"
|
13
13
|
get do
|
14
|
-
|
14
|
+
scope = calculate_scope(scope: configuration[:scope], model: configuration[:model])
|
15
|
+
resource = scope.find_by!((configuration[:column_id] || :id) => params[:id])
|
15
16
|
present resource, with: configuration[:entity]
|
16
17
|
end
|
17
18
|
end
|
@@ -14,7 +14,8 @@ module Grape
|
|
14
14
|
requires :none, using: configuration[:entity].documentation
|
15
15
|
end
|
16
16
|
patch do
|
17
|
-
|
17
|
+
scope = configuration[:scope] || configuration[:model]
|
18
|
+
resource = scope.find_by!((configuration[:column_id] || :id) => params[:id])
|
18
19
|
resource.update!(permitted_params.except(:id))
|
19
20
|
|
20
21
|
present resource, with: configuration[:entity]
|
data/lib/grape_utils/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nix41
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description:
|
84
84
|
email:
|
85
85
|
- acprieto41@gmail.com
|
86
86
|
executables: []
|
@@ -96,7 +96,7 @@ files:
|
|
96
96
|
- LICENSE.txt
|
97
97
|
- README.md
|
98
98
|
- Rakefile
|
99
|
-
- grape-utils.
|
99
|
+
- grape-utils-0.1.2.gem
|
100
100
|
- lib/grape-utils.rb
|
101
101
|
- lib/grape_utils.rb
|
102
102
|
- lib/grape_utils/helpers.rb
|
@@ -115,7 +115,7 @@ metadata:
|
|
115
115
|
homepage_uri: https://github.com/Nix41/grape-utils
|
116
116
|
source_code_uri: https://github.com/Nix41/grape-utils
|
117
117
|
changelog_uri: https://github.com/Nix41/grape-utils/blob/main/CHANGELOG.md
|
118
|
-
post_install_message:
|
118
|
+
post_install_message:
|
119
119
|
rdoc_options: []
|
120
120
|
require_paths:
|
121
121
|
- lib
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
133
|
rubygems_version: 3.4.10
|
134
|
-
signing_key:
|
134
|
+
signing_key:
|
135
135
|
specification_version: 4
|
136
136
|
summary: Grape Utils for building APIs
|
137
137
|
test_files: []
|
data/grape-utils.gemspec
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift File.expand_path("lib", __dir__)
|
4
|
-
require_relative "lib/grape_utils/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "grape-utils"
|
8
|
-
spec.version = Grape::Utils::VERSION
|
9
|
-
spec.authors = ["Nix41"]
|
10
|
-
spec.email = ["acprieto41@gmail.com"]
|
11
|
-
|
12
|
-
spec.summary = "Grape Utils for building APIs"
|
13
|
-
# spec.description = "TODO: Write a longer description or delete this line."
|
14
|
-
spec.homepage = "https://github.com/Nix41/grape-utils"
|
15
|
-
spec.license = "MIT"
|
16
|
-
spec.required_ruby_version = ">= 2.6.0"
|
17
|
-
|
18
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
-
spec.metadata["source_code_uri"] = "https://github.com/Nix41/grape-utils"
|
20
|
-
spec.metadata["changelog_uri"] = "https://github.com/Nix41/grape-utils/blob/main/CHANGELOG.md"
|
21
|
-
|
22
|
-
# Specify which files should be added to the gem when it is released.
|
23
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
-
spec.files = Dir.chdir(__dir__) do
|
25
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
-
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
27
|
-
end
|
28
|
-
end
|
29
|
-
spec.bindir = "exe"
|
30
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = ["lib"]
|
32
|
-
|
33
|
-
spec.add_dependency "grape"
|
34
|
-
spec.add_dependency "grape-entity"
|
35
|
-
spec.add_dependency "grape-kaminari"
|
36
|
-
spec.add_development_dependency "rspec"
|
37
|
-
spec.add_development_dependency "rubocop"
|
38
|
-
|
39
|
-
# For more information and examples about making a new gem, check out our
|
40
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
41
|
-
end
|