ree_lib 1.0.77 → 1.0.79
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/ree_lib/packages/ree_roda/package/ree_roda/plugins/ree_routes.rb +40 -36
- data/lib/ree_lib/packages/ree_roda/spec/ree_roda/app_spec.rb +20 -0
- data/lib/ree_lib/packages/ree_routes/package/ree_routes/route.rb +1 -1
- data/lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb +6 -0
- data/lib/ree_lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31ed7dbe4d9b99ab6768b88017dc9c1f8b59496dd2d099c180098eb1d3a3e538
|
4
|
+
data.tar.gz: 2abb0c70b8ace5e208a6cd74f9e5c1aa6580c8fa8de680a965fe43c3a7e348f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4bd30446b0f1e6fbe9f8b5a28de4a1ec4bc1ff0c84ad3685b8f82236f41332fc8370fa3d837806b6724f637a5cc4c26d6b22065f0b08f425d2af54758ee2608
|
7
|
+
data.tar.gz: cb879dd0cff6800e9dc0dacaf52b1bced2c24ff81f0b8edc72bc1d2f2491521a7bbcdc5c2dbe5accd5d62502b609b26f19c75300f9f74d2aa3141f4ef9a05759
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ree_lib (1.0.
|
4
|
+
ree_lib (1.0.79)
|
5
5
|
binding_of_caller (~> 1.0.0)
|
6
6
|
i18n (~> 1.12.0)
|
7
7
|
loofah (~> 2.18.0)
|
@@ -45,7 +45,7 @@ GEM
|
|
45
45
|
oj (3.13.23)
|
46
46
|
pg (1.4.6)
|
47
47
|
public_suffix (5.0.1)
|
48
|
-
racc (1.7.
|
48
|
+
racc (1.7.3)
|
49
49
|
rack (3.0.5)
|
50
50
|
rack-test (2.0.2)
|
51
51
|
rack (>= 1.3)
|
@@ -71,50 +71,54 @@ class Roda
|
|
71
71
|
def route_proc(route, context)
|
72
72
|
Proc.new do |r|
|
73
73
|
r.send(route.request_method) do
|
74
|
-
|
75
|
-
r.
|
74
|
+
if route.override
|
75
|
+
r.instance_exec(r, &route.override)
|
76
|
+
else
|
77
|
+
r.send(route.respond_to) do
|
78
|
+
r.env["warden"].authenticate!(scope: route.warden_scope)
|
76
79
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
+
if context.opts[:ree_routes_before]
|
81
|
+
r.instance_exec(@_request, route.warden_scope, &r.scope.opts[:ree_routes_before])
|
82
|
+
end
|
80
83
|
|
81
|
-
|
84
|
+
params = r.params
|
82
85
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
if r.body
|
87
|
+
body = begin
|
88
|
+
JSON.parse(r.body.read)
|
89
|
+
rescue => e
|
90
|
+
{}
|
91
|
+
end
|
89
92
|
|
90
|
-
|
91
|
-
|
93
|
+
params = params.merge(body)
|
94
|
+
end
|
92
95
|
|
93
|
-
|
96
|
+
not_blank = ReeObject::NotBlank.new
|
94
97
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
+
filtered_params = ReeHash::TransformValues.new.call(params) do |k, v|
|
99
|
+
v.is_a?(Array) ? v.select { not_blank.call(_1) } : v
|
100
|
+
end
|
98
101
|
|
99
|
-
|
100
|
-
|
102
|
+
accessor = r.env["warden"].user(route.warden_scope)
|
103
|
+
action_result = get_cached_action(route).call(accessor, filtered_params)
|
101
104
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
105
|
+
if route.serializer
|
106
|
+
serialized_result = get_cached_serializer(route).serialize(action_result)
|
107
|
+
else
|
108
|
+
serialized_result = {}
|
109
|
+
end
|
107
110
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
111
|
+
case route.request_method
|
112
|
+
when :post
|
113
|
+
r.response.status = 201
|
114
|
+
ReeJson::ToJson.new.call(serialized_result)
|
115
|
+
when :put, :delete, :patch
|
116
|
+
r.response.status = 204
|
117
|
+
""
|
118
|
+
else
|
119
|
+
r.response.status = 200
|
120
|
+
ReeJson::ToJson.new.call(serialized_result)
|
121
|
+
end
|
118
122
|
end
|
119
123
|
end
|
120
124
|
|
@@ -152,7 +156,7 @@ class Roda
|
|
152
156
|
route_procs.each do |route_proc|
|
153
157
|
r.instance_exec(r, &route_proc)
|
154
158
|
end
|
155
|
-
|
159
|
+
|
156
160
|
nil
|
157
161
|
end
|
158
162
|
|
@@ -116,6 +116,20 @@ RSpec.describe ReeRoda::App do
|
|
116
116
|
serializer :serializer, **opts
|
117
117
|
end
|
118
118
|
|
119
|
+
get "api/action/:action_id/test_override" do
|
120
|
+
summary "Subaction"
|
121
|
+
warden_scope :visitor
|
122
|
+
sections "some_action"
|
123
|
+
action :action_cmd, **opts
|
124
|
+
serializer :serializer, **opts
|
125
|
+
override do |r|
|
126
|
+
r.json do
|
127
|
+
r.response.status = 200
|
128
|
+
"result"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
119
133
|
get "api/action/:id/subaction" do
|
120
134
|
summary "Subaction"
|
121
135
|
warden_scope :visitor
|
@@ -233,6 +247,12 @@ RSpec.describe ReeRoda::App do
|
|
233
247
|
expect(last_response.body).to eq("{\"result\":\"action_cmd\"}")
|
234
248
|
}
|
235
249
|
|
250
|
+
it {
|
251
|
+
get "api/action/:action_id/test_override"
|
252
|
+
expect(last_response.status).to eq(200)
|
253
|
+
expect(last_response.body).to eq("result")
|
254
|
+
}
|
255
|
+
|
236
256
|
it {
|
237
257
|
post "api/action/1/subaction/2"
|
238
258
|
expect(last_response.status).to eq(201)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
class ReeRoutes::Route
|
4
4
|
attr_accessor :summary, :request_method, :serializer, :respond_to,
|
5
|
-
:sections, :action, :route, :warden_scope, :path
|
5
|
+
:sections, :action, :route, :warden_scope, :path, :override
|
6
6
|
|
7
7
|
def valid?
|
8
8
|
!action.nil? && !summary.nil? && !warden_scope.nil?
|
data/lib/ree_lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ree_lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.79
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruslan Gatiyatov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ree
|