From 4c573579c91bace15b9d1cf83ac31e95606672c1 Mon Sep 17 00:00:00 2001 From: Stanislav Katkov Date: Mon, 9 Oct 2023 23:11:12 +0200 Subject: [PATCH] fmt --- .../solid_cache/install/install_generator.rb | 16 ++++++++-------- .../create_solid_cache_entries_btree.rb | 5 ++--- .../templates/create_solid_cache_entries_hash.rb | 5 ++--- lib/solid_cache/store/api.rb | 2 +- lib/tasks/solid_cache_tasks.rake | 6 +++--- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/generators/solid_cache/install/install_generator.rb b/lib/generators/solid_cache/install/install_generator.rb index f04b676..99bc312 100644 --- a/lib/generators/solid_cache/install/install_generator.rb +++ b/lib/generators/solid_cache/install/install_generator.rb @@ -1,11 +1,11 @@ -require 'rails/generators/active_record' +require "rails/generators/active_record" class SolidCache::InstallGenerator < Rails::Generators::Base include ActiveRecord::Generators::Migration - + source_root File.expand_path("templates", __dir__) class_option :skip_migrations, type: :boolean, default: nil, desc: "Skip migrations" - class_option :index, type: :string, default: 'btree', desc: "Index type for key column" + class_option :index, type: :string, default: "btree", desc: "Index type for key column" def add_rails_cache %w[development test production].each do |env_name| @@ -17,12 +17,12 @@ def add_rails_cache def create_migrations return if options[:skip_migrations] - + case options[:index] - when 'btree' - migration_template 'create_solid_cache_entries_btree.rb', 'db/migrate/create_solid_cache_entries.rb' - when 'hash' - migration_template 'create_solid_cache_entries_hash.rb', 'db/migrate/create_solid_cache_entries.rb' + when "btree" + migration_template "create_solid_cache_entries_btree.rb", "db/migrate/create_solid_cache_entries.rb" + when "hash" + migration_template "create_solid_cache_entries_hash.rb", "db/migrate/create_solid_cache_entries.rb" end end end diff --git a/lib/generators/solid_cache/install/templates/create_solid_cache_entries_btree.rb b/lib/generators/solid_cache/install/templates/create_solid_cache_entries_btree.rb index 2b7128d..39be9f5 100644 --- a/lib/generators/solid_cache/install/templates/create_solid_cache_entries_btree.rb +++ b/lib/generators/solid_cache/install/templates/create_solid_cache_entries_btree.rb @@ -4,9 +4,8 @@ def change t.binary :key, null: false, limit: 1024 t.binary :value, null: false, limit: 512.megabytes t.datetime :created_at, null: false - + t.index :key, unique: true end end - end - \ No newline at end of file +end diff --git a/lib/generators/solid_cache/install/templates/create_solid_cache_entries_hash.rb b/lib/generators/solid_cache/install/templates/create_solid_cache_entries_hash.rb index 540190e..d87e1af 100644 --- a/lib/generators/solid_cache/install/templates/create_solid_cache_entries_hash.rb +++ b/lib/generators/solid_cache/install/templates/create_solid_cache_entries_hash.rb @@ -4,9 +4,8 @@ def change t.binary :key, null: false, limit: 1024 t.binary :value, null: false, limit: 512.megabytes t.datetime :created_at, null: false - + t.index :key, unique: true, using: :hash end end - end - \ No newline at end of file +end diff --git a/lib/solid_cache/store/api.rb b/lib/solid_cache/store/api.rb index 95e8e76..acab50f 100644 --- a/lib/solid_cache/store/api.rb +++ b/lib/solid_cache/store/api.rb @@ -51,7 +51,7 @@ def clear(options = nil) private def primary_key_using_hash_index? - ActiveRecord::Base.connection.indexes(:activesupport_cache_entries).first {|i| i.columns.first == 'key'}.using == :hash + ActiveRecord::Base.connection.indexes(:activesupport_cache_entries).first { |i| i.columns.first == "key" }.using == :hash end def read_entry(key, **options) diff --git a/lib/tasks/solid_cache_tasks.rake b/lib/tasks/solid_cache_tasks.rake index 140e41a..c97a6f2 100644 --- a/lib/tasks/solid_cache_tasks.rake +++ b/lib/tasks/solid_cache_tasks.rake @@ -1,9 +1,9 @@ desc "Copy over the migration, and set cache" namespace :solid_cache do - task :install, [:index] do |_t, args| - args.with_defaults(index: 'btree') + task :install, [ :index ] do |_t, args| + args.with_defaults(index: "btree") - if args[:index] == 'btree' || args[:index] == 'hash' + if args[:index] == "btree" || args[:index] == "hash" Rails::Command.invoke :generate, [ "solid_cache:install", "--index=#{args[:index]}" ] else abort "Invalid index type - only 'btree' and 'hash' are supported."