Skip to content

Commit 2cbc5b9

Browse files
committed
Rubocop: Enable Layout/* cops
1 parent 2999d07 commit 2cbc5b9

28 files changed

+128
-84
lines changed

activerecord-sqlserver-adapter.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Gem::Specification.new do |spec|
1717
spec.description = "ActiveRecord SQL Server Adapter. SQL Server 2012 and upward."
1818

1919
spec.metadata = {
20-
"bug_tracker_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues",
21-
"changelog_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v#{version}/CHANGELOG.md",
22-
"source_code_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v#{version}",
20+
"bug_tracker_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues",
21+
"changelog_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v#{version}/CHANGELOG.md",
22+
"source_code_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v#{version}",
2323
}
2424

2525
spec.files = `git ls-files -z`.split("\x0")

lib/active_record/connection_adapters/sqlserver/database_statements.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,14 @@ def with_identity_insert_enabled(table_name)
186186

187187
def use_database(database = nil)
188188
return if sqlserver_azure?
189+
189190
name = SQLServer::Utils.extract_identifiers(database || @connection_options[:database]).quoted
190191
do_execute "USE #{name}" unless name.blank?
191192
end
192193

193194
def user_options
194195
return {} if sqlserver_azure?
196+
195197
rows = select_rows("DBCC USEROPTIONS WITH NO_INFOMSGS", "SCHEMA")
196198
rows = rows.first if rows.size == 2 && rows.last.empty?
197199
rows.reduce(HashWithIndifferentAccess.new) do |values, row|
@@ -315,6 +317,7 @@ def sp_executesql_types_and_parameters(binds)
315317

316318
def sp_executesql_sql_type(attr)
317319
return attr.type.sqlserver_type if attr.type.respond_to?(:sqlserver_type)
320+
318321
case value = attr.value_for_database
319322
when Numeric
320323
value > 2_147_483_647 ? "bigint".freeze : "int".freeze
@@ -376,8 +379,10 @@ def exclude_output_inserted_table_names?
376379

377380
def exclude_output_inserted_table_name?(table_name, sql)
378381
return false unless exclude_output_inserted_table_names?
382+
379383
table_name ||= get_table_name(sql)
380384
return false unless table_name
385+
381386
self.class.exclude_output_inserted_table_names[table_name]
382387
end
383388

lib/active_record/connection_adapters/sqlserver/database_tasks.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,3 @@ def create_database_edition_options(options = {})
6363
end
6464
end
6565
end
66-
67-
68-

lib/active_record/connection_adapters/sqlserver/quoting.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def quoted_date(value)
6565
if value.acts_like?(:date)
6666
Type::Date.new.serialize(value)
6767
else value.acts_like?(:time)
68-
Type::DateTime.new.serialize(value)
68+
Type::DateTime.new.serialize(value)
6969
end
7070
end
7171

lib/active_record/connection_adapters/sqlserver/schema_dumper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ def explicit_primary_key_default?(column)
2020

2121
def schema_limit(column)
2222
return if SQLSEVER_NO_LIMIT_TYPES.include?(column.sql_type)
23+
2324
super
2425
end
2526

2627
def schema_collation(column)
2728
return unless column.collation
29+
2830
column.collation if column.collation != @connection.collation
2931
end
3032

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def indexes(table_name)
6666

6767
def columns(table_name)
6868
return [] if table_name.blank?
69+
6970
column_definitions(table_name).map do |ci|
7071
sqlserver_options = ci.slice :ordinal_position, :is_primary, :is_identity, :table_name
7172
sql_type_metadata = fetch_type_metadata ci[:type], sqlserver_options
@@ -131,6 +132,7 @@ def rename_table(table_name, new_name)
131132

132133
def remove_column(table_name, column_name, type = nil, options = {})
133134
raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_name.is_a? Array
135+
134136
remove_check_constraints(table_name, column_name)
135137
remove_default_constraint(table_name, column_name)
136138
remove_indexes(table_name, column_name)
@@ -144,9 +146,9 @@ def change_column(table_name, column_name, type, options = {})
144146
without_constraints = options.key?(:default) || options.key?(:limit)
145147
default = if !options.key?(:default) && column_object
146148
column_object.default
147-
else
148-
options[:default]
149-
end
149+
else
150+
options[:default]
151+
end
150152
if without_constraints || (column_object && column_object.type != type.to_sym)
151153
remove_default_constraint(table_name, column_name)
152154
indexes = indexes(table_name).select { |index| index.columns.include?(column_name.to_s) }
@@ -172,6 +174,7 @@ def change_column_default(table_name, column_name, default_or_changes)
172174
clear_cache!
173175
column = column_for(table_name, column_name)
174176
return unless column
177+
175178
remove_default_constraint(table_name, column_name)
176179
default = extract_new_default_value(default_or_changes)
177180
do_execute "ALTER TABLE #{quote_table_name(table_name)} ADD CONSTRAINT #{default_constraint_name(table_name, column_name)} DEFAULT #{quote_default_expression(default, column)} FOR #{quote_column_name(column_name)}"
@@ -188,6 +191,7 @@ def rename_column(table_name, column_name, new_column_name)
188191

189192
def rename_index(table_name, old_name, new_name)
190193
raise ArgumentError, "Index name '#{new_name}' on table '#{table_name}' is too long; the limit is #{allowed_index_name_length} characters" if new_name.length > allowed_index_name_length
194+
191195
identifier = SQLServer::Utils.extract_identifiers("#{table_name}.#{old_name}")
192196
execute_procedure :sp_rename, identifier.quoted, new_name, "INDEX"
193197
end
@@ -249,10 +253,10 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, **)
249253

250254
def columns_for_distinct(columns, orders)
251255
order_columns = orders.reject(&:blank?).map { |s|
252-
s = s.to_sql unless s.is_a?(String)
253-
s.gsub(/\s+(?:ASC|DESC)\b/i, "")
254-
.gsub(/\s+NULLS\s+(?:FIRST|LAST)\b/i, "")
255-
}.reject(&:blank?).map.with_index { |column, i| "#{column} AS alias_#{i}" }
256+
s = s.to_sql unless s.is_a?(String)
257+
s.gsub(/\s+(?:ASC|DESC)\b/i, "")
258+
.gsub(/\s+NULLS\s+(?:FIRST|LAST)\b/i, "")
259+
}.reject(&:blank?).map.with_index { |column, i| "#{column} AS alias_#{i}" }
256260

257261
(order_columns << super).join(", ")
258262
end
@@ -507,11 +511,11 @@ def remove_indexes(table_name, column_name)
507511
def get_table_name(sql)
508512
tn = if sql =~ /^\s*(INSERT|EXEC sp_executesql N'INSERT)(\s+INTO)?\s+([^\(\s]+)\s*|^\s*update\s+([^\(\s]+)\s*/i
509513
Regexp.last_match[3] || Regexp.last_match[4]
510-
elsif sql =~ /FROM\s+([^\(\s]+)\s*/i
511-
Regexp.last_match[1]
512-
else
513-
nil
514-
end
514+
elsif sql =~ /FROM\s+([^\(\s]+)\s*/i
515+
Regexp.last_match[1]
516+
else
517+
nil
518+
end
515519
SQLServer::Utils.extract_identifiers(tn).object
516520
end
517521

@@ -540,9 +544,9 @@ def view_information(table_name)
540544
if view_info[:VIEW_DEFINITION].blank? || view_info[:VIEW_DEFINITION].length == 4000
541545
view_info[:VIEW_DEFINITION] = begin
542546
select_values("EXEC sp_helptext #{identifier.object_quoted}", "SCHEMA").join
543-
rescue
544-
warn "No view definition found, possible permissions problem.\nPlease run GRANT VIEW DEFINITION TO your_user;"
545-
nil
547+
rescue
548+
warn "No view definition found, possible permissions problem.\nPlease run GRANT VIEW DEFINITION TO your_user;"
549+
nil
546550
end
547551
end
548552
end
@@ -553,6 +557,7 @@ def view_information(table_name)
553557
def views_real_column_name(table_name, column_name)
554558
view_definition = view_information(table_name)[:VIEW_DEFINITION]
555559
return column_name unless view_definition
560+
556561
match_data = view_definition.match(/([\w-]*)\s+as\s+#{column_name}/im)
557562
match_data ? match_data[1] : column_name
558563
end

lib/active_record/connection_adapters/sqlserver/transaction.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def sqlserver?
1313

1414
def current_isolation_level
1515
return unless sqlserver?
16+
1617
level = connection.user_options_isolation_level
1718
# When READ_COMMITTED_SNAPSHOT is set to ON,
1819
# user_options_isolation_level will be equal to 'read committed

lib/active_record/connection_adapters/sqlserver/type/char.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def type
1212
def serialize(value)
1313
return if value.nil?
1414
return value if value.is_a?(Data)
15+
1516
Data.new super, self
1617
end
1718

@@ -24,6 +25,7 @@ def sqlserver_type
2425

2526
def quoted(value)
2627
return value.quoted_id if value.respond_to?(:quoted_id)
28+
2729
Utils.quote_string_single(value)
2830
end
2931
end

lib/active_record/connection_adapters/sqlserver/type/date.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def sqlserver_type
1111

1212
def serialize(value)
1313
return unless value.present?
14+
1415
date = super(value).to_s(:_sqlserver_dateformat)
1516
Data.new date, self
1617
end

lib/active_record/connection_adapters/sqlserver/type/time.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def quoted(value)
3737
def cast_value(value)
3838
value = super
3939
return if value.blank?
40+
4041
value = value.change year: 2000, month: 01, day: 01
4142
apply_seconds_precision(value)
4243
end

0 commit comments

Comments
 (0)