Skip to content

Commit

Permalink
Merge pull request #1454 from sanger/dpl951_ruby_3
Browse files Browse the repository at this point in the history
DPL-951: Upgrade to Ruby 3
  • Loading branch information
KatyTaylor authored Nov 16, 2023
2 parents 979a6ed + 3f42218 commit 1ee1b44
Show file tree
Hide file tree
Showing 29 changed files with 98 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.8
3.0.6
16 changes: 7 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ GEM
ast (2.4.2)
autoprefixer-rails (10.4.7.0)
execjs (~> 2)
base64 (0.1.1)
bindex (0.8.1)
bootsnap (1.14.0)
msgpack (~> 1.2)
Expand Down Expand Up @@ -248,8 +247,8 @@ GEM
public_suffix (5.0.0)
puma (6.3.1)
nio4r (~> 2.0)
racc (1.7.1)
rack (2.2.8)
racc (1.7.3)
rack (2.2.4)
rack-mini-profiler (3.0.0)
rack (>= 1.2.0)
rack-proxy (0.7.4)
Expand Down Expand Up @@ -317,8 +316,7 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.0)
rubocop (1.57.1)
base64 (~> 0.1.1)
rubocop (1.57.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand All @@ -329,7 +327,7 @@ GEM
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-performance (1.15.1)
rubocop (>= 1.7.0, < 2.0)
Expand Down Expand Up @@ -378,8 +376,8 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
state_machines (0.5.0)
thor (1.3.0)
state_machines (0.6.0)
thor (1.2.1)
tilt (2.0.11)
timeout (0.4.0)
tzinfo (2.0.6)
Expand Down Expand Up @@ -460,4 +458,4 @@ DEPENDENCIES
yard

BUNDLED WITH
2.1.4
2.2.33
2 changes: 1 addition & 1 deletion app/controllers/labware_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# show => Looks up the presenter for the giver purpose and renders the appropriate show page
# update => Used to update the state of a plate/tube
class LabwareController < ApplicationController
UUID = /\A[\da-f]{8}(-[\da-f]{4}){3}-[\da-f]{12}\z/.freeze
UUID = /\A[\da-f]{8}(-[\da-f]{4}){3}-[\da-f]{12}\z/

before_action :locate_labware, only: :show
before_action :find_printers, only: [:show]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/plates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def wells_to_fail
private

def locate_labware_identified_by_id
Sequencescape::Api::V2.plate_for_presenter(search_param) ||
Sequencescape::Api::V2.plate_for_presenter(**search_param) ||
raise(ActionController::RoutingError, "Unknown resource #{search_param}")
end
end
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module DeploymentInfo # rubocop:todo Style/Documentation
rescue LoadError
module Deployed
VERSION_ID = 'LOCAL'
VERSION_STRING = "Limber LOCAL [#{ENV.fetch('RACK_ENV', nil)}]"
VERSION_STRING = "Limber LOCAL [#{ENV.fetch('RACK_ENV', nil)}]".freeze
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/page_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def flash_messages
end

def grouping(_data_role, options = {}, &block)
tag.div(options, &block)
tag.div(**options, &block)
end
private :grouping

Expand Down Expand Up @@ -47,7 +47,7 @@ def jumbotron(jumbotron_id = nil, options = {}, &block)
options[:class] ||= +''
options[:class] << ' jumbotron'
options[:id] = jumbotron_id
tag.div(options, &block)
tag.div(**options, &block)
end

# eg. state_badge('pending')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
# The state presents the library pass page for tagged assets
module Presenters::Statemachine
module AllowsLibraryPassing # rubocop:todo Style/Documentation
def control_library_passing
yield if libraries_passable? && !suggest_library_passing?
end
extend ActiveSupport::Concern
included do
def control_library_passing
yield if libraries_passable? && !suggest_library_passing?
end

def control_suggested_library_passing
yield if libraries_passable? && suggest_library_passing?
def control_suggested_library_passing
yield if libraries_passable? && suggest_library_passing?
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
# The state never presents the library pass button
module Presenters::Statemachine
module DoesNotAllowLibraryPassing # rubocop:todo Style/Documentation
def control_library_passing
false
end
extend ActiveSupport::Concern
included do
def control_library_passing
false
end

def control_suggested_library_passing
false
def control_suggested_library_passing
false
end
end
end
end
1 change: 1 addition & 0 deletions app/models/concerns/presenters/statemachine/standard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module Presenters::Statemachine
module Standard # rubocop:todo Style/Documentation
extend ActiveSupport::Concern

included do
include Shared

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
module Presenters::Statemachine
# Supports creation of child assets in this state
module StateAllowsChildCreation
def control_additional_creation
yield
extend ActiveSupport::Concern
included do
def control_additional_creation
yield
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
module Presenters::Statemachine
# Supports creation of a single child asset in this state
module StateAllowsSingleChildCreation
def control_additional_creation
yield if child_assets.blank?
extend ActiveSupport::Concern
included do
def control_additional_creation
yield if child_assets.blank?
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
module Presenters::Statemachine
# Prevent creation of child assets while in this state
module StateDoesNotAllowChildCreation
def control_additional_creation(&block)
# Does nothing because you can't!
extend ActiveSupport::Concern
included do
def control_additional_creation(&block)
# Does nothing because you can't!
end
end
end
end
2 changes: 1 addition & 1 deletion app/models/labware_creators/multi_stamp_tubes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def parent_uuids
end

def parent_tubes
Sequencescape::Api::V2::Tube.find_all({ uuid: parent_uuids }, includes: 'receptacle,aliquots,aliquots.study')
Sequencescape::Api::V2::Tube.find_all(uuid: parent_uuids, includes: 'receptacle,aliquots,aliquots.study')
end

def transfer_material_from_parent!(child_plate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def tube_must_be_spiked_buffer

# Only call this method if the spikedbuffer_tube_barcode is present
def scanned_tube
@scanned_tube ||= Sequencescape::Api::V2::Tube.find_by(barcode: spikedbuffer_tube_barcode)
search_params = { barcode: spikedbuffer_tube_barcode }
@scanned_tube ||= Sequencescape::Api::V2::Tube.find_by(search_params)
end
end
end
6 changes: 2 additions & 4 deletions app/models/labware_creators/pooled_tubes_from_whole_tubes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ def available_tubes
@search_options = OngoingTube.new(purpose_names: [parent.purpose.name], include_used: false)
@search_results =
Sequencescape::Api::V2::Tube.find_all(
@search_options.v2_search_parameters,
includes: 'purpose',
paginate: @search_options.v2_pagination
**@search_options.v2_search_parameters.merge({ includes: 'purpose', paginate: @search_options.v2_pagination })
)
end

def parents
@parents ||= Sequencescape::Api::V2::Tube.find_all({ barcode: barcodes }, includes: [])
@parents ||= Sequencescape::Api::V2::Tube.find_all(barcode: barcodes, includes: [])
end

def parents_suitable
Expand Down
4 changes: 2 additions & 2 deletions app/sequencescape/sequencescape/api/v2/plate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class Sequencescape::Api::V2::Plate < Sequencescape::Api::V2::Base
property :updated_at, type: :time

def self.find_by(options)
Sequencescape::Api::V2.plate_for_presenter(options)
Sequencescape::Api::V2.plate_for_presenter(**options)
end

def self.find_all(options, includes: DEFAULT_INCLUDES)
Sequencescape::Api::V2::Plate.includes(*includes).where(options).all
Sequencescape::Api::V2::Plate.includes(*includes).where(**options).all
end

#
Expand Down
2 changes: 1 addition & 1 deletion app/sequencescape/sequencescape/api/v2/sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Sequencescape::Api::V2::Sample < Sequencescape::Api::V2::Base
DEFAULT_INCLUDES = [].freeze

def self.find_by(options, includes: DEFAULT_INCLUDES)
Sequencescape::Api::V2::Sample.includes(*includes).find(options).first
Sequencescape::Api::V2::Sample.includes(*includes).find(**options).first
end

def species
Expand Down
2 changes: 1 addition & 1 deletion app/sequencescape/sequencescape/api/v2/sample_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class Sequencescape::Api::V2::SampleMetadata < Sequencescape::Api::V2::Base
DEFAULT_INCLUDES = [].freeze

def self.find_by(options, includes: DEFAULT_INCLUDES)
Sequencescape::Api::V2::SampleMetadata.includes(*includes).find(options).first
Sequencescape::Api::V2::SampleMetadata.includes(*includes).find(**options).first
end
end
13 changes: 9 additions & 4 deletions app/sequencescape/sequencescape/api/v2/tube.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ class Sequencescape::Api::V2::Tube < Sequencescape::Api::V2::Base
property :created_at, type: :time
property :updated_at, type: :time

def self.find_by(options, includes: DEFAULT_INCLUDES)
Sequencescape::Api::V2::Tube.includes(*includes).find(options).first
def self.find_by(params)
options = params.dup
includes = options.delete(:includes) || DEFAULT_INCLUDES
Sequencescape::Api::V2::Tube.includes(*includes).find(**options).first
end

def self.find_all(options, includes: DEFAULT_INCLUDES, paginate: {})
Sequencescape::Api::V2::Tube.includes(*includes).where(options).paginate(paginate).all
def self.find_all(params)
options = params.dup
includes = options.delete(:includes) || DEFAULT_INCLUDES
paginate = options.delete(:paginate) || {}
Sequencescape::Api::V2::Tube.includes(*includes).where(**options).paginate(paginate).all
end

# Dummied out for the moment. But no real reason not to add it to the API.
Expand Down
5 changes: 4 additions & 1 deletion config/initializers/cardinal_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
cardinal_pooling_csv =
CSV.read(
'config/cardinal_pooling.csv',
{ encoding: 'UTF-8', headers: true, header_converters: :symbol, converters: :all }
encoding: 'UTF-8',
headers: true,
header_converters: :symbol,
converters: :all
)

Rails.application.config.cardinal_pooling_config = {}
Expand Down
3 changes: 2 additions & 1 deletion config/initializers/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def instance # rubocop:todo Metrics/AbcSize
# but the creates an immutable setting object that messes with tests.
# Immutability is good here though, so we should probably fix that.
# Added flag onto safe_load to allow read of anchors (aliases) in yml files.
@instance = Hashie::Mash.new(YAML.safe_load(File.read(configuration_filename), [Symbol], [], true))
config_file_descriptor = File.open(configuration_filename, 'r:bom|utf-8')
@instance = Hashie::Mash.new(YAML.safe_load(config_file_descriptor, permitted_classes: [Symbol], aliases: true))

# To view a list of pipeline groups and respective pipelines:
# e.g. Settings.pipelines.group_by(&:pipeline_group).transform_values { |pipelines| pipelines.map(&:name) }
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/version_strings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Deployed
ENVIRONMENT = 'Dev'

VERSION_ID = 'LOCAL'
VERSION_STRING = "Limber LOCAL [#{Deployed::ENVIRONMENT}]"
VERSION_STRING = "Limber LOCAL [#{Deployed::ENVIRONMENT}]".freeze

APP_NAME = 'Limber'
RELEASE_NAME = 'DEV'
Expand Down
2 changes: 1 addition & 1 deletion lib/colour_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# or black text has better contrast for a given colour.
# https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
class ColourConverter
HEX = /#([0-f]{2})([0-f]{2})([0-f]{2})/.freeze
HEX = /#([0-f]{2})([0-f]{2})([0-f]{2})/

RED_MULTIPLIER = 0.2126
GREEN_MULTIPLIER = 0.7152
Expand Down
4 changes: 2 additions & 2 deletions lib/deployed_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def read_file(filename)
COMMIT = REPO_DATA.revision.presence || 'unknown_revision'
ABBREV_COMMIT = REPO_DATA.revision_short.presence || 'unknown_revision'

VERSION_STRING = "#{APP_NAME} #{VERSION_ID} [#{ENVIRONMENT}]"
VERSION_COMMIT = "#{BRANCH}@#{ABBREV_COMMIT}"
VERSION_STRING = "#{APP_NAME} #{VERSION_ID} [#{ENVIRONMENT}]".freeze
VERSION_COMMIT = "#{BRANCH}@#{ABBREV_COMMIT}".freeze
REPO_URL = REPO_DATA.release_url.presence || '#'
HOSTNAME = Socket.gethostname

Expand Down
2 changes: 1 addition & 1 deletion script/limber
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require 'uri'

CONFIG_FILE = "#{Dir.home}/.limber.environments.yml"
CONFIG_FILE = "#{Dir.home}/.limber.environments.yml".freeze

if ARGV[0].nil?
$stdout.puts <<-HELP
Expand Down
24 changes: 22 additions & 2 deletions spec/features/pooling_multiple_tubes_into_one_tube_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,25 @@
stub_api_post('sub-uuid', 'submit')
end

before do
allow(Sequencescape::Api::V2::Tube).to receive(:find_all)
.with(
include_used: false,
purpose_name: ['example-purpose'],
includes: 'purpose',
paginate: {
size: 30,
number: 1
}
)
.and_return([example_v2_tube, example_v2_tube2])

# Parent lookup
allow(Sequencescape::Api::V2::Tube).to receive(:find_all)
.with(barcode: [tube_barcode_1, tube_barcode_2], includes: [])
.and_return([example_v2_tube, example_v2_tube2])
end

background do
create :tube_config, name: parent_purpose_name, uuid: 'example-purpose-uuid'
create :pooled_tube_from_tubes_purpose_config,
Expand All @@ -165,7 +184,8 @@
# Available tubes search
allow(Sequencescape::Api::V2::Tube).to receive(:find_all)
.with(
{ include_used: false, purpose_name: ['example-purpose'] },
include_used: false,
purpose_name: ['example-purpose'],
includes: 'purpose',
paginate: {
size: 30,
Expand All @@ -176,7 +196,7 @@

# Parent lookup
allow(Sequencescape::Api::V2::Tube).to receive(:find_all)
.with({ barcode: [tube_barcode_1, tube_barcode_2] }, includes: [])
.with(barcode: [tube_barcode_1, tube_barcode_2], includes: [])
.and_return([example_v2_tube, example_v2_tube2])

# Old API still used when loading parent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

before do
allow(Sequencescape::Api::V2::Tube).to receive(:find_all)
.with({ barcode: barcodes }, includes: [])
.with(barcode: barcodes, includes: [])
.and_return([parent, parent2])

tube_creation_request
Expand Down
Loading

0 comments on commit 1ee1b44

Please sign in to comment.