Skip to content

Commit

Permalink
upgrade to ruby 3.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
wendelfabianchinsamy committed May 7, 2024
1 parent 3d56932 commit 3cdfecb
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
ELASTIC_PASSWORD: ${{ secrets.RE3DATA_ES_PASSWORD }}
steps:
- uses: actions/checkout@v2
- name: Set up Ruby 2.7
- name: Set up Ruby 3.1.4
uses: actions/setup-ruby@v1
with:
ruby-version: '2.7.6'
ruby-version: '3.1.4'
- uses: actions/cache@v2
with:
path: vendor/bundle
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- 11211/tcp
steps:
- uses: actions/checkout@v2
- name: Set up Ruby 2.7
- name: Set up Ruby 3.1.4
uses: actions/setup-ruby@v1
with:
ruby-version: '2.7.6'
ruby-version: '3.1.4'
- uses: actions/cache@v2
with:
path: vendor/bundle
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
ELASTIC_PASSWORD: ${{ secrets.RE3DATA_ES_PASSWORD }}
steps:
- uses: actions/checkout@v2
- name: Set up Ruby 2.7
- name: Set up Ruby 3.1.4
uses: actions/setup-ruby@v1
with:
ruby-version: '2.7.6'
ruby-version: '3.1.4'
- uses: actions/cache@v2
with:
path: vendor/bundle
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ inherit_from: .rubocop_todo.yml
# from https://github.com/rails/rails/blob/master/.rubocop.yml

AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 3.1
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM phusion/passenger-full:2.3.0
FROM phusion/passenger-full:2.5.1
LABEL maintainer="tech@datacite.org"

# Set correct environment variables.
Expand All @@ -10,8 +10,8 @@ RUN usermod -a -G docker_env app
# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]

# Install Ruby 2.7.6
RUN bash -lc 'rvm --default use ruby-2.7.6'
# Install Ruby 3.1.4
RUN bash -lc 'rvm --default use ruby-3.1.4'

# Update installed APT packages
RUN apt-get update -y -o Dpkg::Options::="--force-confold" && \
Expand Down Expand Up @@ -41,7 +41,7 @@ RUN mkdir -p /home/app/webapp/tmp/pids && \
# Install Ruby gems
WORKDIR /home/app/webapp
RUN gem update --system && \
gem install bundler:2.3.20 && \
gem install bundler:2.5.6 && \
/sbin/setuser app bundle config set --local path 'vendor/bundle' && \
/sbin/setuser app bundle install

Expand Down
12 changes: 6 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gem "dalli", "~> 2.7.6"
gem 'lograge', '~> 0.5'
gem 'sentry-raven', '~> 2.9'
gem 'active_model_serializers', '~> 0.10.0'
gem 'fast_jsonapi', '~> 1.3'
gem 'jsonapi-serializer', '~> 2.2'
gem 'kaminari', '~> 1.2'
gem 'elasticsearch', '~> 1.1', '>= 1.1.3'
gem 'elasticsearch-model', '~> 0.1.9', require: 'elasticsearch/model'
Expand Down Expand Up @@ -35,19 +35,19 @@ group :development, :test do
end

group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'listen', '~> 3.9'
gem 'spring', '~> 4.1', '>= 4.1.3'
gem 'spring-commands-rspec'
gem 'spring-watcher-listen', '~> 2.1'
# gem 'httplog', '~> 1.0'
end

