pgversion 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90ec278816748e4da89d34815910e99bf9bbf9aa
4
- data.tar.gz: 9c38557ea8c01b9389f69d3115c0ca1c9bb92f00
3
+ metadata.gz: 75b2de8ed584defb06c2f2f621e36b0969f85e97
4
+ data.tar.gz: 86a90c6eba2fa5e15785eb895d38c17ccbe9c5ef
5
5
  SHA512:
6
- metadata.gz: 2d3a8cd1c9732deedec9824a474eeef46c23ffb57064107a2b1b76be49bf5f64d6dad28826922a9d81da6cf3dd7e561a814d3c43cfda4fd6c0c5a90ef0d22d4f
7
- data.tar.gz: f46b7f50651cb77b44118240d7fd3fe03a900a75426181a9522daccef47f389a118507f9384142fe05a086d579be9afbc016b47e97f28cd2e8953991b570668a
6
+ metadata.gz: fd3ada292981142986f465f2a96a7db39a0c39959f41291ed3d01ef42d22307cf96c09d17ce1bf80d05aa4286bfe101ec889bb981672df0288bd2632ce41a425
7
+ data.tar.gz: a0a84730c6ae811ed84843f4fc1cf0f4cc83a9f7e494498336dd814d8953d298ada59d2156e7f6679da9d569fe29dfe64a623d987c61e057fe2e4a38ad5bb081
data/lib/pgversion.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  class PGVersion
6
6
  include Comparable
7
7
 
8
- VERSION = "0.0.2"
8
+ VERSION = "0.0.4"
9
9
 
10
10
  # The major and minor version taken together determine the stable
11
11
  # interface to Postgres. New features may be introduced or breaking
@@ -17,9 +17,8 @@ class PGVersion
17
17
  # changes made when either of these change.
18
18
  attr_reader :minor
19
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.
20
+ # The point release, for release states. Always nil when state is
21
+ # not :release.
23
22
  attr_reader :point
24
23
 
25
24
  # The state of a release: :alpha, :beta, :rc, or :release
@@ -29,7 +28,7 @@ class PGVersion
29
28
  # may go through several revisions in that state before moving to
30
29
  # the next state. Nil when state is :release.
31
30
  attr_reader :revision
32
-
31
+
33
32
  # The host architecture of the given binary
34
33
  attr_reader :host
35
34
  # The compiler used to build the given binary
@@ -58,14 +57,15 @@ class PGVersion
58
57
  def initialize(major, minor, point=nil, host: nil, compiler: nil, bit_depth: nil)
59
58
  @major = major
60
59
  @minor = minor
61
- if point.nil? || point.is_a?(Fixnum)
60
+ if point.is_a?(Integer) || (major >=10 && point.nil?)
62
61
  @point = point
63
62
  @state = :release
64
63
  else
65
64
  verstr_states = ALLOWED_STATES.reject { |s| s == :release }.map(&:to_s)
66
65
  @state, @revision = point.to_s.match(
67
66
  /(#{verstr_states.join('|')})(\d+)/
68
- ) && $1.to_sym, $2.to_i
67
+ ) && $1.to_sym, $2.to_i
68
+ @point = nil
69
69
  unless @state && @revision
70
70
  raise ArgumentError, "Unknown point release: #{point}"
71
71
  end
@@ -74,10 +74,8 @@ class PGVersion
74
74
  @compiler = compiler
75
75
  @bit_depth = bit_depth
76
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.
77
+
78
+ # Compare to another PGVersion.
81
79
  def <=>(other)
82
80
  if self.major < other.major
83
81
  -1
@@ -96,15 +94,7 @@ class PGVersion
96
94
  elsif self_state_idx > other_state_idx
97
95
  1
98
96
  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
97
+ self.point <=> other.point
108
98
  else
109
99
  self.revision <=> other.revision
110
100
  end
@@ -125,7 +115,7 @@ class PGVersion
125
115
 
126
116
  def to_s
127
117
  patch = if release?
128
- ".#{point}" unless point.nil?
118
+ point.nil? ? "" : ".#{point}"
129
119
  else
130
120
  "#{state}#{revision}"
131
121
  end
@@ -147,7 +137,7 @@ class PGVersion
147
137
  attr_reader :state
148
138
 
149
139
  private
150
-
151
- VERSION_REGEXP = /PostgreSQL (\d+)\.(\d+).?((?:alpha|beta|rc)?\d+) on ([^,]+), compiled by ([^,]+), (\d+)-bit/
140
+
141
+ VERSION_REGEXP = /PostgreSQL (\d+)\.(\d+).?((?:alpha|beta|rc)?\d+)? on ([^,]+), compiled by ([^,]+), (\d+)-bit/
152
142
  ALLOWED_STATES = %i(alpha beta rc release)
153
143
  end
@@ -11,8 +11,8 @@ describe PGVersion do
11
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
12
  "PostgreSQL 8.4alpha3 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-16ubuntu6) 4.8.2, 64-bit" =>
13
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)
14
+ "PostgreSQL 10.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,nil, host: 'x86_64-unknown-linux-gnu', compiler: 'gcc (Ubuntu 4.8.2-16ubuntu6) 4.8.2', bit_depth: 64)
16
16
  }.each do |version_str, version|
17
17
  describe '.parse' do
18
18
  it "parses #{version_str} into corresponding version #{version}" do
@@ -35,8 +35,7 @@ describe PGVersion do
35
35
  PGVersion.new(8,3,:rc1),
36
36
  PGVersion.new(8,3,:rc3),
37
37
  PGVersion.new(8,3,0),
38
- PGVersion.new(8,3,1),
39
- PGVersion.new(8,3) ].each do |version|
38
+ PGVersion.new(8,3,1) ].each do |version|
40
39
  it "should format #{version.to_s} as 8.3" do
41
40
  expect(version.major_minor).to eq("8.3")
42
41
  end
@@ -63,7 +62,6 @@ describe PGVersion do
63
62
  PGVersion.new(8,3,:rc3),
64
63
  PGVersion.new(8,3,0),
65
64
  PGVersion.new(8,3,1),
66
- PGVersion.new(8,3),
67
65
  PGVersion.new(8,14,0),
68
66
  PGVersion.new(9,4,0),
69
67
  PGVersion.new(10,0,:alpha1),
@@ -72,10 +70,11 @@ describe PGVersion do
72
70
  PGVersion.new(10,0,:beta2),
73
71
  PGVersion.new(10,0,:rc1),
74
72
  PGVersion.new(10,0,:rc3),
75
- PGVersion.new(10,0,0),
76
- PGVersion.new(10,0,2),
77
- PGVersion.new(10,0,10),
78
- PGVersion.new(10,0)
73
+ PGVersion.new(10,0),
74
+ PGVersion.new(10,2),
75
+ PGVersion.new(10,10),
76
+ PGVersion.new(12,0),
77
+ PGVersion.new(12,1)
79
78
  ].each_with_index.to_a.repeated_permutation(2).each do |(l,lidx), (r,ridx)|
80
79
  expected = lidx <=> ridx
81
80
  it "compares #{l} to #{r} and gets #{expected}" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgversion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciek Sakrejda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-06 00:00:00.000000000 Z
11
+ date: 2017-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  requirements: []
60
60
  rubyforge_project:
61
- rubygems_version: 2.2.2
61
+ rubygems_version: 2.6.8
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Parse Postgres version strings and compare versions