ree_lib 1.0.77 → 1.0.79

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f828e49751333dd0c669d75a7066a838f9149d4ab8923ab788e53f84c61aae4
4
- data.tar.gz: b247a24875f2c0a9caa9b5fcfbe5452e0a3c48af7d0ff2c0bd385820ce37c709
3
+ metadata.gz: 31ed7dbe4d9b99ab6768b88017dc9c1f8b59496dd2d099c180098eb1d3a3e538
4
+ data.tar.gz: 2abb0c70b8ace5e208a6cd74f9e5c1aa6580c8fa8de680a965fe43c3a7e348f9
5
5
  SHA512:
6
- metadata.gz: 0d3717364f0554a3e36097431856fb3db75099bb34fd57dc6eabfffa4e57baa2e66a81a59da5206e980dcfef1339c3cc50078fb1242973efbc9df67550ea0716
7
- data.tar.gz: ad0297ec030fd912995b4b740685c017f0a114084cbed83579d42c507a06fd0e70eb2a267c030d12b2763f649dd201cb3d9003684b2843e3105073da8ebff4cf
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.77)
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.1)
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
- r.send(route.respond_to) do
75
- r.env["warden"].authenticate!(scope: route.warden_scope)
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
- if context.opts[:ree_routes_before]
78
- r.instance_exec(@_request, route.warden_scope, &r.scope.opts[:ree_routes_before])
79
- end
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
- params = r.params
84
+ params = r.params
82
85
 
83
- if r.body
84
- body = begin
85
- JSON.parse(r.body.read)
86
- rescue => e
87
- {}
88
- end
86
+ if r.body
87
+ body = begin
88
+ JSON.parse(r.body.read)
89
+ rescue => e
90
+ {}
91
+ end
89
92
 
90
- params = params.merge(body)
91
- end
93
+ params = params.merge(body)
94
+ end
92
95
 
93
- not_blank = ReeObject::NotBlank.new
96
+ not_blank = ReeObject::NotBlank.new
94
97
 
95
- filtered_params = ReeHash::TransformValues.new.call(params) do |k, v|
96
- v.is_a?(Array) ? v.select { not_blank.call(_1) } : v
97
- end
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
- accessor = r.env["warden"].user(route.warden_scope)
100
- action_result = get_cached_action(route).call(accessor, filtered_params)
102
+ accessor = r.env["warden"].user(route.warden_scope)
103
+ action_result = get_cached_action(route).call(accessor, filtered_params)
101
104
 
102
- if route.serializer
103
- serialized_result = get_cached_serializer(route).serialize(action_result)
104
- else
105
- serialized_result = {}
106
- end
105
+ if route.serializer
106
+ serialized_result = get_cached_serializer(route).serialize(action_result)
107
+ else
108
+ serialized_result = {}
109
+ end
107
110
 
108
- case route.request_method
109
- when :post
110
- r.response.status = 201
111
- ReeJson::ToJson.new.call(serialized_result)
112
- when :put, :delete, :patch
113
- r.response.status = 204
114
- ""
115
- else
116
- r.response.status = 200
117
- ReeJson::ToJson.new.call(serialized_result)
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?
@@ -31,6 +31,12 @@ class ReeRoutes::RouteBuilder
31
31
  nil
32
32
  end
33
33
 
34
+ contract Block => nil
35
+ def override(&proc)
36
+ @route.override = proc
37
+ nil
38
+ end
39
+
34
40
  contract String => String
35
41
  def summary(str)
36
42
  @route.summary = str
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.77"
4
+ VERSION = "1.0.79"
5
5
  end
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.77
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-10-18 00:00:00.000000000 Z
11
+ date: 2023-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ree