Skip to content

Commit

Permalink
#32 versions up
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed May 2, 2023
1 parent a74b7cb commit c07db76
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 83 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ AllCops:
- 'assets/**/*'
DisplayCopNames: true
TargetRubyVersion: 2.3
SuggestExtensions: false
NewCops: enable

Style/ClassAndModuleChildren:
Enabled: false
Expand Down
14 changes: 8 additions & 6 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Copyright (c) 2019 Yegor Bugayenko
# frozen_string_literal: true

# Copyright (c) 2019-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
Expand All @@ -18,21 +20,21 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

if Gem.win_platform? then
if Gem.win_platform?
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter
]
SimpleCov.start do
add_filter "/test/"
add_filter "/features/"
add_filter '/test/'
add_filter '/features/'
end
else
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
[SimpleCov::Formatter::HTMLFormatter]
)
SimpleCov.start do
add_filter "/test/"
add_filter "/features/"
add_filter '/test/'
add_filter '/features/'
minimum_coverage 60
end
end
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2019 Yegor Bugayenko
# Copyright (c) 2019-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
Expand All @@ -21,5 +21,4 @@
# SOFTWARE.

source 'https://rubygems.org'
ruby '~>2.3'
gemspec
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(The MIT License)

Copyright (c) 2019 Yegor Bugayenko
Copyright (c) 2019-2023 Yegor Bugayenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,8 @@ $ bundle exec rake

If it's clean and you don't see any error messages, submit your pull request.

To run a single test, do this:

```
$ bundle exec ruby test/test_pool.rb -n test_basic
```
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2019 Yegor Bugayenko
# Copyright (c) 2019-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
Expand Down
4 changes: 2 additions & 2 deletions lib/pgtk.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2019 Yegor Bugayenko
# Copyright (c) 2019-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
Expand All @@ -22,7 +22,7 @@

# Pgtk main module.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2019 Yegor Bugayenko
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
# License:: MIT
module Pgtk
# Nothing here.
Expand Down
14 changes: 5 additions & 9 deletions lib/pgtk/liquibase_task.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2019 Yegor Bugayenko
# Copyright (c) 2019-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
Expand Down Expand Up @@ -29,20 +29,16 @@

# Liquibase rake task.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2019 Yegor Bugayenko
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
# License:: MIT
class Pgtk::LiquibaseTask < Rake::TaskLib
attr_accessor :name
attr_accessor :master
attr_accessor :yaml
attr_accessor :quiet
attr_accessor :name, :master, :yaml, :quiet

def initialize(*args, &task_block)
super()
@name = args.shift || :liquibase
@quite = false
unless ::Rake.application.last_description
desc 'Deploy Liquibase changes to the running PostgreSQL server'
end
desc 'Deploy Liquibase changes to the running PostgreSQL server' unless ::Rake.application.last_description
task(name, *args) do |_, task_args|
RakeFileUtils.send(:verbose, true) do
yield(*[self, task_args].slice(0, task_block.arity)) if block_given?
Expand Down
29 changes: 9 additions & 20 deletions lib/pgtk/pgsql_task.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2019 Yegor Bugayenko
# Copyright (c) 2019-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
Expand Down Expand Up @@ -32,30 +32,21 @@

# Pgsql rake task.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2019 Yegor Bugayenko
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
# License:: MIT
class Pgtk::PgsqlTask < Rake::TaskLib
attr_accessor :name
attr_accessor :dir
attr_accessor :fresh_start
attr_accessor :user
attr_accessor :password
attr_accessor :dbname
attr_accessor :yaml
attr_accessor :quiet
attr_accessor :port
attr_accessor :name, :dir, :fresh_start, :user, :password, :dbname, :yaml, :quiet, :port

