rails-rapido 0.9.3 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/README.md +15 -1
- data/lib/rapido/api_controller.rb +52 -4
- data/lib/rapido/controller.rb +8 -0
- data/lib/rapido/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f94a2c707b7325512f48fee292918d01321378d6cfb6d87bbe9dc92e71a60ed
|
4
|
+
data.tar.gz: 954e3e1b070f353a3f4023202f301f52dc620498ff54aeea1cf7bc8e65a5dfd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a92e60537cca20540113fb1b6186ac9469e11d024127ddeda4391249a926909897198cc56472d7cdeeb80a18d41922601615199934ffc65cd1c993528662c63
|
7
|
+
data.tar.gz: b08530e8028fefcff3d737bb5d6ebd2580fe7949f0eda51b3c7747644433c56c800b4afb901d4b4a49e113fb384b37472336d097d595a722e5530dbb2cf9211a
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.1.0
|
data/README.md
CHANGED
@@ -14,8 +14,14 @@ Below is a typical example of a class using Rapido. More examples are available
|
|
14
14
|
|
15
15
|
class DocumentsController < ApplicationController
|
16
16
|
include Rapido::ApiController
|
17
|
+
|
18
|
+
allow_if do
|
19
|
+
current_user.is_editor?
|
20
|
+
end
|
21
|
+
|
22
|
+
allow_only :create, :delete, :index, :show, :update
|
17
23
|
|
18
|
-
attr_permitted :file, file_name, :category
|
24
|
+
attr_permitted :file, :file_name, :category
|
19
25
|
|
20
26
|
belongs_to :user, getter: :current_user
|
21
27
|
|
@@ -46,6 +52,14 @@ end
|
|
46
52
|
|
47
53
|
## API
|
48
54
|
|
55
|
+
### `allow_if`
|
56
|
+
|
57
|
+
Accepts a method name as symbol or block. Method supplied or block must return true to allow the action to proceed, otherwise a status 401 is returned with no body.
|
58
|
+
|
59
|
+
### `allow_only`
|
60
|
+
|
61
|
+
Accepts a list of symbols. These symbols specify the controller actions that are allowed for this controller.
|
62
|
+
|
49
63
|
### `attr_permitted`
|
50
64
|
|
51
65
|
Accepts a list of symbols. These symbols specify the attributes that are supplied to StrongParameters as permitted parameters in `create` and `update` actions.
|
@@ -18,21 +18,61 @@ module Rapido
|
|
18
18
|
end
|
19
19
|
|
20
20
|
before_action :permit_only_allowed_actions
|
21
|
+
|
22
|
+
before_action :permit_only_if
|
21
23
|
end
|
22
24
|
|
23
25
|
def index
|
24
26
|
return if performed?
|
25
|
-
|
27
|
+
if request.format.to_sym == :json
|
28
|
+
if(params["filename"])
|
29
|
+
send_data resource_collection_presenter.as_json.to_json, filename: params["filename"]
|
30
|
+
else
|
31
|
+
render json: resource_collection_presenter
|
32
|
+
end
|
33
|
+
elsif request.format.to_sym == :xml
|
34
|
+
if(params["filename"])
|
35
|
+
send_data resource_collection_presenter.to_xml, filename: params["filename"]
|
36
|
+
else
|
37
|
+
render xml: resource_collection_presenter
|
38
|
+
end
|
39
|
+
elsif request.format.to_sym == :csv
|
40
|
+
if(params["filename"])
|
41
|
+
send_data resource_collection_presenter.to_csv, filename: params["filename"]
|
42
|
+
else
|
43
|
+
render plain: resource_collection_presenter.send("to_csv")
|
44
|
+
end
|
45
|
+
else
|
46
|
+
render json: resource_collection_presenter
|
47
|
+
end
|
26
48
|
end
|
27
49
|
|
28
50
|
def show
|
29
51
|
return if performed?
|
30
52
|
if request.format.to_sym == :json
|
31
|
-
|
53
|
+
if(params["filename"])
|
54
|
+
send_data resource_presenter.as_json.to_json, filename: params["filename"]
|
55
|
+
else
|
56
|
+
render json: resource_presenter
|
57
|
+
end
|
58
|
+
elsif request.format.to_sym == :html && !request.headers["accept"].include?("application/json")
|
59
|
+
if(params["filename"])
|
60
|
+
send_data resource_presenter.to_html, filename: params["filename"]
|
61
|
+
else
|
62
|
+
render html: resource_presenter.to_html.html_safe
|
63
|
+
end
|
32
64
|
elsif request.format.to_sym == :xml
|
33
|
-
|
65
|
+
if(params["filename"])
|
66
|
+
send_data resource_presenter.to_xml, filename: params["filename"]
|
67
|
+
else
|
68
|
+
render xml: resource_presenter
|
69
|
+
end
|
34
70
|
elsif request.format.to_sym == :csv
|
35
|
-
|
71
|
+
if(params["filename"])
|
72
|
+
send_data resource_presenter.to_csv, filename: params["filename"]
|
73
|
+
else
|
74
|
+
render plain: resource_presenter.send("to_csv")
|
75
|
+
end
|
36
76
|
else
|
37
77
|
render json: resource_presenter
|
38
78
|
end
|
@@ -117,6 +157,14 @@ module Rapido
|
|
117
157
|
head :unauthorized unless allowed_actions.include?(params[:action].to_sym)
|
118
158
|
end
|
119
159
|
|
160
|
+
def permit_only_if
|
161
|
+
if(allow_if)
|
162
|
+
unless (allow_if.is_a?(Symbol) ? send(allow_if) : instance_eval(&allow_if))
|
163
|
+
head :unauthorized
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
120
168
|
def resource_presenter(new_resource = nil)
|
121
169
|
@resource_presenter ||= begin
|
122
170
|
args = presenter_args.nil? ? nil : presenter_args.map { |arg| params[arg] }
|
data/lib/rapido/controller.rb
CHANGED
@@ -28,6 +28,10 @@ module Rapido
|
|
28
28
|
@allowed_actions = ary
|
29
29
|
end
|
30
30
|
|
31
|
+
def allow_if(str = nil, &block)
|
32
|
+
@allow_if = str || block
|
33
|
+
end
|
34
|
+
|
31
35
|
def attr_permitted(*ary)
|
32
36
|
@resource_permitted_params = ary
|
33
37
|
end
|
@@ -101,6 +105,10 @@ module Rapido
|
|
101
105
|
setting(:allowed_actions)
|
102
106
|
end
|
103
107
|
|
108
|
+
def allow_if
|
109
|
+
setting(:allow_if)
|
110
|
+
end
|
111
|
+
|
104
112
|
def build_resource(params = {})
|
105
113
|
return owner.send('build_' + resource_class_name, params) if setting(:has_one)
|
106
114
|
return owner.send(resource_class_name.pluralize).build(params) if owner && owner.respond_to?(resource_class_name.pluralize)
|
data/lib/rapido/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-rapido
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Kirst
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,7 +68,7 @@ homepage: https://github.com/jskirst/rapido
|
|
68
68
|
licenses:
|
69
69
|
- MIT
|
70
70
|
metadata: {}
|
71
|
-
post_install_message:
|
71
|
+
post_install_message:
|
72
72
|
rdoc_options: []
|
73
73
|
require_paths:
|
74
74
|
- lib
|
@@ -83,8 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
87
|
-
signing_key:
|
86
|
+
rubygems_version: 3.3.3
|
87
|
+
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: Rails API Dryer-o
|
90
90
|
test_files: []
|