Skip to content

Commit

Permalink
cleanup line length
Browse files Browse the repository at this point in the history
  • Loading branch information
rpbaltazar committed Jul 16, 2020
1 parent 5566b8f commit ff648f1
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 25 deletions.
7 changes: 0 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,3 @@ Style/IfUnlessModifier:
- 'Rakefile'
- 'lib/apartment.rb'
- 'lib/apartment/tenant.rb'

# Offense count: 12
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 171
2 changes: 0 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

# rubocop:disable Metrics/BlockLength
begin
require 'bundler'
rescue StandardError
Expand Down Expand Up @@ -118,7 +117,6 @@ namespace :mysql do
`mysqladmin #{params.join(' ')} drop #{my_config['database']} --force`
end
end
# rubocop:enable Metrics/BlockLength

# TODO: clean this up
def config
Expand Down
21 changes: 13 additions & 8 deletions lib/apartment/adapters/postgresql_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,17 @@ def reset_sequence_names
# There is `reset_sequence_name`, but that method actually goes to the database
# to find out the new name. Therefore, we do this hack to only unset the name,
# and it will be dynamically found the next time it is needed
ActiveRecord::Base.descendants
.select { |c| c.instance_variable_defined?(:@sequence_name) }
.reject { |c| c.instance_variable_defined?(:@explicit_sequence_name) && c.instance_variable_get(:@explicit_sequence_name) }
.each do |c|
# NOTE: due to this https://github.com/rails-on-services/apartment/issues/81
# unreproduceable error we're checking before trying to remove it
c.remove_instance_variable :@sequence_name if c.instance_variable_defined?(:@sequence_name)
end
descendants_to_unset = ActiveRecord::Base.descendants
.select { |c| c.instance_variable_defined?(:@sequence_name) }
.reject do |c|
c.instance_variable_defined?(:@explicit_sequence_name) &&
c.instance_variable_get(:@explicit_sequence_name)
end
descendants_to_unset.each do |c|
# NOTE: due to this https://github.com/rails-on-services/apartment/issues/81
# unreproduceable error we're checking before trying to remove it
c.remove_instance_variable :@sequence_name if c.instance_variable_defined?(:@sequence_name)
end
end
end

Expand Down Expand Up @@ -197,9 +200,11 @@ def pg_dump_schema
#
# @return {String} raw SQL contaning inserts with data from schema_migrations
#
# rubocop:disable Layout/LineLength
def pg_dump_schema_migrations_data
with_pg_env { `pg_dump -a --inserts -t #{default_tenant}.schema_migrations -t #{default_tenant}.ar_internal_metadata #{dbname}` }
end
# rubocop:enable Layout/LineLength

# Temporary set Postgresql related environment variables if there are in @config
#
Expand Down
2 changes: 2 additions & 0 deletions lib/apartment/custom_console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module CustomConsole
begin
require 'pry-rails'
rescue LoadError
# rubocop:disable Layout/LineLength
puts '[Failed to load pry-rails] If you want to use Apartment custom prompt you need to add pry-rails to your gemfile'
# rubocop:enable Layout/LineLength
end

desc = "Includes the current Rails environment and project folder name.\n" \
Expand Down
3 changes: 2 additions & 1 deletion lib/generators/apartment/install/templates/apartment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
# You can make this dynamic by providing a Proc object to be called on migrations.
# This object should yield either:
# - an array of strings representing each Tenant name.
# - a hash which keys are tenant names, and values custom db config (must contain all key/values required in database.yml)
# - a hash which keys are tenant names, and values custom db config
# (must contain all key/values required in database.yml)
#
# config.tenant_names = lambda{ Customer.pluck(:tenant_name) }
# config.tenant_names = ['tenant1', 'tenant2']
Expand Down
4 changes: 3 additions & 1 deletion spec/adapters/jdbc_mysql_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
subject { Apartment::Tenant.jdbc_mysql_adapter config.symbolize_keys }

def tenant_names
ActiveRecord::Base.connection.execute('SELECT schema_name FROM information_schema.schemata').collect { |row| row['schema_name'] }
ActiveRecord::Base.connection.execute('SELECT schema_name FROM information_schema.schemata').collect do |row|
row['schema_name']
end
end

let(:default_tenant) { subject.switch { ActiveRecord::Base.connection.current_database } }
Expand Down
4 changes: 3 additions & 1 deletion spec/adapters/mysql2_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
subject(:adapter) { Apartment::Tenant.mysql2_adapter config }

def tenant_names
ActiveRecord::Base.connection.execute('SELECT schema_name FROM information_schema.schemata').collect { |row| row[0] }
ActiveRecord::Base.connection.execute('SELECT schema_name FROM information_schema.schemata').collect do |row|
row[0]
end
end

let(:default_tenant) { subject.switch { ActiveRecord::Base.connection.current_database } }
Expand Down
3 changes: 3 additions & 0 deletions spec/dummy/config/initializers/secret_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.

# rubocop:disable Layout/LineLength
Dummy::Application.config.secret_token = '7d33999a86884f74c897c98ecca4277090b69e9f23df8d74bcadd57435320a7a16de67966f9b69d62e7d5ec553bd2febbe64c721e05bc1bc1e82c7a7d2395201'
# rubocop:enable Layout/LineLength
3 changes: 2 additions & 1 deletion spec/dummy/script/rails
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
# This command will automatically be run when you run "rails" with Rails 3 gems installed
# from the root of your application.

APP_PATH = File.expand_path('../config/application', __dir__)
require File.expand_path('../config/boot', __dir__)
Expand Down
3 changes: 2 additions & 1 deletion spec/dummy_engine/bin/rails
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
# This command will automatically be run when you run "rails" with Rails 4 gems installed
# from the root of your application.

ENGINE_ROOT = File.expand_path('..', __dir__)
ENGINE_PATH = File.expand_path('../lib/dummy_engine/engine', __dir__)
Expand Down
3 changes: 2 additions & 1 deletion spec/dummy_engine/config/initializers/apartment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
# supply list of database names for migrations to run on
# config.tenant_names = lambda{ ToDo_Tenant_Or_User_Model.pluck :database }

# Specify a connection other than ActiveRecord::Base for apartment to use (only needed if your models are using a different connection)
# Specify a connection other than ActiveRecord::Base for apartment to use
# (only needed if your models are using a different connection)
# config.connection_class = ActiveRecord::Base
end

Expand Down
8 changes: 6 additions & 2 deletions spec/examples/generic_adapter_custom_configuration_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

describe '#create' do
it 'should establish_connection with the separate connection with expected args' do
expect(Apartment::Adapters::AbstractAdapter::SeparateDbConnectionHandler).to receive(:establish_connection).with(expected_args).and_call_original
expect(Apartment::Adapters::AbstractAdapter::SeparateDbConnectionHandler).to(
receive(:establish_connection).with(expected_args).and_call_original
)

# because we dont have another server to connect to it errors
# what matters is establish_connection receives proper args
Expand All @@ -35,7 +37,9 @@

describe '#drop' do
it 'should establish_connection with the separate connection with expected args' do
expect(Apartment::Adapters::AbstractAdapter::SeparateDbConnectionHandler).to receive(:establish_connection).with(expected_args).and_call_original
expect(Apartment::Adapters::AbstractAdapter::SeparateDbConnectionHandler).to(
receive(:establish_connection).with(expected_args).and_call_original
)

# because we dont have another server to connect to it errors
# what matters is establish_connection receives proper args
Expand Down

0 comments on commit ff648f1

Please sign in to comment.