Skip to content

Commit 58dea08

Browse files
author
Anna Carey
committed
Added rubocop gem and fixed style, no functional changes
removed trailing whitespace and fixed other whitespace issues convert 1.8 hash syntax change double to single quotes where possible style changes such as preferring map over collect
1 parent 5a32bdc commit 58dea08

File tree

70 files changed

+1031
-1089
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1031
-1089
lines changed

.rubocop.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
AllCops:
2+
Exclude:
3+
- doc/**/*
4+
- test/**/*
5+
LineLength:
6+
Max: 200
7+
Documentation:
8+
Enabled: false
9+
MethodLength:
10+
Enabled: false
11+
12+
# TODO: enable after the more important stuff is fixed
13+
LineLength:
14+
Enabled: false
15+
CyclomaticComplexity:
16+
Enabled: false
17+
SignalException:
18+
Enabled: false
19+
MethodName:
20+
Enabled: false

Gemfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source 'https://rubygems.org'
33

44
if ENV['RAILS_SOURCE']
5-
gemspec :path => ENV['RAILS_SOURCE']
5+
gemspec path: ENV['RAILS_SOURCE']
66
else
77
# Need to get rails source beacause the gem doesn't include tests
88
version = ENV['RAILS_VERSION'] || begin
@@ -17,19 +17,19 @@ else
1717
!data['prerelease'] && major == a && (minor.nil? || minor == b)
1818
end.first['number']
1919
end
20-
gem 'rails', :git => "git://github.com/rails/rails.git", :tag => "v#{version}"
20+
gem 'rails', git: "git://github.com/rails/rails.git", tag: "v#{version}"
2121
end
2222

2323
if ENV['AREL']
24-
gem 'arel', :path => ENV['AREL']
24+
gem 'arel', path: ENV['AREL']
2525
end
2626

2727
group :tinytds do
2828
if ENV['TINYTDS_SOURCE']
29-
gem 'tiny_tds', :path => ENV['TINYTDS_SOURCE']
29+
gem 'tiny_tds', path: ENV['TINYTDS_SOURCE']
3030
else
3131
# TODO: [Rails4] Change back... segfault caused by tiny_tds 0.6.1
32-
gem 'tiny_tds', :git =>"https://github.com/rails-sqlserver/tiny_tds.git"
32+
gem 'tiny_tds', git:"https://github.com/rails-sqlserver/tiny_tds.git"
3333
end
3434
end
3535

@@ -44,8 +44,8 @@ group :development do
4444
gem 'minitest-spec-rails'
4545
gem 'nokogiri'
4646
gem 'rake', '~> 0.9.2'
47+
gem 'rubocop'
4748
gem 'ruby-prof'
4849
gem 'simplecov'
4950
gem 'ruby-graphviz'
5051
end
51-

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Every class that sub classes ActiveRecord::Base will now have an execute_procedu
3636
```ruby
3737
Account.execute_procedure :update_totals, 'admin', nil, true
3838
# Or with named parameters.
39-
Account.execute_procedure :update_totals, :named => 'params'
39+
Account.execute_procedure :update_totals, named: 'params'
4040
```
4141

4242
#### Native Data Type Support
@@ -53,9 +53,9 @@ Currently the following custom data types have been tested for schema definition
5353
For example:
5454

5555
```ruby
56-
create_table :sql_server_custom_types, :force => true do |t|
57-
t.column :ten_code, :char, :limit => 10
58-
t.column :ten_code_utf8, :nchar, :limit => 10
56+
create_table :sql_server_custom_types, force: true do |t|
57+
t.column :ten_code, :char, limit: 10
58+
t.column :ten_code_utf8, :nchar, limit: 10
5959
t.column :title_utf8, :nvarchar
6060
t.column :body, :varchar_max # Creates varchar(max)
6161
t.column :body_utf8, :ntext
@@ -159,7 +159,7 @@ end
159159
The 3.2 version of the adapter support ActiveRecord's explain features. In SQL Server, this is called the showplan. By default we use the `SHOWPLAN_ALL` option and format it using a simple table printer. So the following ruby would log the plan table below it.
160160

161161
```ruby
162-
Car.where(:id => 1).explain
162+
Car.where(id: 1).explain
163163
```
164164

165165
```

Rakefile

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ AREL_PATH = Gem.loaded_specs['arel'].full_gem_path
66
# Notes for cross compile:
77
# $ gcla ; bundle install ; rake compile ; rake cross compile ; rake cross native gem
88

9-
def test_libs(mode='dblib')
9+
def test_libs
1010
['lib',
1111
'test',
12-
"#{File.join(AR_PATH,'test')}",
13-
"#{File.join(AREL_PATH,'test')}",
12+
"#{File.join(AR_PATH, 'test')}",
13+
"#{File.join(AREL_PATH, 'test')}"
1414
]
1515
end
1616

