pgversion 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/Rakefile +2 -0
- data/lib/pgversion.rb +147 -0
- data/pgversion.gemspec +19 -0
- data/spec/pgversion_spec.rb +77 -0
- data/spec/spec_helper.rb +21 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7ea9663bfdf214432df8e2a1e5bbdb7930c7ef57
|
4
|
+
data.tar.gz: 856c53a3876a1057654e3d55edd0cf544e09e022
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7284ef96b1fa6b6e0ab2466d286a7df5cfa039353305a1fdefd2c696b138d82fe5160aeea0c6c5e54fa4bdf7460180e4f52237082e616444878322115f78f3ef
|
7
|
+
data.tar.gz: 15bcc4a97179d019effe325b81a2e13b81dd8a9d0efb1c76ef610c0674929ba8d789458eeb0e537627264dcf9378715309672cc75e9f26217c04c5896c3d5cfa
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Maciek Sakrejda
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/pgversion.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
# Represents a Postgres release version. Note that breaking changes
|
2
|
+
# generally only happen during major or minor version changes. Point
|
3
|
+
# releases are strictly focused on fixing data integrity or security
|
4
|
+
# issues.
|
5
|
+
class PGVersion
|
6
|
+
include Comparable
|
7
|
+
|
8
|
+
VERSION = "0.0.1"
|
9
|
+
|
10
|
+
# The major and minor version taken together determine the stable
|
11
|
+
# interface to Postgres. New features may be introduced or breaking
|
12
|
+
# changes made when either of these change.
|
13
|
+
attr_reader :major
|
14
|
+
|
15
|
+
# The major and minor version taken together determine the stable
|
16
|
+
# interface to Postgres. New features may be introduced or breaking
|
17
|
+
# changes made when either of these change.
|
18
|
+
attr_reader :minor
|
19
|
+
|
20
|
+
# The point release, for release states. Note that this may be nil,
|
21
|
+
# which is considered later than all other releases. Always nil
|
22
|
+
# when state is not :release.
|
23
|
+
attr_reader :point
|
24
|
+
|
25
|
+
# The state of a release: :alpha, :beta, :rc, or :release
|
26
|
+
attr_reader :state
|
27
|
+
|
28
|
+
# The revision, for non-release states. A release in a given state
|
29
|
+
# may go through several revisions in that state before moving to
|
30
|
+
# the next state. Nil when state is :release.
|
31
|
+
attr_reader :revision
|
32
|
+
|
33
|
+
# The host architecture of the given binary
|
34
|
+
attr_reader :host
|
35
|
+
# The compiler used to build the given binary
|
36
|
+
attr_reader :compiler
|
37
|
+
# Bit depth of the given binary
|
38
|
+
attr_reader :bit_depth
|
39
|
+
|
40
|
+
# Parse a Postgres version string, as produced by the function
|
41
|
+
# version(), into a PGVersion.
|
42
|
+
def self.parse(version_str)
|
43
|
+
result = version_str.match VERSION_REGEXP
|
44
|
+
raise ArgumentError, "Could not parse version string: #{version_str}" unless result
|
45
|
+
point = result[3]
|
46
|
+
if point =~ /\A\d+\Z/
|
47
|
+
point = point.to_i
|
48
|
+
end
|
49
|
+
PGVersion.new(result[1].to_i,
|
50
|
+
result[2].to_i,
|
51
|
+
point,
|
52
|
+
host: result[4],
|
53
|
+
compiler: result[5],
|
54
|
+
bit_depth: result[6].to_i)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Initialize a new PGVersion
|
58
|
+
def initialize(major, minor, point=nil, host: nil, compiler: nil, bit_depth: nil)
|
59
|
+
@major = major
|
60
|
+
@minor = minor
|
61
|
+
if point.nil? || point.is_a?(Fixnum)
|
62
|
+
@point = point
|
63
|
+
@state = :release
|
64
|
+
else
|
65
|
+
verstr_states = ALLOWED_STATES.reject { |s| s == :release }.map(&:to_s)
|
66
|
+
@state, @revision = point.to_s.match(
|
67
|
+
/(#{verstr_states.join('|')})(\d+)/
|
68
|
+
) && $1.to_sym, $2.to_i
|
69
|
+
unless @state && @revision
|
70
|
+
raise ArgumentError, "Unknown point release: #{point}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
@host = host
|
74
|
+
@compiler = compiler
|
75
|
+
@bit_depth = bit_depth
|
76
|
+
end
|
77
|
+
|
78
|
+
# Compare to another PGVersion. Note that an unspecified point
|
79
|
+
# release version is considered higher than every point version of
|
80
|
+
# the same state.
|
81
|
+
def <=>(other)
|
82
|
+
if self.major < other.major
|
83
|
+
-1
|
84
|
+
elsif self.major > other.major
|
85
|
+
1
|
86
|
+
else
|
87
|
+
if self.minor < other.minor
|
88
|
+
-1
|
89
|
+
elsif self.minor > other.minor
|
90
|
+
1
|
91
|
+
else
|
92
|
+
self_state_idx = ALLOWED_STATES.index(self.state)
|
93
|
+
other_state_idx = ALLOWED_STATES.index(other.state)
|
94
|
+
if self_state_idx < other_state_idx
|
95
|
+
-1
|
96
|
+
elsif self_state_idx > other_state_idx
|
97
|
+
1
|
98
|
+
elsif self.state == :release
|
99
|
+
if self.point.nil? && other.point.nil?
|
100
|
+
0
|
101
|
+
elsif other.point.nil?
|
102
|
+
-1
|
103
|
+
elsif self.point.nil?
|
104
|
+
1
|
105
|
+
else
|
106
|
+
self.point <=> other.point
|
107
|
+
end
|
108
|
+
else
|
109
|
+
self.revision <=> other.revision
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def release?; @state == :release; end
|
116
|
+
def rc?; @state == :rc; end
|
117
|
+
def beta?; @state == :beta; end
|
118
|
+
def alpha?; @state == :alpha; end
|
119
|
+
|
120
|
+
def to_s
|
121
|
+
patch = if release?
|
122
|
+
".#{point}" unless point.nil?
|
123
|
+
else
|
124
|
+
"#{state}#{revision}"
|
125
|
+
end
|
126
|
+
v = "PostgreSQL #{major}.#{minor}#{patch}"
|
127
|
+
if host
|
128
|
+
v << " on #{host}"
|
129
|
+
end
|
130
|
+
if compiler
|
131
|
+
v << ", compiled by #{compiler}"
|
132
|
+
end
|
133
|
+
if bit_depth
|
134
|
+
v << ", #{bit_depth}-bit"
|
135
|
+
end
|
136
|
+
v
|
137
|
+
end
|
138
|
+
|
139
|
+
protected
|
140
|
+
|
141
|
+
attr_reader :state
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
VERSION_REGEXP = /PostgreSQL (\d+)\.(\d+).?((?:alpha|beta|rc)?\d+) on ([^,]+), compiled by ([^,]+), (\d+)-bit/
|
146
|
+
ALLOWED_STATES = %i(alpha beta rc release)
|
147
|
+
end
|
data/pgversion.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'lib/pgversion'
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Maciek Sakrejda"]
|
5
|
+
gem.email = ["m.sakrejda@gmail.com"]
|
6
|
+
gem.description = %q{Easy Postgres version utilities}
|
7
|
+
gem.summary = %q{Parse Postgres version strings and compare versions}
|
8
|
+
gem.homepage = "https://github.com/deafbybeheading/pgversion"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "pgversion"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = PGVersion::VERSION
|
16
|
+
gem.license = "MIT"
|
17
|
+
|
18
|
+
gem.add_development_dependency "rspec", '~> 4.0'
|
19
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/pgversion'
|
3
|
+
|
4
|
+
describe PGVersion do
|
5
|
+
{
|
6
|
+
"PostgreSQL 9.2.8 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-16ubuntu6) 4.8.2, 64-bit" =>
|
7
|
+
PGVersion.new(9,2,8, host: 'x86_64-unknown-linux-gnu', compiler: 'gcc (Ubuntu 4.8.2-16ubuntu6) 4.8.2', bit_depth: 64),
|
8
|
+
"PostgreSQL 9.1rc1 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-16ubuntu6) 4.8.2, 32-bit" =>
|
9
|
+
PGVersion.new(9,1,:rc1, host: 'x86_64-unknown-linux-gnu', compiler: 'gcc (Ubuntu 4.8.2-16ubuntu6) 4.8.2', bit_depth: 32),
|
10
|
+
"PostgreSQL 9.0beta2 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-16ubuntu6) 4.8.2, 64-bit" =>
|
11
|
+
PGVersion.new(9,0,:beta2, host: 'x86_64-unknown-linux-gnu', compiler: 'gcc (Ubuntu 4.8.2-16ubuntu6) 4.8.2', bit_depth: 64),
|
12
|
+
"PostgreSQL 8.4alpha3 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-16ubuntu6) 4.8.2, 64-bit" =>
|
13
|
+
PGVersion.new(8,4,:alpha3, host: 'x86_64-unknown-linux-gnu', compiler: 'gcc (Ubuntu 4.8.2-16ubuntu6) 4.8.2', bit_depth: 64),
|
14
|
+
"PostgreSQL 10.0.0 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-16ubuntu6) 4.8.2, 64-bit" =>
|
15
|
+
PGVersion.new(10,0,0, host: 'x86_64-unknown-linux-gnu', compiler: 'gcc (Ubuntu 4.8.2-16ubuntu6) 4.8.2', bit_depth: 64)
|
16
|
+
}.each do |version_str, version|
|
17
|
+
describe '.parse' do
|
18
|
+
it "parses #{version_str} into corresponding version #{version}" do
|
19
|
+
expect(PGVersion.parse(version_str)).to eq(version)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#to_s' do
|
24
|
+
it "formats #{version} into corresponding #{version_str}" do
|
25
|
+
expect(version.to_s).to eq(version_str)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#<=>" do
|
31
|
+
it "ignores bit_depth" do
|
32
|
+
expect(PGVersion.new(9,0,0, bit_depth: 32) <=> PGVersion.new(9,0,0, bit_depth: 32)).to eq(0)
|
33
|
+
end
|
34
|
+
it "ignores host" do
|
35
|
+
expect(PGVersion.new(9,0,0, host: "Linux") <=> PGVersion.new(9,0,0, host: "OS X")).to eq(0)
|
36
|
+
end
|
37
|
+
it "ignores compiler" do
|
38
|
+
expect(PGVersion.new(9,0,0, compiler: "gcc") <=> PGVersion.new(9,0,0, compiler: "ICC")).to eq(0)
|
39
|
+
end
|
40
|
+
|
41
|
+
test_versions = [
|
42
|
+
PGVersion.new(8,3,:alpha1),
|
43
|
+
PGVersion.new(8,3,:alpha3),
|
44
|
+
PGVersion.new(8,3,:beta1),
|
45
|
+
PGVersion.new(8,3,:beta2),
|
46
|
+
PGVersion.new(8,3,:rc1),
|
47
|
+
PGVersion.new(8,3,:rc3),
|
48
|
+
PGVersion.new(8,3,0),
|
49
|
+
PGVersion.new(8,3,1),
|
50
|
+
PGVersion.new(8,3),
|
51
|
+
PGVersion.new(8,14,0),
|
52
|
+
PGVersion.new(9,4,0),
|
53
|
+
PGVersion.new(10,0,:alpha1),
|
54
|
+
PGVersion.new(10,0,:alpha3),
|
55
|
+
PGVersion.new(10,0,:beta1),
|
56
|
+
PGVersion.new(10,0,:beta2),
|
57
|
+
PGVersion.new(10,0,:rc1),
|
58
|
+
PGVersion.new(10,0,:rc3),
|
59
|
+
PGVersion.new(10,0,0),
|
60
|
+
PGVersion.new(10,0,2),
|
61
|
+
PGVersion.new(10,0,10),
|
62
|
+
PGVersion.new(10,0)
|
63
|
+
].each_with_index.to_a.repeated_permutation(2).each do |(l,lidx), (r,ridx)|
|
64
|
+
expected = lidx <=> ridx
|
65
|
+
it "compares #{l} to #{r} and gets #{expected}" do
|
66
|
+
expect(l <=> r).to eq(expected)
|
67
|
+
end
|
68
|
+
unless expected == 0
|
69
|
+
opposite = expected * -1
|
70
|
+
it "compares #{r} to #{l} and gets #{opposite}" do
|
71
|
+
expect(r <=> l).to eq(opposite)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
|
18
|
+
config.expect_with :rspec do |c|
|
19
|
+
c.syntax = :expect
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pgversion
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maciek Sakrejda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
description: Easy Postgres version utilities
|
28
|
+
email:
|
29
|
+
- m.sakrejda@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- Gemfile
|
35
|
+
- LICENSE
|
36
|
+
- Rakefile
|
37
|
+
- lib/pgversion.rb
|
38
|
+
- pgversion.gemspec
|
39
|
+
- spec/pgversion_spec.rb
|
40
|
+
- spec/spec_helper.rb
|
41
|
+
homepage: https://github.com/deafbybeheading/pgversion
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.2.2
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Parse Postgres version strings and compare versions
|
65
|
+
test_files:
|
66
|
+
- spec/pgversion_spec.rb
|
67
|
+
- spec/spec_helper.rb
|