From 9b83fe20f3a9e6aa28aa694d4af6b84e35dd5efc Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Thu, 19 Oct 2023 10:37:17 +0200 Subject: [PATCH] Fix Style/ExplicitBlockArgument offenses --- .rubocop_todo.yml | 7 ------- lib/chrono_model/adapter/indexes.rb | 10 +++++----- lib/chrono_model/adapter/migrations.rb | 4 ++-- lib/chrono_model/time_machine/history_model.rb | 4 ++-- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 01fd8f9..19e8a0c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -87,13 +87,6 @@ Style/CommentedKeyword: Style/Documentation: Enabled: false -# This cop supports safe autocorrection (--autocorrect). -Style/ExplicitBlockArgument: - Exclude: - - 'lib/chrono_model/adapter/indexes.rb' - - 'lib/chrono_model/adapter/migrations.rb' - - 'lib/chrono_model/time_machine/history_model.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: MinBodyLength, AllowConsecutiveConditionals. Style/GuardClause: diff --git a/lib/chrono_model/adapter/indexes.rb b/lib/chrono_model/adapter/indexes.rb index dd2ec65..668b9de 100644 --- a/lib/chrono_model/adapter/indexes.rb +++ b/lib/chrono_model/adapter/indexes.rb @@ -178,18 +178,18 @@ def temporal_index_names(table, range, options = {}) # only on the history table, and the creation methods already # run scoped into the correct schema. # - def chrono_alter_index(table_name, options) + def chrono_alter_index(table_name, options, &block) if is_chrono?(table_name) && !options[:on_current_schema] - on_temporal_schema { yield } - on_history_schema { yield } + on_temporal_schema(&block) + on_history_schema(&block) else yield end end - def chrono_alter_constraint(table_name, options) + def chrono_alter_constraint(table_name, options, &block) if is_chrono?(table_name) && !options[:on_current_schema] - on_temporal_schema { yield } + on_temporal_schema(&block) else yield end diff --git a/lib/chrono_model/adapter/migrations.rb b/lib/chrono_model/adapter/migrations.rb index d233ae2..001f2c7 100644 --- a/lib/chrono_model/adapter/migrations.rb +++ b/lib/chrono_model/adapter/migrations.rb @@ -173,13 +173,13 @@ def remove_column(table_name, column_name, type = nil, **options) # types, the view must be dropped and recreated, while the change has # to be applied to the table in the temporal schema. # - def drop_and_recreate_public_view(table_name, opts = {}) + def drop_and_recreate_public_view(table_name, opts = {}, &block) transaction do options = chrono_metadata_for(table_name).merge(opts) execute "DROP VIEW #{table_name}" - on_temporal_schema { yield } + on_temporal_schema(&block) # Recreate the triggers chrono_public_view_ddl(table_name, options) diff --git a/lib/chrono_model/time_machine/history_model.rb b/lib/chrono_model/time_machine/history_model.rb index 433a7f1..ef187ca 100644 --- a/lib/chrono_model/time_machine/history_model.rb +++ b/lib/chrono_model/time_machine/history_model.rb @@ -242,11 +242,11 @@ def read_attribute(attr_name, &block) private - def with_hid_pkey + def with_hid_pkey(&block) old_primary_key = @primary_key @primary_key = :hid - self.class.with_hid_pkey { yield } + self.class.with_hid_pkey(&block) ensure @primary_key = old_primary_key end