Skip to content

Commit 5d846fe

Browse files
upgrade to ruby 3.1.4
1 parent b21b36d commit 5d846fe

File tree

4 files changed

+63
-11
lines changed

4 files changed

+63
-11
lines changed

Gemfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ gem "dalli", "~> 2.7.6"
77
gem 'lograge', '~> 0.5'
88
gem 'sentry-raven', '~> 2.9'
99
gem 'active_model_serializers', '~> 0.10.0'
10-
gem 'fast_jsonapi', '~> 1.3'
10+
gem 'jsonapi-serializer', '~> 2.2'
1111
gem 'kaminari', '~> 1.2'
1212
gem 'elasticsearch', '~> 1.1', '>= 1.1.3'
1313
gem 'elasticsearch-model', '~> 0.1.9', require: 'elasticsearch/model'
@@ -45,9 +45,9 @@ end
4545
group :test do
4646
gem 'capybara'
4747
gem 'webmock', '~> 3.1'
48-
gem 'vcr', '~> 3.0.3'
48+
gem 'vcr', '~> 6.1'
4949
gem 'codeclimate-test-reporter', '~> 1.0.0'
5050
gem 'simplecov'
5151
gem 'shoulda-matchers', '~> 3.1'
5252
gem 'elasticsearch-extensions'
53-
end
53+
end

Gemfile.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ GEM
152152
faraday
153153
faraday_middleware (0.14.0)
154154
faraday (>= 0.7.4, < 1.0)
155-
fast_jsonapi (1.5)
156-
activesupport (>= 4.2)
157155
ffi (1.15.5)
158156
git (1.12.0)
159157
addressable (~> 2.8)
@@ -174,6 +172,8 @@ GEM
174172
ice_nine (0.11.2)
175173
json (2.6.2)
176174
jsonapi-renderer (0.2.2)
175+
jsonapi-serializer (2.2.0)
176+
activesupport (>= 4.2)
177177
kaminari (1.2.2)
178178
activesupport (>= 4.1.0)
179179
kaminari-actionview (= 1.2.2)
@@ -348,7 +348,7 @@ GEM
348348
zeitwerk (2.6.0)
349349

350350
PLATFORMS
351-
ruby
351+
aarch64-linux
352352

353353
DEPENDENCIES
354354
active_model_serializers (~> 0.10.0)
@@ -367,13 +367,13 @@ DEPENDENCIES
367367
elasticsearch-model (~> 0.1.9)
368368
elasticsearch-persistence (~> 0.1.9)
369369
elasticsearch-rails (~> 0.1.9)
370-
fast_jsonapi (~> 1.3)
371370
git (~> 1.5)
372371
google-protobuf (~> 3.0)
373372
graphql (~> 1.9, >= 1.9.4)
374373
graphql-batch (~> 0.4.0)
375374
graphql-cache (~> 0.6.0)!
376375
graphql-errors (~> 0.3.0)
376+
jsonapi-serializer (~> 2.2)
377377
kaminari (~> 1.2)
378378
listen (>= 3.0.5, < 3.2)
379379
lograge (~> 0.5)

app/serializers/re3data_serializer.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class Re3dataSerializer
2-
include FastJsonapi::ObjectSerializer
2+
include JSONAPI::Serializer
33
set_key_transform :camel_lower
44
set_type :re3data
55

6-
attributes :re3data_id, :repositoryName, :repositoryUrl, :repositoryContacts, :description, :repositoryLanguages, :certificates, :types,
7-
:additionalNames, :subjects, :contentTypes, :providerTypes,
6+
attributes :re3data_id, :repositoryName, :repositoryUrl, :repositoryContacts, :description, :repositoryLanguages, :certificates, :types,
7+
:additionalNames, :subjects, :contentTypes, :providerTypes,
88
:keywords, :institutions, :dataAccesses, :dataUploads, :dataUploadLicenses, :pidSystems,
99
:apis, :pidSystems, :software, :startDate, :endDate, :created, :updated
1010

@@ -23,4 +23,4 @@ class Re3dataSerializer
2323
attribute :updated do |object|
2424
object.updated.strftime("%FT%TZ")
2525
end
26-
end
26+
end
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: true
2+
3+
# Monkey patch for jsonapi-serializer gem
4+
5+
module FastJsonapi
6+
module SerializationCore
7+
class_methods do
8+
def get_included_records(record, includes_list, known_included_objects, fieldsets, params = {})
9+
return unless includes_list.present?
10+
return [] unless relationships_to_serialize
11+
12+
includes_list = parse_includes_list(includes_list)
13+
14+
includes_list.each_with_object([]) do |include_item, included_records|
15+
relationship_item = relationships_to_serialize[include_item.first]
16+
17+
next unless relationship_item&.include_relationship?(record, params)
18+
19+
associated_objects = relationship_item.fetch_associated_object(record, params)
20+
21+
if associated_objects.is_a?(Elasticsearch::Model::HashWrapper)
22+
associated_objects = OpenStruct.new(associated_objects)
23+
end
24+
25+
included_objects = Array(associated_objects)
26+
27+
next if included_objects.empty?
28+
29+
static_serializer = relationship_item.static_serializer
30+
static_record_type = relationship_item.static_record_type
31+
32+
included_objects.each do |inc_obj|
33+
serializer = static_serializer || relationship_item.serializer_for(inc_obj, params)
34+
record_type = static_record_type || serializer.record_type
35+
36+
if include_item.last.any?
37+
serializer_records = serializer.get_included_records(inc_obj, include_item.last, known_included_objects, fieldsets, params)
38+
included_records.concat(serializer_records) unless serializer_records.empty?
39+
end
40+
41+
code = "#{record_type}_#{serializer.id_from_record(inc_obj, params)}"
42+
next if known_included_objects.include?(code)
43+
44+
known_included_objects << code
45+
46+
included_records << serializer.record_hash(inc_obj, fieldsets[record_type], includes_list, params)
47+
end
48+
end
49+
end
50+
end
51+
end
52+
end

0 commit comments

Comments
 (0)