ree_lib 1.0.76 → 1.0.78

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: fb85650b5a10f4ec01e8323cd6caef7585821acc583a8c1727eec0a3fb4e7f5c
4
- data.tar.gz: 2839d01f406e6c997fea3a19c3aa7d641fe4df8f1bf3ef1ccd3f5044f5f5f094
3
+ metadata.gz: 2c3323a878bb1c2a2d2a629f616a31ff63bc8d64dbbc8c070aa82bc8483d920e
4
+ data.tar.gz: f9a81546f833cc528f7407f08bd1141553e38fe8124128924ca0a6cc963a4e20
5
5
  SHA512:
6
- metadata.gz: 10cf83f3f3e3429a085c15179fe25e0ac278e73d8e2c595522dc99764a787aabee1e8b14e9bd6b3522fc2969fb8f0aec173aef09d5d8dd97250e0cdf8f02e51e
7
- data.tar.gz: a3c2644c4972910c1cbb7d8ef26bbac66f7e575f281f087026f17d9efe3ac24e3cf842473dd9d4ad32319d9761820b90fba28910d97290471ddc219cbbf44300
6
+ metadata.gz: 8ecd161b8070aec4e06e9c30f7397b139d9a954476db9a73ed42d927051b07ff24b30afef38421cf999711f2f3beeb51700246e1067e6e6db5da5a8f2b3c0200
7
+ data.tar.gz: 5d80bb2e3a93dd25190312c4eafba0d5680e8d13d63c85b645a9fbc71d2bce807ebd8d4255bc99f7d0bdb0d33c98a39b9e8a0809fca92227739a9c7c5df345c4
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.1.2
1
+ 3.2.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.76)
4
+ ree_lib (1.0.78)
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)
@@ -83,14 +83,14 @@ module ReeDao
83
83
  return if entities.empty?
84
84
 
85
85
  mapper = opts[:schema_mapper]
86
- columns = columns
86
+ columns = self.columns
87
87
  raw = {}
88
88
 
89
89
  columns.delete(:id)
90
90
  columns.delete(:row)
91
91
 
92
92
  data = entities.map do |entity|
93
- hash = mapper.to_hash(entity)
93
+ hash = mapper.db_dump(entity)
94
94
  raw[entity] = hash
95
95
 
96
96
  columns.map { hash[_1] }
@@ -147,4 +147,14 @@ RSpec.describe :build_pg_connection do
147
147
  expect(product.info[:price]).to eq(1440)
148
148
  expect(product.labels).to eq(["Sale", "New"])
149
149
  }
150
+
151
+ it "insert multiple records" do
152
+ products_dao.delete_all
153
+
154
+ products = Array.new(3) { |i| ReeDaoTestPg::Product.new(title: "Product#{i}", info: { price: 1337, count: 200 }, labels: ["Sale"]) }
155
+
156
+ products_dao.import_all(products)
157
+
158
+ expect(products_dao.count).to eq 3
159
+ end
150
160
  end
@@ -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
+ route.override.call(r)
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.76"
4
+ VERSION = "1.0.78"
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.76
4
+ version: 1.0.78
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-06 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
@@ -1391,7 +1391,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1391
1391
  - !ruby/object:Gem::Version
1392
1392
  version: '0'
1393
1393
  requirements: []
1394
- rubygems_version: 3.3.7
1394
+ rubygems_version: 3.4.1
1395
1395
  signing_key:
1396
1396
  specification_version: 4
1397
1397
  summary: Ruby Standard Library Extensions