From ae5e150a8b784c8e575c0c56f8339563cb23a9a2 Mon Sep 17 00:00:00 2001 From: "juan.alpizar" Date: Thu, 14 Mar 2024 13:05:18 -0600 Subject: [PATCH 1/3] deleded abstract_mysql_adapter behavior --- .../behaviors/abstract_mysql_adapter.rb | 42 ------------------- lib/strainer/patches.rb | 1 - 2 files changed, 43 deletions(-) delete mode 100644 lib/strainer/behaviors/abstract_mysql_adapter.rb diff --git a/lib/strainer/behaviors/abstract_mysql_adapter.rb b/lib/strainer/behaviors/abstract_mysql_adapter.rb deleted file mode 100644 index 016c849..0000000 --- a/lib/strainer/behaviors/abstract_mysql_adapter.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -require 'active_record' - -module Strainer - module Behaviors - class AbstractMysqlAdapter < Strainer::RuntimeBehavior - # This module replace old user stamp columns `created_by` and `updated_by` into `created_by_id` and - # `updated_by_id` - # It logs usages so that the code can be later corrected. - # - # @example - # Model.select('created_by, updated_by') => `SELECT created_by_id, updated_by_id FROM model` - # Model.find_by_sql('SELECT created_by, updated_by FROM model') => - # `SELECT created_by_id, updated_by_id FROM model` - # ActiveRecord::Base.connection.select_all('SELECT created_by, updated_by FROM model') => - # `SELECT created_by_id, updated_by_id FROM model` - # ActiveRecord::Base.connection.select_all('SELECT * FROM model WHERE created_by IS NULL') => - # `SELECT * FROM model WHERE created_by_id IS NULL` - module ReplaceUserStamp - include Strainer::Logable - - STATEMENTS_REGEX = /(?i)(SELECT|INSERT|UPDATE|DELETE)\b/.freeze - USER_STAMP_REGEX = /(?i)(created_by|updated_by)\b/.freeze - - # Executes the SQL statement in the context of this connection. - def execute(sql, name = nil) - if sql.match?(STATEMENTS_REGEX) && sql.match?(USER_STAMP_REGEX) - strainer_log('SQL_WITH_USER_STAMP', custom: { name: name, sql: sql }) - sql = sql.dup.gsub(USER_STAMP_REGEX) { |column| "#{column}_id" } - end - - super - end - end - - def apply_patch! - ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend(ReplaceUserStamp) - end - end - end -end diff --git a/lib/strainer/patches.rb b/lib/strainer/patches.rb index 4b0cbd2..005820d 100644 --- a/lib/strainer/patches.rb +++ b/lib/strainer/patches.rb @@ -15,7 +15,6 @@ def self.setup!(component) ) when :active_record load_behaviors( - Behaviors::AbstractMysqlAdapter, Behaviors::ForcedReloading, Behaviors::RelationDelegationChanges, Behaviors::FinderChanges, From 3114433494c5a4981e105355238d796cde3d98a5 Mon Sep 17 00:00:00 2001 From: "juan.alpizar" Date: Fri, 15 Mar 2024 10:02:56 -0600 Subject: [PATCH 2/3] changed parameter --- lib/strainer/behaviors/parameters_as_hash.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/strainer/behaviors/parameters_as_hash.rb b/lib/strainer/behaviors/parameters_as_hash.rb index 8516318..5af6ff4 100644 --- a/lib/strainer/behaviors/parameters_as_hash.rb +++ b/lib/strainer/behaviors/parameters_as_hash.rb @@ -44,7 +44,7 @@ module ReConvertValue private - def convert_value(value, conversion: nil) + def convert_value(value, conversion = nil) return value if value.is_a? ActionController::Parameters super From 44ab393cc5fe2ac24d15124d3dbfc000fc4da837 Mon Sep 17 00:00:00 2001 From: "juan.alpizar" Date: Fri, 15 Mar 2024 10:15:40 -0600 Subject: [PATCH 3/3] changed parameter --- lib/strainer/behaviors/parameters_as_hash.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/strainer/behaviors/parameters_as_hash.rb b/lib/strainer/behaviors/parameters_as_hash.rb index 5af6ff4..3fc8539 100644 --- a/lib/strainer/behaviors/parameters_as_hash.rb +++ b/lib/strainer/behaviors/parameters_as_hash.rb @@ -44,7 +44,7 @@ module ReConvertValue private - def convert_value(value, conversion = nil) + def convert_value(value, options = {}) return value if value.is_a? ActionController::Parameters super