def initialize(*args, &task_block)
super()
@name = args.shift || :pgsql
@fresh_start = false
@quite = false
@user = 'test'
@password = 'test'
@dbname = 'test'
@port = nil
unless ::Rake.application.last_description
desc 'Start a local PostgreSQL server'
end
desc 'Start a local PostgreSQL server' unless ::Rake.application.last_description
task(name, *args) do |_, task_args|
RakeFileUtils.send(:verbose, true) do
yield(*[self, task_args].slice(0, task_block.arity)) if block_given?
Expand All @@ -71,12 +62,10 @@ def run
raise "Option 'yaml' is mandatory" unless @yaml
home = File.expand_path(@dir)
FileUtils.rm_rf(home) if @fresh_start
if File.exist?(home)
raise "Directory/file #{home} is present, use fresh_start=true"
end
raise "Directory/file #{home} is present, use fresh_start=true" if File.exist?(home)
out = "2>&1 #{@quiet ? '>/dev/null' : ''}"
Tempfile.open do |pwfile|
IO.write(pwfile.path, @password)
File.write(pwfile.path, @password)
system(
[
'initdb --auth=trust',
Expand All @@ -98,7 +87,7 @@ def run
puts "Required TCP port #{port} is used"
end
pid = Process.spawn('postgres', '-k', home, '-D', home, "--port=#{port}")
IO.write(File.join(@dir, 'pid'), pid)
File.write(File.join(@dir, 'pid'), pid)
at_exit do
`kill -TERM #{pid}`
puts "PostgreSQL killed in PID #{pid}"
Expand All @@ -123,7 +112,7 @@ def run
raise if attempt > 10
retry
end
IO.write(
File.write(
@yaml,
{
'pgsql' => {
Expand Down
12 changes: 5 additions & 7 deletions lib/pgtk/pool.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2019 Yegor Bugayenko
# Copyright (c) 2019-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
Expand All @@ -27,7 +27,7 @@

# Pool.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2019 Yegor Bugayenko
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
# License:: MIT
class Pgtk::Pool
# Constructor.
Expand All @@ -39,7 +39,7 @@ def initialize(wire, log: Loog::NULL)

# Get the version of PostgreSQL server.
def version
@version ||= exec('SHOW server_version')[0]['server_version'].split(' ')[0]
@version ||= exec('SHOW server_version')[0]['server_version'].split[0]
end

# Start it with a fixed number of connections. The amount of connections
Expand Down Expand Up @@ -101,13 +101,11 @@ def start(max = 8)
#
# More details about +exec_params+, which is called here, you can find
# here: https://www.rubydoc.info/gems/pg/0.17.1/PG%2FConnection:exec_params
def exec(query, args = [], result = 0)
def exec(query, args = [], result = 0, &block)
connect do |c|
t = Txn.new(c, @log)
if block_given?
t.exec(query, args, result) do |res|
yield res
end
t.exec(query, args, result, &block)
else
t.exec(query, args, result)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pgtk/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2019 Yegor Bugayenko
# Copyright (c) 2019-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
Expand All @@ -24,7 +24,7 @@

# Pgtk version.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2019 Yegor Bugayenko
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
# License:: MIT
module Pgtk
# Current version of the library.
Expand Down
12 changes: 6 additions & 6 deletions lib/pgtk/wire.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2019 Yegor Bugayenko
# Copyright (c) 2019-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
Expand All @@ -27,14 +27,14 @@

# Wires.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2019 Yegor Bugayenko
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
# License:: MIT
module Pgtk::Wire
end

# Simple wire with details.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2019 Yegor Bugayenko
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
# License:: MIT
class Pgtk::Wire::Direct
# Constructor.
Expand All @@ -59,7 +59,7 @@ def connection

# Using ENV variable.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2019 Yegor Bugayenko
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
# License:: MIT
class Pgtk::Wire::Env
# Constructor.
Expand All @@ -70,7 +70,7 @@ def initialize(var = 'DATABASE_URL')

# Create a new connection to PostgreSQL server.
def connection
v = ENV[@var]
v = ENV.fetch(@var, nil)
raise "The environment variable #{@var.inspect} is not set" if v.nil?
uri = URI(v)
Pgtk::Wire::Direct.new(
Expand All @@ -85,7 +85,7 @@ def connection

# Using configuration from YAML file.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2019 Yegor Bugayenko
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
# License:: MIT
class Pgtk::Wire::Yaml
# Constructor.
Expand Down
23 changes: 10 additions & 13 deletions pgtk.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2019 Yegor Bugayenko
# Copyright (c) 2019-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
Expand All @@ -26,11 +26,7 @@ lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require_relative 'lib/pgtk/version'
Gem::Specification.new do |s|
s.specification_version = 2 if s.respond_to? :specification_version=
if s.respond_to? :required_rubygems_version=
s.required_rubygems_version = Gem::Requirement.new('>= 0')
end
s.rubygems_version = '2.2'
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
s.required_ruby_version = '>= 2.3'
s.name = 'pgtk'
s.version = Pgtk::VERSION
Expand All @@ -44,18 +40,19 @@ connection pool and query processor, to make SQL manipulation simpler.'
s.homepage = 'http://github.com/yegor256/pgtk'
s.files = `git ls-files`.split($RS)
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
s.test_files = s.files.grep(%r{^(test|spec|features)/})
s.rdoc_options = ['--charset=UTF-8']
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
s.add_runtime_dependency 'backtrace', '~> 0.3'
s.add_runtime_dependency 'loog', '~> 0.2'
s.add_runtime_dependency 'pg', '~> 1.1'
s.add_runtime_dependency 'random-port', '~> 0.3'
s.add_development_dependency 'codecov', '0.1.10'
s.add_development_dependency 'minitest', '5.5.0'
s.add_development_dependency 'rake', '12.0.0'
s.add_development_dependency 'minitest', '5.18.0'
s.add_development_dependency 'rack', '2.2.7'
s.add_development_dependency 'rake', '13.0.6'
s.add_development_dependency 'rspec-rails', '3.1.0'
s.add_development_dependency 'rubocop', '0.61.0'
s.add_development_dependency 'rubocop-rspec', '1.31.0'
s.add_development_dependency 'xcop', '0.6'
s.add_development_dependency 'rubocop', '1.50.2'
s.add_development_dependency 'rubocop-rspec', '2.20.0'
s.add_development_dependency 'simplecov', '0.22.0'
s.add_development_dependency 'xcop', '0.7.1'
s.metadata['rubygems_mfa_required'] = 'true'
end
2 changes: 1 addition & 1 deletion resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--
(The MIT License)
Copyright (c) 2019 Yegor Bugayenko
Copyright (c) 2019-2023 Yegor Bugayenko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
Expand Down
2 changes: 1 addition & 1 deletion test-resources/2019/01-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--
(The MIT License)
Copyright (c) 2019 Yegor Bugayenko
Copyright (c) 2019-2023 Yegor Bugayenko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
Expand Down
2 changes: 1 addition & 1 deletion test-resources/master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--
(The MIT License)
Copyright (c) 2019 Yegor Bugayenko
Copyright (c) 2019-2023 Yegor Bugayenko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
Expand Down
Loading

0 comments on commit c07db76

Please sign in to comment.