diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 76e2489..a6cd297 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,8 +3,10 @@ on: [push, pull_request] jobs: rubocop: - name: Rubocop + name: RuboCop runs-on: ubuntu-latest + env: + BUNDLE_ONLY: rubocop steps: - name: Checkout code uses: actions/checkout@v4 @@ -14,7 +16,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 diff --git a/.rubocop.yml b/.rubocop.yml index 63b149e..e8ce860 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,9 +1,382 @@ -# 37signals house style -inherit_gem: { rubocop-37signals: rubocop.yml } +require: + - rubocop-minitest + - rubocop-packaging + - rubocop-performance + - rubocop-rails + - rubocop-md AllCops: + TargetRubyVersion: 3.1 + # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop + # to ignore them, so only the ones explicitly set in this file are enabled. + DisabledByDefault: true + SuggestExtensions: false Exclude: # These have been copied from the Rails repo - test/unit/behaviors/* # Don't second guess the generated schemas - - test/dummy/db/*schema.rb + - test/dummy/* + - '**/tmp/**/*' + - '**/vendor/**/*' + - '**/node_modules/**/*' + +Performance: + Exclude: + - '**/test/**/*' + +# Prefer assert_not over assert ! +Rails/AssertNot: + Include: + - '**/test/**/*' + +# Prefer assert_not_x over refute_x +Rails/RefuteMethods: + Include: + - '**/test/**/*' + +Rails/IndexBy: + Enabled: true + +Rails/IndexWith: + Enabled: true + +# Prefer &&/|| over and/or. +Style/AndOr: + Enabled: true + +# Align `when` with `case`. +Layout/CaseIndentation: + Enabled: true + +Layout/ClosingHeredocIndentation: + Enabled: true + +Layout/ClosingParenthesisIndentation: + Enabled: true + +# Align comments with method definitions. +Layout/CommentIndentation: + Enabled: true + +Layout/ElseAlignment: + Enabled: true + +# Align `end` with the matching keyword or starting expression except for +# assignments, where it should be aligned with the LHS. +Layout/EndAlignment: + Enabled: true + EnforcedStyleAlignWith: variable + AutoCorrect: true + +Layout/EndOfLine: + Enabled: true + +Layout/EmptyLineAfterMagicComment: + Enabled: true + +Layout/EmptyLinesAroundAccessModifier: + Enabled: true + EnforcedStyle: only_before + +Layout/EmptyLinesAroundBlockBody: + Enabled: true + +# In a regular class definition, no empty lines around the body. +Layout/EmptyLinesAroundClassBody: + Enabled: true + +# In a regular method definition, no empty lines around the body. +Layout/EmptyLinesAroundMethodBody: + Enabled: true + +# In a regular module definition, no empty lines around the body. +Layout/EmptyLinesAroundModuleBody: + Enabled: true + +# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }. +Style/HashSyntax: + Enabled: true + EnforcedShorthandSyntax: either + +# Method definitions after `private` or `protected` isolated calls need one +# extra level of indentation. +Layout/IndentationConsistency: + Enabled: true + EnforcedStyle: indented_internal_methods + Exclude: + - '**/*.md' + +# Two spaces, no tabs (for indentation). +Layout/IndentationWidth: + Enabled: true + +Layout/LeadingCommentSpace: + Enabled: true + +Layout/SpaceAfterColon: + Enabled: true + +Layout/SpaceAfterComma: + Enabled: true + +Layout/SpaceAfterSemicolon: + Enabled: true + +Layout/SpaceAroundEqualsInParameterDefault: + Enabled: true + +Layout/SpaceAroundKeyword: + Enabled: true + +Layout/SpaceAroundOperators: + Enabled: true + +Layout/SpaceBeforeComma: + Enabled: true + +Layout/SpaceBeforeComment: + Enabled: true + +Layout/SpaceBeforeFirstArg: + Enabled: true + +Style/DefWithParentheses: + Enabled: true + +# Defining a method with parameters needs parentheses. +Style/MethodDefParentheses: + Enabled: true + +Style/ExplicitBlockArgument: + Enabled: true + +Style/FrozenStringLiteralComment: + Enabled: true + EnforcedStyle: always + Exclude: + - 'actionview/test/**/*.builder' + - 'actionview/test/**/*.ruby' + - 'actionpack/test/**/*.builder' + - 'actionpack/test/**/*.ruby' + - 'activestorage/db/migrate/**/*.rb' + - 'activestorage/db/update_migrate/**/*.rb' + - 'actionmailbox/db/migrate/**/*.rb' + - 'actiontext/db/migrate/**/*.rb' + - '**/*.md' + +Style/MapToHash: + Enabled: true + +Style/RedundantFreeze: + Enabled: true + +# Use `foo {}` not `foo{}`. +Layout/SpaceBeforeBlockBraces: + Enabled: true + +# Use `foo { bar }` not `foo {bar}`. +Layout/SpaceInsideBlockBraces: + Enabled: true + EnforcedStyleForEmptyBraces: space + +# Use `{ a: 1 }` not `{a:1}`. +Layout/SpaceInsideHashLiteralBraces: + Enabled: true + +Layout/SpaceInsideParens: + Enabled: true + +# Check quotes usage according to lint rule below. +Style/StringLiterals: + Enabled: true + EnforcedStyle: double_quotes + +# Detect hard tabs, no hard tabs. +Layout/IndentationStyle: + Enabled: true + +# Empty lines should not have any spaces. +Layout/TrailingEmptyLines: + Enabled: true + +# No trailing whitespace. +Layout/TrailingWhitespace: + Enabled: true + +# Use quotes for string literals when they are enough. +Style/RedundantPercentQ: + Enabled: true + +Lint/AmbiguousOperator: + Enabled: true + +Lint/AmbiguousRegexpLiteral: + Enabled: true + +Lint/DuplicateRequire: + Enabled: true + +Lint/DuplicateMagicComment: + Enabled: true + +Lint/DuplicateMethods: + Enabled: true + +Lint/ErbNewArguments: + Enabled: true + +Lint/EnsureReturn: + Enabled: true + +Lint/MissingCopEnableDirective: + Enabled: true + +# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg. +Lint/RequireParentheses: + Enabled: true + +Lint/RedundantCopDisableDirective: + Enabled: true + +Lint/RedundantCopEnableDirective: + Enabled: true + +Lint/RedundantStringCoercion: + Enabled: true + +Lint/RedundantSafeNavigation: + Enabled: true + +Lint/UriEscapeUnescape: + Enabled: true + +Lint/UselessAssignment: + Enabled: true + +Lint/DeprecatedClassMethods: + Enabled: true + +Lint/InterpolationCheck: + Enabled: true + Exclude: + - '**/test/**/*' + +Style/EvalWithLocation: + Enabled: true + Exclude: + - '**/test/**/*' + +Style/ParenthesesAroundCondition: + Enabled: true + +Style/HashTransformKeys: + Enabled: true + +Style/HashTransformValues: + Enabled: true + +Style/RedundantBegin: + Enabled: true + +Style/RedundantReturn: + Enabled: true + AllowMultipleReturnValues: true + +Style/RedundantRegexpEscape: + Enabled: true + +Style/Semicolon: + Enabled: true + AllowAsExpressionSeparator: true + +# Prefer Foo.method over Foo::method +Style/ColonMethodCall: + Enabled: true + +Style/TrivialAccessors: + Enabled: true + +# Prefer a = b || c over a = b ? b : c +Style/RedundantCondition: + Enabled: true + +Style/RedundantDoubleSplatHashBraces: + Enabled: true + +Performance/BindCall: + Enabled: true + +Performance/FlatMap: + Enabled: true + +Performance/MapCompact: + Enabled: true + +Performance/SelectMap: + Enabled: true + +Performance/RedundantMerge: + Enabled: true + +Performance/StartWith: + Enabled: true + +Performance/EndWith: + Enabled: true + +Performance/RegexpMatch: + Enabled: true + +Performance/ReverseEach: + Enabled: true + +Performance/StringReplacement: + Enabled: true + +Performance/DeletePrefix: + Enabled: true + +Performance/DeleteSuffix: + Enabled: true + +Performance/OpenStruct: + Enabled: true + +Performance/InefficientHashSearch: + Enabled: true + +Performance/ConstantRegexp: + Enabled: true + +Performance/RedundantStringChars: + Enabled: true + +Performance/StringInclude: + Enabled: true + +Minitest/AssertPredicate: + Enabled: true + +Minitest/AssertRaisesWithRegexpArgument: + Enabled: true + +Minitest/AssertWithExpectedArgument: + Enabled: true + +Minitest/LiteralAsActualArgument: + Enabled: true + +Minitest/NonExecutableTestMethod: + Enabled: true + +Minitest/SkipEnsure: + Enabled: true + +Minitest/UnreachableAssertion: + Enabled: true + +Markdown: + # Whether to run RuboCop against non-valid snippets + WarnInvalid: true + # Whether to lint codeblocks without code attributes + Autodetect: false diff --git a/Appraisals b/Appraisals index 6596d08..fe8d666 100644 --- a/Appraisals +++ b/Appraisals @@ -1,3 +1,5 @@ +# frozen_string_literal: true + appraise "rails-7" do gem "rails", github: "rails/rails", branch: "7-0-stable" end diff --git a/Gemfile b/Gemfile index 785aa43..a83ed54 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } @@ -10,8 +12,16 @@ gem "pg" gem "sprockets-rails" -gem "rubocop-37signals", github: "basecamp/house-style", require: false gem "appraisal" # Start debugger with binding.b [https://github.com/ruby/debug] # 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 +end diff --git a/Gemfile.lock b/Gemfile.lock index 501db15..5fb3788 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,13 +1,3 @@ -GIT - remote: https://github.com/basecamp/house-style.git - revision: a9ca7e4ab80b72c1a10053c50efefe8cd275e3b8 - specs: - rubocop-37signals (1.0.0) - rubocop - rubocop-minitest - rubocop-performance - rubocop-rails - PATH remote: . specs: @@ -97,15 +87,15 @@ GEM thor (>= 0.14.0) ast (2.4.2) base64 (0.2.0) - bigdecimal (3.1.4) + bigdecimal (3.1.5) builder (3.2.4) concurrent-ruby (1.2.2) connection_pool (2.4.1) crass (1.0.6) date (3.3.4) - debug (1.8.0) - irb (>= 1.5.0) - reline (>= 0.3.1) + debug (1.9.1) + irb (~> 1.10) + reline (>= 0.3.8) drb (2.2.0) ruby2_keywords erubi (1.12.0) @@ -113,11 +103,11 @@ GEM activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) - io-console (0.6.0) - irb (1.9.0) + io-console (0.7.1) + irb (1.11.0) rdoc reline (>= 0.3.8) - json (2.6.3) + json (2.7.1) language_server-protocol (3.17.0.3) loofah (2.22.0) crass (~> 1.0.2) @@ -134,7 +124,7 @@ GEM ruby2_keywords (>= 0.0.5) mutex_m (0.2.0) mysql2 (0.5.5) - net-imap (0.4.5) + net-imap (0.4.9) date net-protocol net-pop (0.1.2) @@ -143,19 +133,19 @@ GEM timeout net-smtp (0.4.0) net-protocol - nio4r (2.5.9) - nokogiri (1.15.4-arm64-darwin) + nio4r (2.7.0) + nokogiri (1.16.0-arm64-darwin) racc (~> 1.4) - nokogiri (1.15.4-x86_64-darwin) + nokogiri (1.16.0-x86_64-darwin) racc (~> 1.4) - nokogiri (1.15.4-x86_64-linux) + nokogiri (1.16.0-x86_64-linux) racc (~> 1.4) - parallel (1.23.0) + parallel (1.24.0) parser (3.2.2.4) ast (~> 2.4.1) racc pg (1.5.4) - psych (5.1.1.1) + psych (5.1.2) stringio racc (1.7.3) rack (3.0.8) @@ -197,13 +187,13 @@ GEM zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.1.0) - rdoc (6.6.0) + rdoc (6.6.2) psych (>= 4.0.0) - regexp_parser (2.8.2) - reline (0.4.0) + regexp_parser (2.8.3) + reline (0.4.1) io-console (~> 0.5) rexml (3.2.6) - rubocop (1.57.2) + rubocop (1.59.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -211,20 +201,26 @@ GEM rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.30.0) parser (>= 3.2.1.0) - rubocop-minitest (0.33.0) + rubocop-md (1.2.2) + rubocop (>= 1.0) + rubocop-minitest (0.34.3) rubocop (>= 1.39, < 2.0) - rubocop-performance (1.19.1) - rubocop (>= 1.7.0, < 2.0) - rubocop-ast (>= 0.4.0) - rubocop-rails (2.22.1) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-packaging (0.5.2) + rubocop (>= 1.33, < 2.0) + rubocop-performance (1.20.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-rails (2.23.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) sprockets (4.2.1) @@ -234,10 +230,10 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.6.8-arm64-darwin) - sqlite3 (1.6.8-x86_64-darwin) - sqlite3 (1.6.8-x86_64-linux) - stringio (3.0.9) + sqlite3 (1.7.0-arm64-darwin) + sqlite3 (1.7.0-x86_64-darwin) + sqlite3 (1.7.0-x86_64-linux) + stringio (3.1.0) thor (1.3.0) timeout (0.4.1) tzinfo (2.0.6) @@ -262,7 +258,12 @@ DEPENDENCIES mocha mysql2 pg - rubocop-37signals! + rubocop (>= 1.25.1) + rubocop-md + rubocop-minitest + rubocop-packaging + rubocop-performance + rubocop-rails solid_cache! sprockets-rails sqlite3 diff --git a/README.md b/README.md index ee7950d..465d5d6 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ To shard: 3. Pass the shards for the cache to use via the cluster option For example: -```ruby +```yml # config/database.yml production: cache_shard1: @@ -167,8 +167,9 @@ production: cache_shard3: database: cache3_production host: cache3-db +``` - +```ruby # config/environment/production.rb Rails.application.configure do config.solid_cache.connects_to = { diff --git a/Rakefile b/Rakefile index e7793b5..e990eb8 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "bundler/setup" APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__) diff --git a/app/jobs/solid_cache/expiry_job.rb b/app/jobs/solid_cache/expiry_job.rb index 43aef59..65e0ff3 100644 --- a/app/jobs/solid_cache/expiry_job.rb +++ b/app/jobs/solid_cache/expiry_job.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache class ExpiryJob < ActiveJob::Base def perform(count, shard: nil, max_age:, max_entries:) diff --git a/app/models/solid_cache/entry.rb b/app/models/solid_cache/entry.rb index feaa9f4..efc5efe 100644 --- a/app/models/solid_cache/entry.rb +++ b/app/models/solid_cache/entry.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache class Entry < Record # This is all quite awkward but it achieves a couple of performance aims diff --git a/app/models/solid_cache/record.rb b/app/models/solid_cache/record.rb index b06128a..7591de8 100644 --- a/app/models/solid_cache/record.rb +++ b/app/models/solid_cache/record.rb @@ -1,16 +1,16 @@ +# frozen_string_literal: true + module SolidCache class Record < ActiveRecord::Base NULL_INSTRUMENTER = ActiveSupport::Notifications::Instrumenter.new(ActiveSupport::Notifications::Fanout.new) 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) diff --git a/bin/irb b/bin/irb index 42346ee..e7de6d6 100755 --- a/bin/irb +++ b/bin/irb @@ -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 File.read(bundle_binstub, 300).include?("This file was generated by Bundler") load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. diff --git a/bin/rails b/bin/rails index 41ed1e0..d3170a3 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + # This command will automatically be run when you run "rails" with Rails gems # installed from the root of your application. diff --git a/bin/rake b/bin/rake index 51e10c4..4eb7d7b 100755 --- a/bin/rake +++ b/bin/rake @@ -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 File.read(bundle_binstub, 300).include?("This file was generated by Bundler") load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. diff --git a/bin/rdbg b/bin/rdbg index 0622550..5e3b279 100755 --- a/bin/rdbg +++ b/bin/rdbg @@ -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 File.read(bundle_binstub, 300).include?("This file was generated by Bundler") load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. diff --git a/bin/rubocop b/bin/rubocop index 2b1fa1f..369a05b 100755 --- a/bin/rubocop +++ b/bin/rubocop @@ -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 File.read(bundle_binstub, 300).include?("This file was generated by Bundler") load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. diff --git a/db/migrate/20230724121448_create_solid_cache_entries.rb b/db/migrate/20230724121448_create_solid_cache_entries.rb index 82749d9..693ad10 100644 --- a/db/migrate/20230724121448_create_solid_cache_entries.rb +++ b/db/migrate/20230724121448_create_solid_cache_entries.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateSolidCacheEntries < ActiveRecord::Migration[7.0] def change create_table :solid_cache_entries do |t| diff --git a/gemfiles/rails_7.gemfile b/gemfiles/rails_7.gemfile index 2692e90..bb85a6c 100644 --- a/gemfiles/rails_7.gemfile +++ b/gemfiles/rails_7.gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by Appraisal source "https://rubygems.org" @@ -6,8 +8,16 @@ gem "sqlite3" gem "mysql2" gem "pg" gem "sprockets-rails" -gem "rubocop-37signals", require: false, git: "https://github.com/basecamp/house-style.git" gem "appraisal" gem "rails", branch: "7-0-stable", git: "https://github.com/rails/rails.git" +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 +end + gemspec path: "../" diff --git a/gemfiles/rails_7.gemfile.lock b/gemfiles/rails_7.gemfile.lock index 9e662af..d9f3a45 100644 --- a/gemfiles/rails_7.gemfile.lock +++ b/gemfiles/rails_7.gemfile.lock @@ -1,16 +1,6 @@ -GIT - remote: https://github.com/basecamp/house-style.git - revision: a9ca7e4ab80b72c1a10053c50efefe8cd275e3b8 - specs: - rubocop-37signals (1.0.0) - rubocop - rubocop-minitest - rubocop-performance - rubocop-rails - GIT remote: https://github.com/rails/rails.git - revision: a1759f292c48d5ebe49edf6c7a937bfab2901023 + revision: 71e29aaa0ffecf13da37428f7cbae110cd104689 branch: 7-0-stable specs: actioncable (7.0.8) @@ -76,6 +66,7 @@ GIT mini_mime (>= 1.1.0) activesupport (7.0.8) base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) drb i18n (>= 1.6, < 2) @@ -119,13 +110,14 @@ GEM thor (>= 0.14.0) ast (2.4.2) base64 (0.2.0) + bigdecimal (3.1.5) builder (3.2.4) concurrent-ruby (1.2.2) crass (1.0.6) date (3.3.4) - debug (1.8.0) - irb (>= 1.5.0) - reline (>= 0.3.1) + debug (1.9.1) + irb (~> 1.10) + reline (>= 0.3.8) drb (2.2.0) ruby2_keywords erubi (1.12.0) @@ -133,11 +125,11 @@ GEM activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) - io-console (0.6.0) - irb (1.9.0) + io-console (0.7.1) + irb (1.11.0) rdoc reline (>= 0.3.8) - json (2.6.3) + json (2.7.1) language_server-protocol (3.17.0.3) loofah (2.22.0) crass (~> 1.0.2) @@ -155,7 +147,7 @@ GEM ruby2_keywords (>= 0.0.5) mutex_m (0.2.0) mysql2 (0.5.5) - net-imap (0.4.5) + net-imap (0.4.9) date net-protocol net-pop (0.1.2) @@ -164,19 +156,19 @@ GEM timeout net-smtp (0.4.0) net-protocol - nio4r (2.5.9) - nokogiri (1.15.4-arm64-darwin) + nio4r (2.7.0) + nokogiri (1.16.0-arm64-darwin) racc (~> 1.4) - nokogiri (1.15.4-x86_64-darwin) + nokogiri (1.16.0-x86_64-darwin) racc (~> 1.4) - nokogiri (1.15.4-x86_64-linux) + nokogiri (1.16.0-x86_64-linux) racc (~> 1.4) - parallel (1.23.0) + parallel (1.24.0) parser (3.2.2.4) ast (~> 2.4.1) racc pg (1.5.4) - psych (5.1.1.1) + psych (5.1.2) stringio racc (1.7.3) rack (2.2.8) @@ -191,13 +183,13 @@ GEM nokogiri (~> 1.14) rainbow (3.1.1) rake (13.1.0) - rdoc (6.6.0) + rdoc (6.6.2) psych (>= 4.0.0) - regexp_parser (2.8.2) - reline (0.4.0) + regexp_parser (2.8.3) + reline (0.4.1) io-console (~> 0.5) rexml (3.2.6) - rubocop (1.57.2) + rubocop (1.59.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -205,20 +197,26 @@ GEM rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.30.0) parser (>= 3.2.1.0) - rubocop-minitest (0.33.0) + rubocop-md (1.2.2) + rubocop (>= 1.0) + rubocop-minitest (0.34.3) rubocop (>= 1.39, < 2.0) - rubocop-performance (1.19.1) - rubocop (>= 1.7.0, < 2.0) - rubocop-ast (>= 0.4.0) - rubocop-rails (2.22.1) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-packaging (0.5.2) + rubocop (>= 1.33, < 2.0) + rubocop-performance (1.20.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-rails (2.23.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) sprockets (4.2.1) @@ -228,10 +226,10 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.6.8-arm64-darwin) - sqlite3 (1.6.8-x86_64-darwin) - sqlite3 (1.6.8-x86_64-linux) - stringio (3.0.9) + sqlite3 (1.7.0-arm64-darwin) + sqlite3 (1.7.0-x86_64-darwin) + sqlite3 (1.7.0-x86_64-linux) + stringio (3.1.0) thor (1.3.0) timeout (0.4.1) tzinfo (2.0.6) @@ -256,7 +254,12 @@ DEPENDENCIES mysql2 pg rails! - rubocop-37signals! + rubocop (>= 1.25.1) + rubocop-md + rubocop-minitest + rubocop-packaging + rubocop-performance + rubocop-rails solid_cache! sprockets-rails sqlite3 diff --git a/gemfiles/rails_7_1.gemfile b/gemfiles/rails_7_1.gemfile index cb238c5..b3b0888 100644 --- a/gemfiles/rails_7_1.gemfile +++ b/gemfiles/rails_7_1.gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by Appraisal source "https://rubygems.org" @@ -6,8 +8,16 @@ gem "sqlite3" gem "mysql2" gem "pg" gem "sprockets-rails" -gem "rubocop-37signals", require: false, git: "https://github.com/basecamp/house-style.git" gem "appraisal" gem "rails", branch: "7-1-stable", git: "https://github.com/rails/rails.git" +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 +end + gemspec path: "../" diff --git a/gemfiles/rails_7_1.gemfile.lock b/gemfiles/rails_7_1.gemfile.lock index 1969c3e..14b5739 100644 --- a/gemfiles/rails_7_1.gemfile.lock +++ b/gemfiles/rails_7_1.gemfile.lock @@ -1,16 +1,6 @@ -GIT - remote: https://github.com/basecamp/house-style.git - revision: a9ca7e4ab80b72c1a10053c50efefe8cd275e3b8 - specs: - rubocop-37signals (1.0.0) - rubocop - rubocop-minitest - rubocop-performance - rubocop-rails - GIT remote: https://github.com/rails/rails.git - revision: 71e0c050b81498adb1fec2a18056038ca14990ca + revision: 9a2bfebbc8e4800de58c26a5a119c3acad068664 branch: 7-1-stable specs: actioncable (7.1.2) @@ -125,15 +115,15 @@ GEM thor (>= 0.14.0) ast (2.4.2) base64 (0.2.0) - bigdecimal (3.1.4) + bigdecimal (3.1.5) builder (3.2.4) concurrent-ruby (1.2.2) connection_pool (2.4.1) crass (1.0.6) date (3.3.4) - debug (1.8.0) - irb (>= 1.5.0) - reline (>= 0.3.1) + debug (1.9.1) + irb (~> 1.10) + reline (>= 0.3.8) drb (2.2.0) ruby2_keywords erubi (1.12.0) @@ -141,11 +131,11 @@ GEM activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) - io-console (0.6.0) - irb (1.9.0) + io-console (0.7.1) + irb (1.11.0) rdoc reline (>= 0.3.8) - json (2.6.3) + json (2.7.1) language_server-protocol (3.17.0.3) loofah (2.22.0) crass (~> 1.0.2) @@ -162,7 +152,7 @@ GEM ruby2_keywords (>= 0.0.5) mutex_m (0.2.0) mysql2 (0.5.5) - net-imap (0.4.5) + net-imap (0.4.9) date net-protocol net-pop (0.1.2) @@ -171,19 +161,19 @@ GEM timeout net-smtp (0.4.0) net-protocol - nio4r (2.5.9) - nokogiri (1.15.4-arm64-darwin) + nio4r (2.7.0) + nokogiri (1.16.0-arm64-darwin) racc (~> 1.4) - nokogiri (1.15.4-x86_64-darwin) + nokogiri (1.16.0-x86_64-darwin) racc (~> 1.4) - nokogiri (1.15.4-x86_64-linux) + nokogiri (1.16.0-x86_64-linux) racc (~> 1.4) - parallel (1.23.0) + parallel (1.24.0) parser (3.2.2.4) ast (~> 2.4.1) racc pg (1.5.4) - psych (5.1.1.1) + psych (5.1.2) stringio racc (1.7.3) rack (3.0.8) @@ -203,13 +193,13 @@ GEM nokogiri (~> 1.14) rainbow (3.1.1) rake (13.1.0) - rdoc (6.6.0) + rdoc (6.6.2) psych (>= 4.0.0) - regexp_parser (2.8.2) - reline (0.4.0) + regexp_parser (2.8.3) + reline (0.4.1) io-console (~> 0.5) rexml (3.2.6) - rubocop (1.57.2) + rubocop (1.59.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -217,20 +207,26 @@ GEM rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.30.0) parser (>= 3.2.1.0) - rubocop-minitest (0.33.0) + rubocop-md (1.2.2) + rubocop (>= 1.0) + rubocop-minitest (0.34.3) rubocop (>= 1.39, < 2.0) - rubocop-performance (1.19.1) - rubocop (>= 1.7.0, < 2.0) - rubocop-ast (>= 0.4.0) - rubocop-rails (2.22.1) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-packaging (0.5.2) + rubocop (>= 1.33, < 2.0) + rubocop-performance (1.20.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-rails (2.23.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) sprockets (4.2.1) @@ -240,10 +236,10 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.6.8-arm64-darwin) - sqlite3 (1.6.8-x86_64-darwin) - sqlite3 (1.6.8-x86_64-linux) - stringio (3.0.9) + sqlite3 (1.7.0-arm64-darwin) + sqlite3 (1.7.0-x86_64-darwin) + sqlite3 (1.7.0-x86_64-linux) + stringio (3.1.0) thor (1.3.0) timeout (0.4.1) tzinfo (2.0.6) @@ -269,7 +265,12 @@ DEPENDENCIES mysql2 pg rails! - rubocop-37signals! + rubocop (>= 1.25.1) + rubocop-md + rubocop-minitest + rubocop-packaging + rubocop-performance + rubocop-rails solid_cache! sprockets-rails sqlite3 diff --git a/gemfiles/rails_main.gemfile b/gemfiles/rails_main.gemfile index 240793d..55129ba 100644 --- a/gemfiles/rails_main.gemfile +++ b/gemfiles/rails_main.gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by Appraisal source "https://rubygems.org" @@ -6,8 +8,16 @@ gem "sqlite3" gem "mysql2" gem "pg" gem "sprockets-rails" -gem "rubocop-37signals", require: false, git: "https://github.com/basecamp/house-style.git" gem "appraisal" gem "rails", branch: "main", git: "https://github.com/rails/rails.git" +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 +end + gemspec path: "../" diff --git a/gemfiles/rails_main.gemfile.lock b/gemfiles/rails_main.gemfile.lock index 4ffee19..7ca92d2 100644 --- a/gemfiles/rails_main.gemfile.lock +++ b/gemfiles/rails_main.gemfile.lock @@ -1,16 +1,6 @@ -GIT - remote: https://github.com/basecamp/house-style.git - revision: a9ca7e4ab80b72c1a10053c50efefe8cd275e3b8 - specs: - rubocop-37signals (1.0.0) - rubocop - rubocop-minitest - rubocop-performance - rubocop-rails - GIT remote: https://github.com/rails/rails.git - revision: f98bb7ed41d513539cd6a1af1f21d96ae4f3cd17 + revision: 1c3ae8719f2a127e1003916291e94305367a7dab branch: main specs: actioncable (7.2.0.alpha) @@ -49,6 +39,7 @@ GIT rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) actiontext (7.2.0.alpha) actionpack (= 7.2.0.alpha) activerecord (= 7.2.0.alpha) @@ -124,15 +115,15 @@ GEM thor (>= 0.14.0) ast (2.4.2) base64 (0.2.0) - bigdecimal (3.1.4) + bigdecimal (3.1.5) builder (3.2.4) concurrent-ruby (1.2.2) connection_pool (2.4.1) crass (1.0.6) date (3.3.4) - debug (1.8.0) - irb (>= 1.5.0) - reline (>= 0.3.1) + debug (1.9.1) + irb (~> 1.10) + reline (>= 0.3.8) drb (2.2.0) ruby2_keywords erubi (1.12.0) @@ -140,11 +131,11 @@ GEM activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) - io-console (0.6.0) - irb (1.9.0) + io-console (0.7.1) + irb (1.11.0) rdoc reline (>= 0.3.8) - json (2.6.3) + json (2.7.1) language_server-protocol (3.17.0.3) loofah (2.22.0) crass (~> 1.0.2) @@ -160,7 +151,7 @@ GEM mocha (2.1.0) ruby2_keywords (>= 0.0.5) mysql2 (0.5.5) - net-imap (0.4.5) + net-imap (0.4.9) date net-protocol net-pop (0.1.2) @@ -169,19 +160,19 @@ GEM timeout net-smtp (0.4.0) net-protocol - nio4r (2.5.9) - nokogiri (1.15.4-arm64-darwin) + nio4r (2.7.0) + nokogiri (1.16.0-arm64-darwin) racc (~> 1.4) - nokogiri (1.15.4-x86_64-darwin) + nokogiri (1.16.0-x86_64-darwin) racc (~> 1.4) - nokogiri (1.15.4-x86_64-linux) + nokogiri (1.16.0-x86_64-linux) racc (~> 1.4) - parallel (1.23.0) + parallel (1.24.0) parser (3.2.2.4) ast (~> 2.4.1) racc pg (1.5.4) - psych (5.1.1.1) + psych (5.1.2) stringio racc (1.7.3) rack (3.0.8) @@ -201,13 +192,13 @@ GEM nokogiri (~> 1.14) rainbow (3.1.1) rake (13.1.0) - rdoc (6.6.0) + rdoc (6.6.2) psych (>= 4.0.0) - regexp_parser (2.8.2) - reline (0.4.0) + regexp_parser (2.8.3) + reline (0.4.1) io-console (~> 0.5) rexml (3.2.6) - rubocop (1.57.2) + rubocop (1.59.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -215,20 +206,26 @@ GEM rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.30.0) parser (>= 3.2.1.0) - rubocop-minitest (0.33.0) + rubocop-md (1.2.2) + rubocop (>= 1.0) + rubocop-minitest (0.34.3) rubocop (>= 1.39, < 2.0) - rubocop-performance (1.19.1) - rubocop (>= 1.7.0, < 2.0) - rubocop-ast (>= 0.4.0) - rubocop-rails (2.22.1) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-packaging (0.5.2) + rubocop (>= 1.33, < 2.0) + rubocop-performance (1.20.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-rails (2.23.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) sprockets (4.2.1) @@ -238,15 +235,16 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.6.8-arm64-darwin) - sqlite3 (1.6.8-x86_64-darwin) - sqlite3 (1.6.8-x86_64-linux) - stringio (3.0.9) + sqlite3 (1.7.0-arm64-darwin) + sqlite3 (1.7.0-x86_64-darwin) + sqlite3 (1.7.0-x86_64-linux) + stringio (3.1.0) thor (1.3.0) timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) + useragent (0.16.10) webrick (1.8.1) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) @@ -267,7 +265,12 @@ DEPENDENCIES mysql2 pg rails! - rubocop-37signals! + rubocop (>= 1.25.1) + rubocop-md + rubocop-minitest + rubocop-packaging + rubocop-performance + rubocop-rails solid_cache! sprockets-rails sqlite3 diff --git a/lib/active_support/cache/solid_cache_store.rb b/lib/active_support/cache/solid_cache_store.rb index df21294..d91a5d0 100644 --- a/lib/active_support/cache/solid_cache_store.rb +++ b/lib/active_support/cache/solid_cache_store.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ActiveSupport module Cache SolidCacheStore = SolidCache::Store diff --git a/lib/generators/solid_cache/install/install_generator.rb b/lib/generators/solid_cache/install/install_generator.rb index 6b649be..f8ee53f 100644 --- a/lib/generators/solid_cache/install/install_generator.rb +++ b/lib/generators/solid_cache/install/install_generator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class SolidCache::InstallGenerator < Rails::Generators::Base class_option :skip_migrations, type: :boolean, default: nil, desc: "Skip migrations" diff --git a/lib/solid_cache.rb b/lib/solid_cache.rb index 6f61cad..67c0b4a 100644 --- a/lib/solid_cache.rb +++ b/lib/solid_cache.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "zeitwerk" require "solid_cache/engine" @@ -17,12 +19,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.with_shard(shard) { yield } + Record.with_shard(shard, &block) end else yield diff --git a/lib/solid_cache/cluster.rb b/lib/solid_cache/cluster.rb index 2e262eb..789a5ab 100644 --- a/lib/solid_cache/cluster.rb +++ b/lib/solid_cache/cluster.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache class Cluster include Connections, Execution, Expiry, Stats diff --git a/lib/solid_cache/cluster/connections.rb b/lib/solid_cache/cluster/connections.rb index 2eb4cec..442a069 100644 --- a/lib/solid_cache/cluster/connections.rb +++ b/lib/solid_cache/cluster/connections.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache class Cluster module Connections diff --git a/lib/solid_cache/cluster/execution.rb b/lib/solid_cache/cluster/execution.rb index 6789834..e732108 100644 --- a/lib/solid_cache/cluster/execution.rb +++ b/lib/solid_cache/cluster/execution.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache class Cluster module Execution diff --git a/lib/solid_cache/cluster/expiry.rb b/lib/solid_cache/cluster/expiry.rb index 17fe40a..8e5b9b9 100644 --- a/lib/solid_cache/cluster/expiry.rb +++ b/lib/solid_cache/cluster/expiry.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "concurrent/atomic/atomic_fixnum" module SolidCache @@ -34,7 +36,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 diff --git a/lib/solid_cache/cluster/stats.rb b/lib/solid_cache/cluster/stats.rb index e1884a4..16f0059 100644 --- a/lib/solid_cache/cluster/stats.rb +++ b/lib/solid_cache/cluster/stats.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache class Cluster module Stats @@ -6,7 +8,7 @@ def initialize(options = {}) end def stats - stats = { + { connections: connections.count, connection_stats: connections_stats } diff --git a/lib/solid_cache/connections.rb b/lib/solid_cache/connections.rb index 379245e..b27be2e 100644 --- a/lib/solid_cache/connections.rb +++ b/lib/solid_cache/connections.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache module Connections def self.from_config(options) diff --git a/lib/solid_cache/connections/sharded.rb b/lib/solid_cache/connections/sharded.rb index 185308c..c6d750c 100644 --- a/lib/solid_cache/connections/sharded.rb +++ b/lib/solid_cache/connections/sharded.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache module Connections class Sharded diff --git a/lib/solid_cache/connections/single.rb b/lib/solid_cache/connections/single.rb index 0a857ce..f7fde96 100644 --- a/lib/solid_cache/connections/single.rb +++ b/lib/solid_cache/connections/single.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache module Connections class Single diff --git a/lib/solid_cache/connections/unmanaged.rb b/lib/solid_cache/connections/unmanaged.rb index 23b2d74..6c36846 100644 --- a/lib/solid_cache/connections/unmanaged.rb +++ b/lib/solid_cache/connections/unmanaged.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache module Connections class Unmanaged diff --git a/lib/solid_cache/engine.rb b/lib/solid_cache/engine.rb index 3914853..67852ed 100644 --- a/lib/solid_cache/engine.rb +++ b/lib/solid_cache/engine.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support" module SolidCache diff --git a/lib/solid_cache/maglev_hash.rb b/lib/solid_cache/maglev_hash.rb index 6fc4a98..8183f82 100644 --- a/lib/solid_cache/maglev_hash.rb +++ b/lib/solid_cache/maglev_hash.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # See https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/44824.pdf module SolidCache diff --git a/lib/solid_cache/store.rb b/lib/solid_cache/store.rb index 22ca636..88d132f 100644 --- a/lib/solid_cache/store.rb +++ b/lib/solid_cache/store.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache class Store < ActiveSupport::Cache::Store include Api, Clusters, Entries, Failsafe diff --git a/lib/solid_cache/store/api.rb b/lib/solid_cache/store/api.rb index 6da663e..4eb5345 100644 --- a/lib/solid_cache/store/api.rb +++ b/lib/solid_cache/store/api.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache class Store module Api @@ -74,7 +76,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| diff --git a/lib/solid_cache/store/clusters.rb b/lib/solid_cache/store/clusters.rb index f9935c8..468775d 100644 --- a/lib/solid_cache/store/clusters.rb +++ b/lib/solid_cache/store/clusters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache class Store module Clusters @@ -20,11 +22,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 @@ -65,13 +65,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 diff --git a/lib/solid_cache/store/entries.rb b/lib/solid_cache/store/entries.rb index 90417f2..2a258f6 100644 --- a/lib/solid_cache/store/entries.rb +++ b/lib/solid_cache/store/entries.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache class Store module Entries diff --git a/lib/solid_cache/store/failsafe.rb b/lib/solid_cache/store/failsafe.rb index 5ab3ce0..2f5c711 100644 --- a/lib/solid_cache/store/failsafe.rb +++ b/lib/solid_cache/store/failsafe.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache class Store module Failsafe diff --git a/lib/solid_cache/version.rb b/lib/solid_cache/version.rb index fd97b53..1585bcc 100644 --- a/lib/solid_cache/version.rb +++ b/lib/solid_cache/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidCache VERSION = "0.2.0" end diff --git a/lib/tasks/solid_cache_tasks.rake b/lib/tasks/solid_cache_tasks.rake index 7f3280c..55be806 100644 --- a/lib/tasks/solid_cache_tasks.rake +++ b/lib/tasks/solid_cache_tasks.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + desc "Copy over the migration, and set cache" namespace :solid_cache do task :install do diff --git a/solid_cache.gemspec b/solid_cache.gemspec index afaeac5..8b7b216 100644 --- a/solid_cache.gemspec +++ b/solid_cache.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "lib/solid_cache/version" Gem::Specification.new do |spec| diff --git a/test/dummy/Rakefile b/test/dummy/Rakefile index 9a5ea73..d2a78aa 100644 --- a/test/dummy/Rakefile +++ b/test/dummy/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. diff --git a/test/dummy/app/channels/application_cable/channel.rb b/test/dummy/app/channels/application_cable/channel.rb index d672697..9aec230 100644 --- a/test/dummy/app/channels/application_cable/channel.rb +++ b/test/dummy/app/channels/application_cable/channel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/test/dummy/app/channels/application_cable/connection.rb b/test/dummy/app/channels/application_cable/connection.rb index 0ff5442..8d6c2a1 100644 --- a/test/dummy/app/channels/application_cable/connection.rb +++ b/test/dummy/app/channels/application_cable/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base end diff --git a/test/dummy/app/controllers/application_controller.rb b/test/dummy/app/controllers/application_controller.rb index 09705d1..7944f9f 100644 --- a/test/dummy/app/controllers/application_controller.rb +++ b/test/dummy/app/controllers/application_controller.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base end diff --git a/test/dummy/app/helpers/application_helper.rb b/test/dummy/app/helpers/application_helper.rb index de6be79..15b06f0 100644 --- a/test/dummy/app/helpers/application_helper.rb +++ b/test/dummy/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/test/dummy/app/jobs/application_job.rb b/test/dummy/app/jobs/application_job.rb index d394c3d..bef3959 100644 --- a/test/dummy/app/jobs/application_job.rb +++ b/test/dummy/app/jobs/application_job.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked diff --git a/test/dummy/app/mailers/application_mailer.rb b/test/dummy/app/mailers/application_mailer.rb index 3c34c81..5cc63a0 100644 --- a/test/dummy/app/mailers/application_mailer.rb +++ b/test/dummy/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: "from@example.com" layout "mailer" diff --git a/test/dummy/app/models/application_record.rb b/test/dummy/app/models/application_record.rb index b63caeb..08dc537 100644 --- a/test/dummy/app/models/application_record.rb +++ b/test/dummy/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base primary_abstract_class end diff --git a/test/dummy/bin/rails b/test/dummy/bin/rails index efc0377..22f2d8d 100755 --- a/test/dummy/bin/rails +++ b/test/dummy/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + APP_PATH = File.expand_path("../config/application", __dir__) require_relative "../config/boot" require "rails/commands" diff --git a/test/dummy/bin/rake b/test/dummy/bin/rake index 4fbf10b..e436ea5 100755 --- a/test/dummy/bin/rake +++ b/test/dummy/bin/rake @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require_relative "../config/boot" require "rake" Rake.application.run diff --git a/test/dummy/bin/setup b/test/dummy/bin/setup index ec47b79..25fe477 100755 --- a/test/dummy/bin/setup +++ b/test/dummy/bin/setup @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require "fileutils" # path to your application root. diff --git a/test/dummy/config.ru b/test/dummy/config.ru index 4a3c09a..2e03084 100644 --- a/test/dummy/config.ru +++ b/test/dummy/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require_relative "config/environment" diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 684353c..8fb82dc 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "boot" require "rails/all" diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb index 116591a..59459d4 100644 --- a/test/dummy/config/boot.rb +++ b/test/dummy/config/boot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Set up gems listed in the Gemfile. ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__) diff --git a/test/dummy/config/environment.rb b/test/dummy/config/environment.rb index cac5315..7df99e8 100644 --- a/test/dummy/config/environment.rb +++ b/test/dummy/config/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Load the Rails application. require_relative "application" diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index 8500f45..c8758ce 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/integer/time" Rails.application.configure do diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb index 8e989b5..d9e7b35 100644 --- a/test/dummy/config/environments/production.rb +++ b/test/dummy/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/integer/time" Rails.application.configure do diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index 6ea4d1e..28504a9 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/integer/time" # The test environment is used exclusively to run your application's diff --git a/test/dummy/config/initializers/assets.rb b/test/dummy/config/initializers/assets.rb index 2eeef96..101a290 100644 --- a/test/dummy/config/initializers/assets.rb +++ b/test/dummy/config/initializers/assets.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. diff --git a/test/dummy/config/initializers/content_security_policy.rb b/test/dummy/config/initializers/content_security_policy.rb index 54f47cf..691cfa1 100644 --- a/test/dummy/config/initializers/content_security_policy.rb +++ b/test/dummy/config/initializers/content_security_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Define an application-wide content security policy. diff --git a/test/dummy/config/initializers/filter_parameter_logging.rb b/test/dummy/config/initializers/filter_parameter_logging.rb index adc6568..ca55f95 100644 --- a/test/dummy/config/initializers/filter_parameter_logging.rb +++ b/test/dummy/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure parameters to be filtered from the log file. Use this to limit dissemination of diff --git a/test/dummy/config/initializers/inflections.rb b/test/dummy/config/initializers/inflections.rb index 3860f65..6c78420 100644 --- a/test/dummy/config/initializers/inflections.rb +++ b/test/dummy/config/initializers/inflections.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/test/dummy/config/initializers/permissions_policy.rb b/test/dummy/config/initializers/permissions_policy.rb index 00f64d7..50bcf4e 100644 --- a/test/dummy/config/initializers/permissions_policy.rb +++ b/test/dummy/config/initializers/permissions_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Define an application-wide HTTP permissions policy. For further # information see https://developers.google.com/web/updates/2018/06/feature-policy # diff --git a/test/dummy/config/puma.rb b/test/dummy/config/puma.rb index daaf036..ea3b550 100644 --- a/test/dummy/config/puma.rb +++ b/test/dummy/config/puma.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index b26e3b8..9fb4b63 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.routes.draw do mount SolidCache::Engine => "/solid_cache" end diff --git a/test/dummy/db/primary_shard_one_schema.rb b/test/dummy/db/primary_shard_one_schema.rb index 9a00cd4..8360029 100644 --- a/test/dummy/db/primary_shard_one_schema.rb +++ b/test/dummy/db/primary_shard_one_schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -17,5 +19,4 @@ t.datetime "created_at", null: false t.index ["key"], name: "index_solid_cache_entries_on_key", unique: true end - end diff --git a/test/dummy/db/primary_shard_two_schema.rb b/test/dummy/db/primary_shard_two_schema.rb index 9a00cd4..8360029 100644 --- a/test/dummy/db/primary_shard_two_schema.rb +++ b/test/dummy/db/primary_shard_two_schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -17,5 +19,4 @@ t.datetime "created_at", null: false t.index ["key"], name: "index_solid_cache_entries_on_key", unique: true end - end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 9a00cd4..8360029 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -17,5 +19,4 @@ t.datetime "created_at", null: false t.index ["key"], name: "index_solid_cache_entries_on_key", unique: true end - end diff --git a/test/dummy/db/secondary_shard_one_schema.rb b/test/dummy/db/secondary_shard_one_schema.rb index 9a00cd4..8360029 100644 --- a/test/dummy/db/secondary_shard_one_schema.rb +++ b/test/dummy/db/secondary_shard_one_schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -17,5 +19,4 @@ t.datetime "created_at", null: false t.index ["key"], name: "index_solid_cache_entries_on_key", unique: true end - end diff --git a/test/dummy/db/secondary_shard_two_schema.rb b/test/dummy/db/secondary_shard_two_schema.rb index 9a00cd4..8360029 100644 --- a/test/dummy/db/secondary_shard_two_schema.rb +++ b/test/dummy/db/secondary_shard_two_schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -17,5 +19,4 @@ t.datetime "created_at", null: false t.index ["key"], name: "index_solid_cache_entries_on_key", unique: true end - end diff --git a/test/fixtures/generators/dummy_app/config/environments/development.rb b/test/fixtures/generators/dummy_app/config/environments/development.rb index 8500f45..c8758ce 100644 --- a/test/fixtures/generators/dummy_app/config/environments/development.rb +++ b/test/fixtures/generators/dummy_app/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/integer/time" Rails.application.configure do diff --git a/test/fixtures/generators/dummy_app/config/environments/production.rb b/test/fixtures/generators/dummy_app/config/environments/production.rb index 7a93dfe..b758486 100644 --- a/test/fixtures/generators/dummy_app/config/environments/production.rb +++ b/test/fixtures/generators/dummy_app/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/integer/time" Rails.application.configure do diff --git a/test/fixtures/generators/dummy_app/config/environments/test.rb b/test/fixtures/generators/dummy_app/config/environments/test.rb index 6ea4d1e..28504a9 100644 --- a/test/fixtures/generators/dummy_app/config/environments/test.rb +++ b/test/fixtures/generators/dummy_app/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/integer/time" # The test environment is used exclusively to run your application's diff --git a/test/lib/generators/solid_cache/solid_cache/install_generator_test.rb b/test/lib/generators/solid_cache/solid_cache/install_generator_test.rb index 8dd62e2..2403745 100644 --- a/test/lib/generators/solid_cache/solid_cache/install_generator_test.rb +++ b/test/lib/generators/solid_cache/solid_cache/install_generator_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" require "generators/solid_cache/install/install_generator" diff --git a/test/models/solid_cache/entry_test.rb b/test/models/solid_cache/entry_test.rb index cf68c12..04dd942 100644 --- a/test/models/solid_cache/entry_test.rb +++ b/test/models/solid_cache/entry_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module SolidCache diff --git a/test/test_helper.rb b/test/test_helper.rb index 3ea3889..450146b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Configure Rails Environment ENV["RAILS_ENV"] = "test" diff --git a/test/unit/clear_test.rb b/test/unit/clear_test.rb index a548760..dec235f 100644 --- a/test/unit/clear_test.rb +++ b/test/unit/clear_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class DeleteMatchedTest < ActiveSupport::TestCase @@ -13,7 +15,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 @@ -23,7 +25,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 diff --git a/test/unit/cluster_test.rb b/test/unit/cluster_test.rb index bed89de..5b5989d 100644 --- a/test/unit/cluster_test.rb +++ b/test/unit/cluster_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class ClusterTest < ActiveSupport::TestCase diff --git a/test/unit/delete_matched_test.rb b/test/unit/delete_matched_test.rb index c055dd3..c920938 100644 --- a/test/unit/delete_matched_test.rb +++ b/test/unit/delete_matched_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class DeleteMatchedTest < ActiveSupport::TestCase diff --git a/test/unit/execution_test.rb b/test/unit/execution_test.rb index 76b408c..74d245e 100644 --- a/test/unit/execution_test.rb +++ b/test/unit/execution_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" require "active_support/testing/method_call_assertions" diff --git a/test/unit/expiry_test.rb b/test/unit/expiry_test.rb index f565dd0..71ccc3b 100644 --- a/test/unit/expiry_test.rb +++ b/test/unit/expiry_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" require "active_support/testing/method_call_assertions" diff --git a/test/unit/maglev_hash_test.rb b/test/unit/maglev_hash_test.rb index c276929..e20a633 100644 --- a/test/unit/maglev_hash_test.rb +++ b/test/unit/maglev_hash_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" require "active_support/testing/method_call_assertions" diff --git a/test/unit/query_cache_test.rb b/test/unit/query_cache_test.rb index bf00b92..7d5306a 100644 --- a/test/unit/query_cache_test.rb +++ b/test/unit/query_cache_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class QueryCacheTest < ActiveSupport::TestCase diff --git a/test/unit/solid_cache_test.rb b/test/unit/solid_cache_test.rb index 3346c4b..25f9c73 100644 --- a/test/unit/solid_cache_test.rb +++ b/test/unit/solid_cache_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" require_relative "behaviors" require "active_support/testing/method_call_assertions" diff --git a/test/unit/stats_test.rb b/test/unit/stats_test.rb index d2b6db5..da76a8d 100644 --- a/test/unit/stats_test.rb +++ b/test/unit/stats_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" require "active_support/testing/method_call_assertions"