Skip to content

Commit

Permalink
rubocop safe corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Katkov committed Jan 3, 2024
1 parent d4cf51b commit 568cecd
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
ruby-version: 3.2.2
bundler-cache: true
- name: Run Rubocop
run: bin/rubocop
run: bundle exec rubocop --parallel
tests:
name: Tests
runs-on: ubuntu-latest
Expand Down
12 changes: 6 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ gem "appraisal"
# gem "debug", ">= 1.0.0"

group :rubocop do
gem "rubocop", ">= 1.25.1", require: false
gem "rubocop-minitest", require: false
gem "rubocop-packaging", require: false
gem "rubocop-performance", require: false
gem "rubocop-rails", require: false
gem "rubocop-md", require: false
gem "rubocop", ">= 1.25.1", require: false
gem "rubocop-minitest", require: false
gem "rubocop-packaging", require: false
gem "rubocop-performance", require: false
gem "rubocop-rails", require: false
gem "rubocop-md", require: false
end
8 changes: 3 additions & 5 deletions app/models/solid_cache/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ class Record < ActiveRecord::Base

self.abstract_class = true

connects_to **SolidCache.connects_to if SolidCache.connects_to
connects_to(**SolidCache.connects_to) if SolidCache.connects_to

class << self
def disable_instrumentation
connection.with_instrumenter(NULL_INSTRUMENTER) do
yield
end
def disable_instrumentation(&block)
connection.with_instrumenter(NULL_INSTRUMENTER, &block)
end

def with_shard(shard, &block)
Expand Down
2 changes: 1 addition & 1 deletion bin/irb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Expand Down
2 changes: 1 addition & 1 deletion bin/rake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Expand Down
2 changes: 1 addition & 1 deletion bin/rdbg
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Expand Down
2 changes: 1 addition & 1 deletion bin/rubocop
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Expand Down
4 changes: 2 additions & 2 deletions lib/solid_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ def self.all_shards_config
connects_to && connects_to[:shards]
end

def self.each_shard
def self.each_shard(&block)
return to_enum(:each_shard) unless block_given?

if (shards = all_shards_config&.keys)
shards.each do |shard|
Record.connected_to(shard: shard) { yield }
Record.connected_to(shard: shard, &block)
end
else
yield
Expand Down
2 changes: 1 addition & 1 deletion lib/solid_cache/cluster/expiry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def expire_later
end

def expiry_counter
@expiry_counters ||= connection_names.to_h { |connection_name| [ connection_name, Counter.new(expire_every) ] }
@expiry_counters ||= connection_names.index_with { |connection_name| Counter.new(expire_every) }
@expiry_counters[Entry.current_shard]
end

Expand Down
2 changes: 1 addition & 1 deletion lib/solid_cache/store/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def read_serialized_entries(keys)
end

def read_multi_entries(names, **options)
keys_and_names = names.to_h { |name| [ normalize_key(name, options), name ] }
keys_and_names = names.index_by { |name| normalize_key(name, options) }
serialized_entries = read_serialized_entries(keys_and_names.keys)

keys_and_names.each_with_object({}) do |(key, name), results|
Expand Down
12 changes: 4 additions & 8 deletions lib/solid_cache/store/clusters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ def setup!
end

private
def reading_key(key, failsafe:, failsafe_returning: nil)
def reading_key(key, failsafe:, failsafe_returning: nil, &block)
failsafe(failsafe, returning: failsafe_returning) do
primary_cluster.with_connection_for(key) do
yield
end
primary_cluster.with_connection_for(key, &block)
end
end

Expand Down Expand Up @@ -65,13 +63,11 @@ def writing_keys(entries, failsafe:, failsafe_returning: nil)
end
end

def writing_all(failsafe:, failsafe_returning: nil)
def writing_all(failsafe:, failsafe_returning: nil, &block)
first_cluster_sync_rest_async do |cluster, async|
cluster.connection_names.each do |connection|
failsafe(failsafe, returning: failsafe_returning) do
cluster.with_connection(connection, async: async) do
yield
end
cluster.with_connection(connection, async: async, &block)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/unit/clear_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DeleteMatchedTest < ActiveSupport::TestCase

cache.clear

assert_equal cache.clear_with, :truncate
assert_equal :truncate, cache.clear_with
assert_equal 0, uncached_entry_count
end

Expand All @@ -23,7 +23,7 @@ class DeleteMatchedTest < ActiveSupport::TestCase

cache.clear

assert_equal cache.clear_with, :delete
assert_equal :delete, cache.clear_with
assert_equal 0, uncached_entry_count
end

Expand Down

0 comments on commit 568cecd

Please sign in to comment.