Skip to content

Commit cba28e3

Browse files
authored
Merge pull request #574 from andyundso/standard-rb
Use `standardrb` for code formatting
2 parents fbd2797 + 9bcc011 commit cba28e3

27 files changed

+815
-1168
lines changed

.github/workflows/ci.yml

+15
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,18 @@ jobs:
573573
shell: bash
574574
run: |
575575
ruby -e "require 'tiny_tds'; puts TinyTds::Gem.root_path"
576+
577+
standardrb:
578+
name: standardrb
579+
runs-on: ubuntu-22.04
580+
steps:
581+
- uses: actions/checkout@v4
582+
583+
- uses: ruby/setup-ruby@v1
584+
with:
585+
ruby-version: "2.7"
586+
bundler-cache: true
587+
588+
- name: Check standardrb
589+
shell: bash
590+
run: bundle exec standardrb

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22
gemspec

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@ $ rake TINYTDS_UNIT_DATASERVER=mydbserver TINYTDS_SCHEMA=sqlserver_2017
439439
$ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_SCHEMA=sqlserver_azure
440440
```
441441

442+
### Code formatting
443+
444+
We are using `standardrb` to format our code. Just run `bundle exec standardrb --fix` to format all Ruby files.
445+
442446
### Compiling Gems for Windows and Linux
443447

444448
> [!WARNING]

Rakefile

+27-28
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,54 @@
1-
# encoding: UTF-8
2-
require 'rbconfig'
3-
require 'rake'
4-
require 'rake/clean'
5-
require 'rake/extensiontask'
1+
require "rbconfig"
2+
require "rake"
3+
require "rake/clean"
4+
require "rake/extensiontask"
65

7-
SPEC = Gem::Specification.load(File.expand_path('../tiny_tds.gemspec', __FILE__))
6+
SPEC = Gem::Specification.load(File.expand_path("../tiny_tds.gemspec", __FILE__))
87

98
CrossLibrary = Struct.new :platform, :openssl_config
109
CrossLibraries = [
11-
['x64-mingw-ucrt', 'mingw64'],
12-
['x64-mingw32', 'mingw64'],
13-
['x86_64-linux-gnu', 'linux-x86_64'],
14-
['x86_64-linux-musl', 'linux-x86_64'],
15-
['aarch64-linux-gnu', 'linux-aarch64'],
16-
['aarch64-linux-musl', 'linux-aarch64'],
10+
["x64-mingw-ucrt", "mingw64"],
11+
["x64-mingw32", "mingw64"],
12+
["x86_64-linux-gnu", "linux-x86_64"],
13+
["x86_64-linux-musl", "linux-x86_64"],
14+
["aarch64-linux-gnu", "linux-aarch64"],
15+
["aarch64-linux-musl", "linux-aarch64"]
1716
].map do |platform, openssl_config|
1817
CrossLibrary.new platform, openssl_config
1918
end
2019

2120
# Add our project specific files to clean for a rebuild
22-
CLEAN.include FileList["{ext,lib}/**/*.{so,#{RbConfig::CONFIG['DLEXT']},o}"],
23-
FileList["exe/*"]
21+
CLEAN.include FileList["{ext,lib}/**/*.{so,#{RbConfig::CONFIG["DLEXT"]},o}"],
22+
FileList["exe/*"]
2423

2524
# Clobber all our temp files and ports files including .install files
2625
# and archives
2726
CLOBBER.include FileList["tmp/**/*"],
28-
FileList["ports/**/*"].exclude(%r{^ports/archives})
27+
FileList["ports/**/*"].exclude(%r{^ports/archives})
2928

30-
Dir['tasks/*.rake'].sort.each { |f| load f }
29+
Dir["tasks/*.rake"].sort.each { |f| load f }
3130

32-
Rake::ExtensionTask.new('tiny_tds', SPEC) do |ext|
33-
ext.lib_dir = 'lib/tiny_tds'
31+
Rake::ExtensionTask.new("tiny_tds", SPEC) do |ext|
32+
ext.lib_dir = "lib/tiny_tds"
3433
ext.cross_compile = true
3534
ext.cross_platform = CrossLibraries.map(&:platform)
3635

3736
# Add dependent DLLs to the cross gems
3837
ext.cross_compiling do |spec|
3938
# The fat binary gem doesn't depend on the freetds package, since it bundles the library.
40-
spec.metadata.delete('msys2_mingw_dependencies')
41-
42-
if spec.platform.to_s =~ /mingw/
39+
spec.metadata.delete("msys2_mingw_dependencies")
40+
41+
if /mingw/.match?(spec.platform.to_s)
4342
spec.files += [
44-
"ports/#{spec.platform.to_s}/bin/libsybdb-5.dll",
45-
"ports/#{spec.platform.to_s}/bin/defncopy.exe",
46-
"ports/#{spec.platform.to_s}/bin/tsql.exe"
43+
"ports/#{spec.platform}/bin/libsybdb-5.dll",
44+
"ports/#{spec.platform}/bin/defncopy.exe",
45+
"ports/#{spec.platform}/bin/tsql.exe"
4746
]
48-
elsif spec.platform.to_s =~ /linux/
47+
elsif /linux/.match?(spec.platform.to_s)
4948
spec.files += [
50-
"ports/#{spec.platform.to_s}/lib/libsybdb.so.5",
51-
"ports/#{spec.platform.to_s}/bin/defncopy",
52-
"ports/#{spec.platform.to_s}/bin/tsql"
49+
"ports/#{spec.platform}/lib/libsybdb.so.5",
50+
"ports/#{spec.platform}/bin/defncopy",
51+
"ports/#{spec.platform}/bin/tsql"
5352
]
5453
end
5554
end

ext/tiny_tds/extconf.rb

+46-46
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
require 'mkmf'
2-
require_relative 'extconsts'
3-
4-
if ENV['MAINTAINER_MODE']
5-
$stderr.puts "Maintainer mode enabled."
6-
$CFLAGS <<
7-
' -Wall' <<
8-
' -ggdb' <<
9-
' -DDEBUG' <<
10-
' -pedantic'
11-
$LDFLAGS <<
12-
' -ggdb'
1+
require "mkmf"
2+
require_relative "extconsts"
3+
4+
if ENV["MAINTAINER_MODE"]
5+
warn "Maintainer mode enabled."
6+
$CFLAGS << # standard:disable Style/GlobalVars
7+
" -Wall" \
8+
" -ggdb" \
9+
" -DDEBUG" \
10+
" -pedantic"
11+
$LDFLAGS << # standard:disable Style/GlobalVars
12+
" -ggdb"
1313
end
1414

15-
if gem_platform=with_config("cross-build")
16-
require 'mini_portile2'
15+
if (gem_platform = with_config("cross-build"))
16+
require "mini_portile2"
1717

1818
openssl_platform = with_config("openssl-platform")
1919

@@ -23,7 +23,7 @@ class BuildRecipe < MiniPortile
2323
def initialize(name, version, files)
2424
super(name, version)
2525
self.files = files
26-
rootdir = File.expand_path('../../..', __FILE__)
26+
rootdir = File.expand_path("../../..", __FILE__)
2727
self.target = File.join(rootdir, "ports")
2828
self.patch_files = Dir[File.join("patches", self.name, self.version, "*.patch")].sort
2929
end
@@ -34,35 +34,35 @@ def port_path
3434
end
3535

3636
def cook_and_activate
37-
checkpoint = File.join(self.target, "#{self.name}-#{self.version}-#{gem_platform}.installed")
38-
37+
checkpoint = File.join(target, "#{name}-#{version}-#{gem_platform}.installed")
38+
3939
unless File.exist?(checkpoint)
40-
self.cook
41-
FileUtils.touch checkpoint
42-
end
43-
44-
self.activate
40+
cook
41+
FileUtils.touch checkpoint
42+
end
43+
44+
activate
4545
self
4646
end
4747
end
4848

4949
openssl_recipe = BuildRecipe.new("openssl", OPENSSL_VERSION, [OPENSSL_SOURCE_URI]).tap do |recipe|
50-
class << recipe
50+
class << recipe
5151
attr_accessor :openssl_platform
52-
52+
5353
def configure
5454
envs = []
5555
envs << "CFLAGS=-DDSO_WIN32 -DOPENSSL_THREADS" if MiniPortile.windows?
5656
envs << "CFLAGS=-fPIC -DOPENSSL_THREADS" if MiniPortile.linux?
57-
execute('configure', ['env', *envs, "./Configure", openssl_platform, "threads", "-static", "CROSS_COMPILE=#{host}-", configure_prefix, "--libdir=lib"], altlog: "config.log")
57+
execute("configure", ["env", *envs, "./Configure", openssl_platform, "threads", "-static", "CROSS_COMPILE=#{host}-", configure_prefix, "--libdir=lib"], altlog: "config.log")
5858
end
59-
59+
6060
def compile
61-
execute('compile', "#{make_cmd} build_libs")
61+
execute("compile", "#{make_cmd} build_libs")
6262
end
63-
63+
6464
def install
65-
execute('install', "#{make_cmd} install_dev")
65+
execute("install", "#{make_cmd} install_dev")
6666
end
6767
end
6868

@@ -122,30 +122,30 @@ def configure_defaults
122122
end
123123

124124
# enable relative path to later load the FreeTDS shared library
125-
$LDFLAGS << " '-Wl,-rpath=$$ORIGIN/../../../ports/#{gem_platform}/lib'"
125+
$LDFLAGS << " '-Wl,-rpath=$$ORIGIN/../../../ports/#{gem_platform}/lib'" # standard:disable Style/GlobalVars
126126

127-
dir_config('freetds', "#{freetds_recipe.path}/include", "#{freetds_recipe.path}/lib")
127+
dir_config("freetds", "#{freetds_recipe.path}/include", "#{freetds_recipe.path}/lib")
128128
else
129129
# Make sure to check the ports path for the configured host
130-
architecture = RbConfig::CONFIG['arch']
130+
architecture = RbConfig::CONFIG["arch"]
131131

132132
project_dir = File.expand_path("../../..", __FILE__)
133-
freetds_ports_dir = File.join(project_dir, 'ports', architecture, 'freetds', FREETDS_VERSION)
133+
freetds_ports_dir = File.join(project_dir, "ports", architecture, "freetds", FREETDS_VERSION)
134134
freetds_ports_dir = File.expand_path(freetds_ports_dir)
135-
135+
136136
# Add all the special path searching from the original tiny_tds build
137137
# order is important here! First in, first searched.
138-
DIRS = %w(
138+
DIRS = %w[
139139
/opt/local
140140
/usr/local
141-
)
141+
]
142142

143-
if RbConfig::CONFIG['host_os'] =~ /darwin/i
143+
if /darwin/i.match?(RbConfig::CONFIG["host_os"])
144144
# Ruby below 2.7 seems to label the host CPU on Apple Silicon as aarch64
145145
# 2.7 and above print is as ARM64
146-
target_host_cpu = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7') ? 'aarch64' : 'arm64'
146+
target_host_cpu = (Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7")) ? "aarch64" : "arm64"
147147

148-
if RbConfig::CONFIG['host_cpu'] == target_host_cpu
148+
if RbConfig::CONFIG["host_cpu"] == target_host_cpu
149149
# Homebrew on Apple Silicon installs into /opt/hombrew
150150
# https://docs.brew.sh/Installation
151151
# On Intel Macs, it is /usr/local, so no changes necessary to DIRS
@@ -162,7 +162,7 @@ def configure_defaults
162162

163163
# Grab freetds environment variable for use by people on services like
164164
# Heroku who they can't easily use bundler config to set directories
165-
DIRS.unshift(ENV['FREETDS_DIR']) if ENV.has_key?('FREETDS_DIR')
165+
DIRS.unshift(ENV["FREETDS_DIR"]) if ENV.has_key?("FREETDS_DIR")
166166

167167
# Add the search paths for freetds configured above
168168
ldirs = DIRS.flat_map do |path|
@@ -175,15 +175,15 @@ def configure_defaults
175175
[idir, "#{idir}/freetds"]
176176
end
177177

178-
puts "looking for freetds headers in the following directories:\n#{idirs.map{|a| " - #{a}\n"}.join}"
179-
puts "looking for freetds library in the following directories:\n#{ldirs.map{|a| " - #{a}\n"}.join}"
180-
dir_config('freetds', idirs, ldirs)
178+
puts "looking for freetds headers in the following directories:\n#{idirs.map { |a| " - #{a}\n" }.join}"
179+
puts "looking for freetds library in the following directories:\n#{ldirs.map { |a| " - #{a}\n" }.join}"
180+
dir_config("freetds", idirs, ldirs)
181181
end
182182

183-
find_header('sybfront.h') or abort "Can't find the 'sybfront.h' header"
184-
find_header('sybdb.h') or abort "Can't find the 'sybdb.h' header"
183+
find_header("sybfront.h") or abort "Can't find the 'sybfront.h' header"
184+
find_header("sybdb.h") or abort "Can't find the 'sybdb.h' header"
185185

186-
unless have_library('sybdb', 'dbanydatecrack')
186+
unless have_library("sybdb", "dbanydatecrack")
187187
abort "Failed! Do you have FreeTDS 1.0.0 or higher installed?"
188188
end
189189

ext/tiny_tds/extconsts.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
2-
ICONV_VERSION = ENV['TINYTDS_ICONV_VERSION'] || "1.17"
1+
ICONV_VERSION = ENV["TINYTDS_ICONV_VERSION"] || "1.17"
32
ICONV_SOURCE_URI = "http://ftp.gnu.org/pub/gnu/libiconv/libiconv-#{ICONV_VERSION}.tar.gz"
43

5-
OPENSSL_VERSION = ENV['TINYTDS_OPENSSL_VERSION'] || '3.4.0'
4+
OPENSSL_VERSION = ENV["TINYTDS_OPENSSL_VERSION"] || "3.4.0"
65
OPENSSL_SOURCE_URI = "https://www.openssl.org/source/openssl-#{OPENSSL_VERSION}.tar.gz"
76

8-
FREETDS_VERSION = ENV['TINYTDS_FREETDS_VERSION'] || '1.4.23'
7+
FREETDS_VERSION = ENV["TINYTDS_FREETDS_VERSION"] || "1.4.23"
98
FREETDS_SOURCE_URI = "http://www.freetds.org/files/stable/freetds-#{FREETDS_VERSION}.tar.bz2"

lib/tiny_tds.rb

+18-23
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
# encoding: UTF-8
2-
require 'date'
3-
require 'bigdecimal'
4-
require 'rational'
1+
require "date"
2+
require "bigdecimal"
53

6-
require 'tiny_tds/version'
7-
require 'tiny_tds/error'
8-
require 'tiny_tds/client'
9-
require 'tiny_tds/result'
10-
require 'tiny_tds/gem'
4+
require "tiny_tds/version"
5+
require "tiny_tds/error"
6+
require "tiny_tds/client"
7+
require "tiny_tds/result"
8+
require "tiny_tds/gem"
119

1210
module TinyTds
13-
1411
# Is this file part of a fat binary gem with bundled freetds?
1512
# This path must be enabled by add_dll_directory on Windows.
1613
gplat = ::Gem::Platform.local
1714
FREETDS_LIB_PATH = Dir[File.expand_path("../ports/#{gplat.cpu}-#{gplat.os}*/lib", __dir__)].first
1815

1916
add_dll_path = proc do |path, &block|
20-
if RUBY_PLATFORM =~/(mswin|mingw)/i && path
17+
if RUBY_PLATFORM =~ /(mswin|mingw)/i && path
2118
begin
22-
require 'ruby_installer/runtime'
19+
require "ruby_installer/runtime"
2320
RubyInstaller::Runtime.add_dll_directory(path, &block)
2421
rescue LoadError
25-
old_path = ENV['PATH']
26-
ENV['PATH'] = "#{path};#{old_path}"
22+
old_path = ENV["PATH"]
23+
ENV["PATH"] = "#{path};#{old_path}"
2724
block.call
28-
ENV['PATH'] = old_path
25+
ENV["PATH"] = old_path
2926
end
3027
else
3128
# libsybdb is found by a relative rpath in the cross compiled extension dll
@@ -35,13 +32,11 @@ module TinyTds
3532
end
3633

3734
add_dll_path.call(FREETDS_LIB_PATH) do
38-
begin
39-
# Try the <major>.<minor> subdirectory for fat binary gems
40-
major_minor = RUBY_VERSION[ /^(\d+\.\d+)/ ] or
41-
raise "Oops, can't extract the major/minor version from #{RUBY_VERSION.dump}"
42-
require "tiny_tds/#{major_minor}/tiny_tds"
43-
rescue LoadError
44-
require 'tiny_tds/tiny_tds'
45-
end
35+
# Try the <major>.<minor> subdirectory for fat binary gems
36+
major_minor = RUBY_VERSION[/^(\d+\.\d+)/] or
37+
raise "Oops, can't extract the major/minor version from #{RUBY_VERSION.dump}"
38+
require "tiny_tds/#{major_minor}/tiny_tds"
39+
rescue LoadError
40+
require "tiny_tds/tiny_tds"
4641
end
4742
end

0 commit comments

Comments
 (0)