1717
# bundle exec rake test SQLSERVER_ONLY=true
18-
#
18+
#
1919
# If you have trouble running single tests (errors about requirements):
2020
# http://veganswithtypewriters.net/blog/2013/06/29/weirdness-with-rake-solved/
2121
def test_files
22-
test_setup = ["test/cases/sqlserver_helper.rb"]
22+
test_setup = ['test/cases/sqlserver_helper.rb']
2323

2424
return test_setup + (ENV['TEST_FILES']).split(',') if ENV['TEST_FILES']
25-
26-
sqlserver_cases = Dir.glob("test/cases/**/*_test_sqlserver.rb")
27-
25+
26+
sqlserver_cases = Dir.glob('test/cases/**/*_test_sqlserver.rb')
27+
2828
ar_cases = Dir.glob("#{AR_PATH}/test/cases/**/*_test.rb")
2929
adapter_cases = Dir.glob("#{AR_PATH}/test/cases/adapters/**/*_test.rb")
3030

@@ -39,57 +39,54 @@ def test_files
3939
else
4040
test_setup + arel_cases + sqlserver_cases + (ar_cases - adapter_cases)
4141
end
42-
4342
end
4443

45-
task :test => ['test:dblib']
46-
task :default => [:test]
47-
44+
task test: ['test:dblib']
45+
task default: [:test]
4846

4947
namespace :test do
50-
51-
['dblib','odbc'].each do |mode|
52-
48+
49+
%w(dblib odbc).each do |mode|
50+
5351
Rake::TestTask.new(mode) do |t|
54-
t.libs = test_libs(mode)
52+
t.libs = test_libs
5553
t.test_files = test_files
5654
t.verbose = true
5755
end
58-
56+
5957
end
60-
58+
6159
task 'dblib:env' do
6260
ENV['ARCONN'] = 'dblib'
6361
end
64-
65-
task 'odbc:env' do
62+
63+
task 'odbc:env' do
6664
ENV['ARCONN'] = 'odbc'
6765
end
68-
66+
6967
end
7068

7169
task 'test:dblib' => 'test:dblib:env'
7270
task 'test:odbc' => 'test:odbc:env'
7371

7472

7573
namespace :profile do
76-
77-
['dblib','odbc'].each do |mode|
74+
%w(dblib odbc).each do |mode|
7875
namespace mode.to_sym do
79-
80-
Dir.glob("test/profile/*_profile_case.rb").sort.each do |test_file|
81-
82-
profile_case = File.basename(test_file).sub('_profile_case.rb','')
83-
76+
77+
Dir.glob('test/profile/*_profile_case.rb').sort.each do |test_file|
78+
79+
profile_case = File.basename(test_file).sub('_profile_case.rb', '')
80+
8481
Rake::TestTask.new(profile_case) do |t|
85-
t.libs = test_libs(mode)
82+
t.libs = test_libs
8683
t.test_files = [test_file]
8784
t.verbose = true
8885
end
89-
86+
9087
end
91-
88+
9289
end
9390
end
94-
91+
9592
end
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
$:.push File.expand_path("../lib", __FILE__)
1+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
22

33
Gem::Specification.new do |s|
44
s.platform = Gem::Platform::RUBY
5-
s.name = "activerecord-sqlserver-adapter"
6-
s.version = File.read(File.expand_path("../VERSION",__FILE__)).strip
7-
s.summary = "ActiveRecord SQL Server Adapter. For SQL Server 2005 And Higher."
8-
s.description = "ActiveRecord SQL Server Adapter. For SQL Server 2005 And Higher."
9-
10-
s.authors = ['Ken Collins', 'Murray Steele', 'Shawn Balestracci', 'Joe Rafaniello', 'Tom Ward']
11-
s.email = "ken@metaskills.net"
12-
s.homepage = "http://github.com/rails-sqlserver/activerecord-sqlserver-adapter"
13-
14-
s.files = Dir['CHANGELOG', 'MIT-LICENSE', 'README.rdoc', 'VERSION', 'lib/**/*' ]
5+
s.name = 'activerecord-sqlserver-adapter'
6+
s.version = File.read(File.expand_path('../VERSION', __FILE__)).strip
7+
s.summary = 'ActiveRecord SQL Server Adapter. For SQL Server 2005 And Higher.'
8+
s.description = 'ActiveRecord SQL Server Adapter. For SQL Server 2005 And Higher.'
9+
10+
s.authors = ['Ken Collins', 'Anna Carey', 'Murray Steele', 'Shawn Balestracci', 'Joe Rafaniello', 'Tom Ward']
11+
s.email = 'ken@metaskills.net'
12+
s.homepage = 'http://github.com/rails-sqlserver/activerecord-sqlserver-adapter'
13+
14+
s.files = Dir['CHANGELOG', 'MIT-LICENSE', 'README.rdoc', 'VERSION', 'lib/**/*']
1515
s.require_path = 'lib'
1616
s.rubyforge_project = 'activerecord-sqlserver-adapter'
17-
17+
1818
s.add_dependency('activerecord', '~> 4.0.0')
1919
s.add_dependency('arel', '~> 4.0.1')
2020
end
21-

lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ module ConnectionAdapters
33
module Sqlserver
44
module CoreExt
55
module ActiveRecord
6-
76
extend ActiveSupport::Concern
8-
7+
98
included do
109
class_attribute :coerced_sqlserver_date_columns, :coerced_sqlserver_time_columns
1110
self.coerced_sqlserver_date_columns = Set.new
1211
self.coerced_sqlserver_time_columns = Set.new
1312
end
1413

1514
module ClassMethods
16-
1715
def execute_procedure(proc_name, *variables)
1816
if connection.respond_to?(:execute_procedure)
19-
connection.execute_procedure(proc_name,*variables)
17+
connection.execute_procedure(proc_name, *variables)
2018
else
2119
[]
2220
end
@@ -29,14 +27,11 @@ def coerce_sqlserver_date(*attributes)
2927
def coerce_sqlserver_time(*attributes)
3028
self.coerced_sqlserver_time_columns += attributes.map(&:to_s)
3129
end
32-
3330
end
34-
3531
end
3632
end
3733
end
3834
end
3935
end
4036

41-
4237
ActiveRecord::Base.send :include, ActiveRecord::ConnectionAdapters::Sqlserver::CoreExt::ActiveRecord

lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ module ConnectionAdapters
33
module Sqlserver
44
module CoreExt
55
module Explain
6-
7-
SQLSERVER_STATEMENT_PREFIX = "EXEC sp_executesql "
6+
SQLSERVER_STATEMENT_PREFIX = 'EXEC sp_executesql '
87
SQLSERVER_PARAM_MATCHER = /@\d+ =/
9-
8+
109
def exec_explain(queries)
1110
unprepared_queries = queries.map { |sql, bind| [unprepare_sqlserver_statement(sql), bind] }
1211
super(unprepared_queries)
1312
end
14-
13+
1514
private
16-
17-
# This is somewhat hacky, but it should reliably reformat our prepared sql statment
18-
# which uses sp_executesql to just the first argument, then unquote it. Likewise our
15+
16+
# This is somewhat hacky, but it should reliably reformat our prepared sql statment
17+
# which uses sp_executesql to just the first argument, then unquote it. Likewise our
1918
# do_exec_query method should substitude the @n args withe the quoted values.
2019
def unprepare_sqlserver_statement(sql)
2120
if sql.starts_with?(SQLSERVER_STATEMENT_PREFIX)
@@ -29,8 +28,6 @@ def unprepare_sqlserver_statement(sql)
2928
sql
3029
end
3130
end
32-
33-
3431
end
3532
end
3633
end

lib/active_record/connection_adapters/sqlserver/core_ext/odbc.rb

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,26 @@ module ConnectionAdapters
33
module Sqlserver
44
module CoreExt
55
module ODBC
6-
76
module Statement
8-
97
def finished?
10-
begin
11-
connected?
12-
false
13-
rescue ::ODBC::Error
14-
true
15-
end
8+
connected?
9+
false
10+
rescue ::ODBC::Error
11+
true
1612
end
17-
1813
end
1914

2015
module Database
21-
2216
def run_block(*args)
2317
yield sth = run(*args)
2418
sth.drop
2519
end
26-
2720
end
28-
2921
end
3022
end
3123
end
3224
end
3325
end
3426

35-
3627
ODBC::Statement.send :include, ActiveRecord::ConnectionAdapters::Sqlserver::CoreExt::ODBC::Statement
3728
ODBC::Database.send :include, ActiveRecord::ConnectionAdapters::Sqlserver::CoreExt::ODBC::Database
38-

lib/active_record/connection_adapters/sqlserver/core_ext/relation.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ module ConnectionAdapters
33
module Sqlserver
44
module CoreExt
55
module Relation
6-
76
private
8-
7+
98
def tables_in_string(string)
109
super - ['__rnt']
1110
end
12-
1311
end
1412
end
1513
end

lib/active_record/connection_adapters/sqlserver/database_limits.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module ActiveRecord
22
module ConnectionAdapters
33
module Sqlserver
44
module DatabaseLimits
5-
65
def table_alias_length
76
128
87
end
@@ -32,17 +31,16 @@ def columns_per_multicolumn_index
3231
end
3332

3433
def in_clause_length
35-
65536
34+
65_536
3635
end
3736

3837
def sql_query_length
39-
65536 * 4096
38+
65_536 * 4_096
4039
end
4140

4241
def joins_per_query
4342
256
4443
end
45-
4644
end
4745
end
4846
end

0 commit comments

Comments
 (0)