group :test do
gem 'capybara'
gem 'webmock', '~> 3.1'
gem 'vcr', '~> 3.0.3'
gem 'vcr', '~> 6.1'
gem 'codeclimate-test-reporter', '~> 1.0.0'
gem 'simplecov'
gem 'shoulda-matchers', '~> 3.1'
gem 'elasticsearch-extensions'
end
end
36 changes: 17 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ GEM
faraday
faraday_middleware (0.14.0)
faraday (>= 0.7.4, < 1.0)
fast_jsonapi (1.5)
activesupport (>= 4.2)
ffi (1.15.5)
ffi (1.16.3)
git (1.12.0)
addressable (~> 2.8)
rchardet (~> 1.8)
Expand All @@ -174,6 +172,8 @@ GEM
ice_nine (0.11.2)
json (2.6.2)
jsonapi-renderer (0.2.2)
jsonapi-serializer (2.2.0)
activesupport (>= 4.2)
kaminari (1.2.2)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2)
Expand All @@ -186,10 +186,9 @@ GEM
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
lograge (0.12.0)
actionpack (>= 4)
activesupport (>= 4)
Expand Down Expand Up @@ -265,7 +264,7 @@ GEM
thor (~> 1.0)
rainbow (3.1.1)
rake (13.0.6)
rb-fsevent (0.11.1)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rchardet (1.8.0)
Expand Down Expand Up @@ -305,7 +304,6 @@ GEM
rubocop-performance (1.3.0)
rubocop (>= 0.68.0)
ruby-progressbar (1.11.0)
ruby_dep (1.5.0)
sentry-raven (2.13.0)
faraday (>= 0.7.6, < 1.0)
shoulda-matchers (3.1.3)
Expand All @@ -315,12 +313,12 @@ GEM
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
spring (2.1.1)
spring (4.2.1)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
spring-watcher-listen (2.0.1)
spring-watcher-listen (2.1.0)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
spring (>= 4)
sprockets (4.1.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand All @@ -333,7 +331,7 @@ GEM
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unicode-display_width (2.2.0)
vcr (3.0.3)
vcr (6.2.0)
virtus (2.0.0)
axiom-types (~> 0.1)
coercible (~> 1.0)
Expand Down Expand Up @@ -369,15 +367,15 @@ DEPENDENCIES
elasticsearch-model (~> 0.1.9)
elasticsearch-persistence (~> 0.1.9)
elasticsearch-rails (~> 0.1.9)
fast_jsonapi (~> 1.3)
git (~> 1.5)
google-protobuf (~> 3.0)
graphql (~> 1.9, >= 1.9.4)
graphql-batch (~> 0.4.0)
graphql-cache (~> 0.6.0)!
graphql-errors (~> 0.3.0)
jsonapi-serializer (~> 2.2)
kaminari (~> 1.2)
listen (>= 3.0.5, < 3.2)
listen (~> 3.9)
lograge (~> 0.5)
maremma (>= 4.1)
rack-cors (~> 1.0)
Expand All @@ -388,11 +386,11 @@ DEPENDENCIES
sentry-raven (~> 2.9)
shoulda-matchers (~> 3.1)
simplecov
spring
spring (~> 4.1, >= 4.1.3)
spring-commands-rspec
spring-watcher-listen (~> 2.0.0)
vcr (~> 3.0.3)
spring-watcher-listen (~> 2.1)
vcr (~> 6.1)
webmock (~> 3.1)

BUNDLED WITH
2.3.20
2.5.6
14 changes: 7 additions & 7 deletions app/controllers/re3data_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def index
end

page = params[:page] || {}
if page[:size].present?
if page[:size].present?
page[:size] = [page[:size].to_i, 1000].min
max_number = page[:size] > 0 ? 10000/page[:size] : 1
else
Expand All @@ -26,11 +26,11 @@ def index
elsif params[:ids].present?
response = Repository.find_by_id(params[:ids], page: page, sort: sort)
else
response = Repository.query(params[:query],
page: page,
sort: sort,
response = Repository.query(params[:query],
page: page,
sort: sort,
subject: params[:subject],
open: params[:open],
open: params[:open],
certified: params[:certified],
pid: params[:pid],
software: params[:software],
Expand Down Expand Up @@ -59,7 +59,7 @@ def index
}.compact
options[:is_collection] = true

render json: Re3dataSerializer.new(@repositories, options).serialized_json, status: :ok
render json: Re3dataSerializer.new(@repositories, options).serializable_hash.to_json, status: :ok
rescue Elasticsearch::Transport::Transport::Errors::LengthRequired
render json: []
end
Expand All @@ -68,7 +68,7 @@ def show
options = {}
options[:is_collection] = false

render json: Re3dataSerializer.new(@repository, options).serialized_json, status: :ok
render json: Re3dataSerializer.new(@repository, options).serializable_hash.to_json, status: :ok
end

def suggest
Expand Down
8 changes: 4 additions & 4 deletions app/serializers/re3data_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class Re3dataSerializer
include FastJsonapi::ObjectSerializer
include JSONAPI::Serializer
set_key_transform :camel_lower
set_type :re3data

attributes :re3data_id, :repositoryName, :repositoryUrl, :repositoryContacts, :description, :repositoryLanguages, :certificates, :types,
:additionalNames, :subjects, :contentTypes, :providerTypes,
attributes :re3data_id, :repositoryName, :repositoryUrl, :repositoryContacts, :description, :repositoryLanguages, :certificates, :types,
:additionalNames, :subjects, :contentTypes, :providerTypes,
:keywords, :institutions, :dataAccesses, :dataUploads, :dataUploadLicenses, :pidSystems,
:apis, :pidSystems, :software, :startDate, :endDate, :created, :updated

Expand All @@ -23,4 +23,4 @@ class Re3dataSerializer
attribute :updated do |object|
object.updated.strftime("%FT%TZ")
end
end
end
52 changes: 52 additions & 0 deletions config/initializers/serialization_core.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

# Monkey patch for jsonapi-serializer gem

module FastJsonapi
module SerializationCore
class_methods do
def get_included_records(record, includes_list, known_included_objects, fieldsets, params = {})
return unless includes_list.present?
return [] unless relationships_to_serialize

includes_list = parse_includes_list(includes_list)

includes_list.each_with_object([]) do |include_item, included_records|
relationship_item = relationships_to_serialize[include_item.first]

next unless relationship_item&.include_relationship?(record, params)

associated_objects = relationship_item.fetch_associated_object(record, params)

if associated_objects.is_a?(Elasticsearch::Model::HashWrapper)
associated_objects = OpenStruct.new(associated_objects)
end

included_objects = Array(associated_objects)

next if included_objects.empty?

static_serializer = relationship_item.static_serializer
static_record_type = relationship_item.static_record_type

included_objects.each do |inc_obj|
serializer = static_serializer || relationship_item.serializer_for(inc_obj, params)
record_type = static_record_type || serializer.record_type

if include_item.last.any?
serializer_records = serializer.get_included_records(inc_obj, include_item.last, known_included_objects, fieldsets, params)
included_records.concat(serializer_records) unless serializer_records.empty?
end

code = "#{record_type}_#{serializer.id_from_record(inc_obj, params)}"
next if known_included_objects.include?(code)

known_included_objects << code

included_records << serializer.record_hash(inc_obj, fieldsets[record_type], includes_list, params)
end
end
end
end
end
end
5 changes: 5 additions & 0 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: "2.1"

services:
web:
build: .

0 comments on commit 3cdfecb

Please sign in to comment.