Skip to content

Commit e158b9b

Browse files
committed
chore: add new utils
1 parent ece5f0e commit e158b9b

File tree

3 files changed

+327
-0
lines changed

3 files changed

+327
-0
lines changed

Gemfile.lock

Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
PATH
2+
remote: .
3+
specs:
4+
forest_liana (9.15.8)
5+
bcrypt
6+
deepsort
7+
forestadmin-jsonapi-serializers (>= 0.14.0)
8+
groupdate (>= 5.0.0)
9+
httparty
10+
ipaddress
11+
json
12+
json-jwt (>= 1.16.0)
13+
jwt
14+
openid_connect (= 1.4.2)
15+
rack-cors
16+
rails (>= 6.1.7.9)
17+
useragent
18+
19+
GEM
20+
remote: https://rubygems.org/
21+
specs:
22+
actioncable (6.1.7.9)
23+
actionpack (= 6.1.7.9)
24+
activesupport (= 6.1.7.9)
25+
nio4r (~> 2.0)
26+
websocket-driver (>= 0.6.1)
27+
actionmailbox (6.1.7.9)
28+
actionpack (= 6.1.7.9)
29+
activejob (= 6.1.7.9)
30+
activerecord (= 6.1.7.9)
31+
activestorage (= 6.1.7.9)
32+
activesupport (= 6.1.7.9)
33+
mail (>= 2.7.1)
34+
actionmailer (6.1.7.9)
35+
actionpack (= 6.1.7.9)
36+
actionview (= 6.1.7.9)
37+
activejob (= 6.1.7.9)
38+
activesupport (= 6.1.7.9)
39+
mail (~> 2.5, >= 2.5.4)
40+
rails-dom-testing (~> 2.0)
41+
actionpack (6.1.7.9)
42+
actionview (= 6.1.7.9)
43+
activesupport (= 6.1.7.9)
44+
rack (~> 2.0, >= 2.0.9)
45+
rack-test (>= 0.6.3)
46+
rails-dom-testing (~> 2.0)
47+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
48+
actiontext (6.1.7.9)
49+
actionpack (= 6.1.7.9)
50+
activerecord (= 6.1.7.9)
51+
activestorage (= 6.1.7.9)
52+
activesupport (= 6.1.7.9)
53+
nokogiri (>= 1.8.5)
54+
actionview (6.1.7.9)
55+
activesupport (= 6.1.7.9)
56+
builder (~> 3.1)
57+
erubi (~> 1.4)
58+
rails-dom-testing (~> 2.0)
59+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
60+
activejob (6.1.7.9)
61+
activesupport (= 6.1.7.9)
62+
globalid (>= 0.3.6)
63+
activemodel (6.1.7.9)
64+
activesupport (= 6.1.7.9)
65+
activerecord (6.1.7.9)
66+
activemodel (= 6.1.7.9)
67+
activesupport (= 6.1.7.9)
68+
activestorage (6.1.7.9)
69+
actionpack (= 6.1.7.9)
70+
activejob (= 6.1.7.9)
71+
activerecord (= 6.1.7.9)
72+
activesupport (= 6.1.7.9)
73+
marcel (~> 1.0)
74+
mini_mime (>= 1.1.0)
75+
activesupport (6.1.7.9)
76+
concurrent-ruby (~> 1.0, >= 1.0.2)
77+
i18n (>= 1.6, < 2)
78+
minitest (>= 5.1)
79+
tzinfo (~> 2.0)
80+
zeitwerk (~> 2.3)
81+
aes_key_wrap (1.1.0)
82+
attr_required (1.0.2)
83+
base64 (0.3.0)
84+
bcrypt (3.1.20)
85+
bigdecimal (3.2.3)
86+
bindata (2.5.1)
87+
builder (3.3.0)
88+
byebug (12.0.0)
89+
concurrent-ruby (1.3.4)
90+
crass (1.0.6)
91+
date (3.4.1)
92+
deepsort (0.5.0)
93+
diff-lcs (1.6.2)
94+
docile (1.4.1)
95+
erubi (1.13.1)
96+
faraday (2.14.0)
97+
faraday-net_http (>= 2.0, < 3.5)
98+
json
99+
logger
100+
faraday-follow_redirects (0.4.0)
101+
faraday (>= 1, < 3)
102+
faraday-net_http (3.4.1)
103+
net-http (>= 0.5.0)
104+
forestadmin-jsonapi-serializers (2.0.0.pre.beta.2)
105+
activesupport
106+
globalid (1.3.0)
107+
activesupport (>= 6.1)
108+
groupdate (5.2.2)
109+
activesupport (>= 5)
110+
httparty (0.21.0)
111+
mini_mime (>= 1.0.0)
112+
multi_xml (>= 0.5.2)
113+
httpclient (2.9.0)
114+
mutex_m
115+
i18n (1.14.7)
116+
concurrent-ruby (~> 1.0)
117+
ipaddress (0.8.3)
118+
json (2.15.0)
119+
json-jwt (1.17.0)
120+
activesupport (>= 4.2)
121+
aes_key_wrap
122+
base64
123+
bindata
124+
faraday (~> 2.0)
125+
faraday-follow_redirects
126+
jwt (3.1.2)
127+
base64
128+
logger (1.7.0)
129+
loofah (2.24.1)
130+
crass (~> 1.0.2)
131+
nokogiri (>= 1.12.0)
132+
mail (2.8.1)
133+
mini_mime (>= 0.1.1)
134+
net-imap
135+
net-pop
136+
net-smtp
137+
marcel (1.1.0)
138+
method_source (1.1.0)
139+
mini_mime (1.1.5)
140+
minitest (5.25.5)
141+
multi_xml (0.7.2)
142+
bigdecimal (~> 3.1)
143+
mutex_m (0.3.0)
144+
net-http (0.6.0)
145+
uri
146+
net-imap (0.5.11)
147+
date
148+
net-protocol
149+
net-pop (0.1.2)
150+
net-protocol
151+
net-protocol (0.2.2)
152+
timeout
153+
net-smtp (0.5.1)
154+
net-protocol
155+
nio4r (2.7.4)
156+
nokogiri (1.18.10-arm64-darwin)
157+
racc (~> 1.4)
158+
openid_connect (1.4.2)
159+
activemodel
160+
attr_required (>= 1.0.0)
161+
json-jwt (>= 1.15.0)
162+
net-smtp
163+
rack-oauth2 (~> 1.21)
164+
swd (~> 1.3)
165+
tzinfo
166+
validate_email
167+
validate_url
168+
webfinger (~> 1.2)
169+
public_suffix (6.0.2)
170+
racc (1.8.1)
171+
rack (2.2.17)
172+
rack-cors (2.0.2)
173+
rack (>= 2.0.0)
174+
rack-oauth2 (1.21.3)
175+
activesupport
176+
attr_required
177+
httpclient
178+
json-jwt (>= 1.11.0)
179+
rack (>= 2.1.0)
180+
rack-test (2.2.0)
181+
rack (>= 1.3)
182+
rails (6.1.7.9)
183+
actioncable (= 6.1.7.9)
184+
actionmailbox (= 6.1.7.9)
185+
actionmailer (= 6.1.7.9)
186+
actionpack (= 6.1.7.9)
187+
actiontext (= 6.1.7.9)
188+
actionview (= 6.1.7.9)
189+
activejob (= 6.1.7.9)
190+
activemodel (= 6.1.7.9)
191+
activerecord (= 6.1.7.9)
192+
activestorage (= 6.1.7.9)
193+
activesupport (= 6.1.7.9)
194+
bundler (>= 1.15.0)
195+
railties (= 6.1.7.9)
196+
sprockets-rails (>= 2.0.0)
197+
rails-dom-testing (2.3.0)
198+
activesupport (>= 5.0.0)
199+
minitest
200+
nokogiri (>= 1.6)
201+
rails-html-sanitizer (1.6.2)
202+
loofah (~> 2.21)
203+
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
204+
railties (6.1.7.9)
205+
actionpack (= 6.1.7.9)
206+
activesupport (= 6.1.7.9)
207+
method_source
208+
rake (>= 12.2)
209+
thor (~> 1.0)
210+
rake (13.3.0)
211+
rspec-core (3.13.5)
212+
rspec-support (~> 3.13.0)
213+
rspec-expectations (3.13.5)
214+
diff-lcs (>= 1.2.0, < 2.0)
215+
rspec-support (~> 3.13.0)
216+
rspec-mocks (3.13.5)
217+
diff-lcs (>= 1.2.0, < 2.0)
218+
rspec-support (~> 3.13.0)
219+
rspec-rails (6.1.5)
220+
actionpack (>= 6.1)
221+
activesupport (>= 6.1)
222+
railties (>= 6.1)
223+
rspec-core (~> 3.13)
224+
rspec-expectations (~> 3.13)
225+
rspec-mocks (~> 3.13)
226+
rspec-support (~> 3.13)
227+
rspec-support (3.13.4)
228+
simplecov (0.22.0)
229+
docile (~> 1.1)
230+
simplecov-html (~> 0.11)
231+
simplecov_json_formatter (~> 0.1)
232+
simplecov-html (0.13.2)
233+
simplecov_json_formatter (0.1.4)
234+
sprockets (4.2.2)
235+
concurrent-ruby (~> 1.0)
236+
logger
237+
rack (>= 2.2.4, < 4)
238+
sprockets-rails (3.5.2)
239+
actionpack (>= 6.1)
240+
activesupport (>= 6.1)
241+
sprockets (>= 3.0.0)
242+
sqlite3 (1.7.3-arm64-darwin)
243+
swd (1.3.0)
244+
activesupport (>= 3)
245+
attr_required (>= 0.0.5)
246+
httpclient (>= 2.4)
247+
thor (1.4.0)
248+
timecop (0.9.10)
249+
timeout (0.4.3)
250+
tzinfo (2.0.6)
251+
concurrent-ruby (~> 1.0)
252+
uri (1.0.3)
253+
useragent (0.16.11)
254+
validate_email (0.1.6)
255+
activemodel (>= 3.0)
256+
mail (>= 2.2.5)
257+
validate_url (1.0.15)
258+
activemodel (>= 3.0.0)
259+
public_suffix
260+
webfinger (1.2.0)
261+
activesupport
262+
httpclient (>= 2.4)
263+
websocket-driver (0.8.0)
264+
base64
265+
websocket-extensions (>= 0.1.0)
266+
websocket-extensions (0.1.5)
267+
zeitwerk (2.7.3)
268+
269+
PLATFORMS
270+
arm64-darwin-23
271+
272+
DEPENDENCIES
273+
bcrypt
274+
byebug
275+
concurrent-ruby (= 1.3.4)
276+
deepsort
277+
forest_liana!
278+
forestadmin-jsonapi-serializers
279+
groupdate (= 5.2.2)
280+
httparty (= 0.21.0)
281+
ipaddress (= 0.8.3)
282+
json
283+
json-jwt (>= 1.16)
284+
jwt
285+
openid_connect (= 1.4.2)
286+
rack-cors
287+
rails (= 6.1.7.9)
288+
rake
289+
rspec-rails
290+
simplecov (~> 0.22)
291+
simplecov_json_formatter (~> 0.1.4)
292+
sqlite3 (~> 1.4)
293+
timecop
294+
useragent
295+
296+
BUNDLED WITH
297+
2.7.1

