Skip to content

Commit f1f043d

Browse files
authored
Fix rubocop warnings (citusdata#215)
Enable more
1 parent de48c9f commit f1f043d

22 files changed

+75
-28
lines changed

.rubocop.yml

+13-5
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,29 @@ AllCops:
77
- 'node_modules/**/*'
88
- 'Vagrantfile'
99
TargetRubyVersion: 3.0
10+
SuggestExtensions: false
11+
NewCops: enable
1012

11-
Style/FrozenStringLiteralComment:
13+
Gemspec/DevelopmentDependencies:
1214
Enabled: false
1315

14-
Style/Documentation:
15-
Exclude:
16-
- '**/*.rb'
16+
Lint/ConstantDefinitionInBlock:
1717
Enabled: false
1818

19-
Lint/ConstantDefinitionInBlock:
19+
Lint/EmptyBlock:
2020
Enabled: false
2121

2222
Style/ClassAndModuleChildren:
2323
Enabled: false
2424

25+
Style/Documentation:
26+
Exclude:
27+
- '**/*.rb'
28+
Enabled: false
29+
30+
Style/DocumentDynamicEvalDefinition:
31+
Enabled: false
32+
2533
Metrics/BlockLength:
2634
Max: 650
2735

Appraisals

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
appraise 'rails-6.0' do
24
gem 'rails', '~> 6.0.3'
35
end

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
gemspec

Rakefile

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'rubygems'
24
require 'bundler/setup'
35
require 'bundler/gem_tasks'

activerecord-multi-tenant.gemspec

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
# frozen_string_literal: true
2+
13
$LOAD_PATH.push File.expand_path('lib', __dir__)
24
require 'activerecord-multi-tenant/version'
35

46
Gem::Specification.new do |spec|
57
spec.name = 'activerecord-multi-tenant'
68
spec.version = MultiTenant::VERSION
7-
spec.summary = 'ActiveRecord/Rails integration for multi-tenant databases, '\
8-
'in particular the Citus extension for PostgreSQL'
9+
spec.summary = 'ActiveRecord/Rails integration for multi-tenant databases, ' \
10+
'in particular the Citus extension for PostgreSQL'
911
spec.description = ''
1012
spec.authors = ['Citus Data']
1113
spec.email = '[email protected]'
1214
spec.required_ruby_version = '>= 3.0.0'
15+
spec.metadata = { 'rubygems_mfa_required' => 'true' }
1316

1417
spec.files = `git ls-files`.split("\n")
15-
spec.test_files = `git ls-files -- {spec}/*`.split("\n")
1618
spec.require_paths = ['lib']
1719
spec.homepage = 'https://github.com/citusdata/activerecord-multi-tenant'
1820
spec.license = 'MIT'

lib/activerecord-multi-tenant/copy_from_client.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module MultiTenant
24
# Designed to be mixed into an ActiveRecord model to provide
35
# a copy_from_client method that allows for efficient bulk insertion of

lib/activerecord-multi-tenant/fast_truncate.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Truncates only the tables that have been modified, according to sequence
24
# values
35
# Faster alternative to DatabaseCleaner.clean_with(:truncation, pre_count: true)

lib/activerecord-multi-tenant/habtm.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ def has_and_belongs_to_many_with_tenant(name, scope = nil, **options, &extension
3434

3535
# This method sets the tenant_id on the join table and executes before creation of the join table record.
3636
define_method :tenant_set do
37-
if tenant_enabled
38-
raise MultiTenant::MissingTenantError, 'Tenant Id is not set' unless MultiTenant.current_tenant_id
37+
return unless tenant_enabled
38+
raise MultiTenant::MissingTenantError, 'Tenant Id is not set' unless MultiTenant.current_tenant_id
3939

40-
send("#{tenant_column}=", MultiTenant.current_tenant_id)
41-
end
40+
send("#{tenant_column}=", MultiTenant.current_tenant_id)
4241
end
4342
end
4443
end

lib/activerecord-multi-tenant/migrations.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module MultiTenant
24
module MigrationExtensions
35
def create_distributed_table(table_name, partition_key)

lib/activerecord-multi-tenant/model_extensions.rb

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
require_relative './multi_tenant'
1+
# frozen_string_literal: true
2+
3+
require_relative 'multi_tenant'
24

35
module MultiTenant
46
# Extension to the model to allow scoping of models to the current tenant. This is done by adding
57
# the multitenant method to the models that need to be scoped. This method is called in the
68
# model declaration.
79
# Adds scoped_by_tenant? partition_key, primary_key and inherited methods to the model
810
module ModelExtensionsClassMethods
9-
DEFAULT_ID_FIELD = 'id'.freeze
11+
DEFAULT_ID_FIELD = 'id'
1012
# executes when multi_tenant method is called in the model. This method adds the following
1113
# methods to the model that calls it.
1214
# scoped_by_tenant? - returns true if the model is scoped by tenant
@@ -188,17 +190,21 @@ def inherited(subclass)
188190
end
189191

190192
# skips statement caching for classes that is Multi-tenant or has a multi-tenant relation
191-
class ActiveRecord::Associations::Association
192-
alias skip_statement_cache_orig skip_statement_cache?
193+
module ActiveRecord
194+
module Associations
195+
class Association
196+
alias skip_statement_cache_orig skip_statement_cache?
193197

194-
def skip_statement_cache?(*scope)
195-
return true if klass.respond_to?(:scoped_by_tenant?) && klass.scoped_by_tenant?
198+
def skip_statement_cache?(*scope)
199+
return true if klass.respond_to?(:scoped_by_tenant?) && klass.scoped_by_tenant?
196200

197-
if reflection.through_reflection
198-
through_klass = reflection.through_reflection.klass
199-
return true if through_klass.respond_to?(:scoped_by_tenant?) && through_klass.scoped_by_tenant?
200-
end
201+
if reflection.through_reflection
202+
through_klass = reflection.through_reflection.klass
203+
return true if through_klass.respond_to?(:scoped_by_tenant?) && through_klass.scoped_by_tenant?
204+
end
201205

202-
skip_statement_cache_orig(*scope)
206+
skip_statement_cache_orig(*scope)
207+
end
208+
end
203209
end
204210
end

lib/activerecord-multi-tenant/multi_tenant.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'active_support/current_attributes'
24

35
module MultiTenant

lib/activerecord-multi-tenant/query_monitor.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Add generic warning when queries fail and there is no tenant set
24
# To handle this case, a QueryMonitor hook is created and registered
35
# to sql.active_record. This hook will log a warning when a query fails

lib/activerecord-multi-tenant/query_rewriter.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
# frozen_string_literal: true
2+
13
require 'active_record'
2-
require_relative './arel_visitors_depth_first' unless Arel::Visitors.const_defined?(:DepthFirst)
4+
require_relative 'arel_visitors_depth_first' unless Arel::Visitors.const_defined?(:DepthFirst)
35

46
# Iterates AST and adds tenant enforcement clauses to all relations
57
module MultiTenant

lib/activerecord-multi-tenant/sidekiq.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'sidekiq/client'
24

35
# Adds methods to handle tenant information both in the client and server.

lib/activerecord-multi-tenant/table_node.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module MultiTenant
24
module TableNode
35
# Return table name
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module MultiTenant
2-
VERSION = '2.4.0'.freeze
4+
VERSION = '2.4.0'
35
end

spec/activerecord-multi-tenant/associations_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'spec_helper'
24

35
describe MultiTenant, 'Association methods' do

spec/activerecord-multi-tenant/multi_tenant_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
RSpec.describe MultiTenant do
66
describe '.load_current_tenant!' do
7-
let(:fake_tenant) { OpenStruct.new(id: 1) }
7+
let(:fake_tenant) { double(id: 1) }
88
let(:mock_klass) { double(find: fake_tenant) }
99

1010
before do

spec/activerecord-multi-tenant/record_callback_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'spec_helper'
24

35
class ProjectWithCallbacks < ActiveRecord::Base

spec/activerecord-multi-tenant/record_finding_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'spec_helper'
24

35
describe MultiTenant, 'Record finding' do

spec/activerecord-multi-tenant/sidekiq_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'spec_helper'
24
require 'sidekiq/client'
35
require 'activerecord-multi-tenant/sidekiq'

spec/spec_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ class Application < Rails::Application; end
4848

4949
require 'bundler'
5050
Bundler.require(:default, :development)
51-
require_relative './support/format_sql'
51+
require_relative 'support/format_sql'
5252

53-
dbconfig = YAML.safe_load(IO.read(File.join(File.dirname(__FILE__), 'database.yml')))
53+
dbconfig = YAML.safe_load_file(File.join(File.dirname(__FILE__), 'database.yml'))
5454
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), 'debug.log'))
5555
ActiveRecord::Base.establish_connection(dbconfig['test'])
5656

0 commit comments

Comments
 (0)