From f8fa852867f1593c5bbc205e2b3e86b32035ca74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Fri, 1 Dec 2023 15:44:36 +0100 Subject: [PATCH] chore: fix rubocop issues --- lib/activerecord_spanner_adapter/base.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/activerecord_spanner_adapter/base.rb b/lib/activerecord_spanner_adapter/base.rb index 08b8eab2..b341edf8 100644 --- a/lib/activerecord_spanner_adapter/base.rb +++ b/lib/activerecord_spanner_adapter/base.rb @@ -4,6 +4,7 @@ # license that can be found in the LICENSE file or at # https://opensource.org/licenses/MIT. +require "active_record/gem_version" require "activerecord_spanner_adapter/relation" module ActiveRecord @@ -14,7 +15,7 @@ class TableMetadata # :nodoc: end class Base - VERSION_7_1 = Gem::Version.create('7.1.0') + VERSION_7_1 = Gem::Version.create "7.1.0" # Creates an object (or multiple objects) and saves it to the database. This method will use mutations instead # of DML if there is no active transaction, or if the active transaction has been created with the option @@ -64,8 +65,12 @@ def self._insert_record values, returning = [] end result = connection.insert(im, "#{self} Create", primary_key || false, primary_key_value) - return result if ActiveRecord::gem_version < VERSION_7_1 - [result] + _convert_primary_key result + end + + def self._convert_primary_key primary_key_value + return primary_key_value if ActiveRecord.gem_version < VERSION_7_1 + [primary_key_value] end def self._upsert_record values @@ -137,11 +142,9 @@ def self._buffer_record values, method mutation = Google::Cloud::Spanner::V1::Mutation.new( "#{method}": write ) - connection.current_spanner_transaction.buffer mutation - return primary_key_value if ActiveRecord::gem_version < VERSION_7_1 - [primary_key_value] + _convert_primary_key primary_key_value end def self._set_composite_primary_key_values primary_key, values