app/services/forest_liana/resources_getter.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ def compute_select_fields
319319
end
320320

321321
def get_one_association(name)
322+
#return nil if name.nil?
323+
324+
#name_sym = name.is_a?(Symbol) ? name : name.to_sym
322325
ForestLiana::QueryHelper.get_one_associations(@resource)
323326
.select { |association| association.name == name.to_sym }
324327
.first
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module ForestLiana
2+
module Utils
3+
module CompositePrimaryKeyHelper
4+
def self.find_record(scoped_records, resource, id)
5+
primary_key = resource.primary_key
6+
7+
if primary_key.is_a?(Array)
8+
id_values = parse_composite_id(id)
9+
conditions = primary_key.zip(id_values).to_h
10+
scoped_records.find_by(conditions)
11+
else
12+
scoped_records.find(id)
13+
end
14+
end
15+
16+
def self.parse_composite_id(id)
17+
return id if id.is_a?(Array)
18+
19+
if id.to_s.start_with?('[') && id.to_s.end_with?(']')
20+
JSON.parse(id.to_s)
21+
else
22+
raise ForestLiana::Errors::HTTP422Error.new("Composite primary key ID must be in format [value1,value2], received: #{id}")
23+
end
24+
end
25+
end
26+
end
27+
end

0 commit comments

Comments
 (0)