Class: PGVersion
Overview
Represents a Postgres release version. Note that breaking changes generally only happen during major or minor version changes. Point releases are strictly focused on fixing data integrity or security issues.
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Attribute Summary collapse
-
#bit_depth ⇒ Object
readonly
Bit depth of the given binary.
-
#compiler ⇒ Object
readonly
The compiler used to build the given binary.
-
#host ⇒ Object
readonly
The host architecture of the given binary.
-
#major ⇒ Object
readonly
The major and minor version taken together determine the stable interface to Postgres.
-
#minor ⇒ Object
readonly
The major and minor version taken together determine the stable interface to Postgres.
-
#point ⇒ Object
readonly
The point release, for release states.
-
#revision ⇒ Object
readonly
The revision, for non-release states.
Class Method Summary collapse
-
.parse(version_str) ⇒ Object
Parse a Postgres version string, as produced by the function version(), into a PGVersion.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compare to another PGVersion.
- #alpha? ⇒ Boolean
- #beta? ⇒ Boolean
-
#initialize(major, minor, point = nil, host: nil, compiler: nil, bit_depth: nil) ⇒ PGVersion
constructor
Initialize a new PGVersion.
-
#major_minor ⇒ Object
Return the major and minor components of the version as a String, omitting the point release.
- #rc? ⇒ Boolean
- #release? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(major, minor, point = nil, host: nil, compiler: nil, bit_depth: nil) ⇒ PGVersion
Initialize a new PGVersion
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pgversion.rb', line 58 def initialize(major, minor, point=nil, host: nil, compiler: nil, bit_depth: nil) @major = major @minor = minor if point.nil? || point.is_a?(Fixnum) @point = point @state = :release else verstr_states = ALLOWED_STATES.reject { |s| s == :release }.map(&:to_s) @state, @revision = point.to_s.match( /(#{verstr_states.join('|')})(\d+)/ ) && $1.to_sym, $2.to_i unless @state && @revision raise ArgumentError, "Unknown point release: #{point}" end end @host = host @compiler = compiler @bit_depth = bit_depth end |
Instance Attribute Details
#bit_depth ⇒ Object (readonly)
Bit depth of the given binary
38 39 40 |
# File 'lib/pgversion.rb', line 38 def bit_depth @bit_depth end |
#compiler ⇒ Object (readonly)
The compiler used to build the given binary
36 37 38 |
# File 'lib/pgversion.rb', line 36 def compiler @compiler end |
#host ⇒ Object (readonly)
The host architecture of the given binary
34 35 36 |
# File 'lib/pgversion.rb', line 34 def host @host end |
#major ⇒ Object (readonly)
The major and minor version taken together determine the stable interface to Postgres. New features may be introduced or breaking changes made when either of these change.
13 14 15 |
# File 'lib/pgversion.rb', line 13 def major @major end |
#minor ⇒ Object (readonly)
The major and minor version taken together determine the stable interface to Postgres. New features may be introduced or breaking changes made when either of these change.
18 19 20 |
# File 'lib/pgversion.rb', line 18 def minor @minor end |
#point ⇒ Object (readonly)
The point release, for release states. Note that this may be nil, which is considered later than all other releases. Always nil when state is not :release.
23 24 25 |
# File 'lib/pgversion.rb', line 23 def point @point end |
#revision ⇒ Object (readonly)
The revision, for non-release states. A release in a given state may go through several revisions in that state before moving to the next state. Nil when state is :release.
31 32 33 |
# File 'lib/pgversion.rb', line 31 def revision @revision end |
Class Method Details
.parse(version_str) ⇒ Object
Parse a Postgres version string, as produced by the function version(), into a PGVersion.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pgversion.rb', line 42 def self.parse(version_str) result = version_str.match VERSION_REGEXP raise ArgumentError, "Could not parse version string: #{version_str}" unless result point = result[3] if point =~ /\A\d+\Z/ point = point.to_i end PGVersion.new(result[1].to_i, result[2].to_i, point, host: result[4], compiler: result[5], bit_depth: result[6].to_i) end |
Instance Method Details
#<=>(other) ⇒ Object
Compare to another PGVersion. Note that an unspecified point release version is considered higher than every point version of the same state.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/pgversion.rb', line 81 def <=>(other) if self.major < other.major -1 elsif self.major > other.major 1 else if self.minor < other.minor -1 elsif self.minor > other.minor 1 else self_state_idx = ALLOWED_STATES.index(self.state) other_state_idx = ALLOWED_STATES.index(other.state) if self_state_idx < other_state_idx -1 elsif self_state_idx > other_state_idx 1 elsif self.state == :release if self.point.nil? && other.point.nil? 0 elsif other.point.nil? -1 elsif self.point.nil? 1 else self.point <=> other.point end else self.revision <=> other.revision end end end end |
#alpha? ⇒ Boolean
118 |
# File 'lib/pgversion.rb', line 118 def alpha?; @state == :alpha; end |
#beta? ⇒ Boolean
117 |
# File 'lib/pgversion.rb', line 117 def beta?; @state == :beta; end |
#major_minor ⇒ Object
Return the major and minor components of the version as a String, omitting the point release
122 123 124 |
# File 'lib/pgversion.rb', line 122 def major_minor "#{major}.#{minor}" end |
#rc? ⇒ Boolean
116 |
# File 'lib/pgversion.rb', line 116 def rc?; @state == :rc; end |
#release? ⇒ Boolean
115 |
# File 'lib/pgversion.rb', line 115 def release?; @state == :release; end |
#to_s ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/pgversion.rb', line 126 def to_s patch = if release? ".#{point}" unless point.nil? else "#{state}#{revision}" end v = "PostgreSQL #{major}.#{minor}#{patch}" if host v << " on #{host}" end if compiler v << ", compiled by #{compiler}" end if bit_depth v << ", #{bit_depth}-bit" end v end |