Class: SchemaEvolutionManager::Version
- Inherits:
-
Object
- Object
- SchemaEvolutionManager::Version
- Defined in:
- lib/schema-evolution-manager/version.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#micro ⇒ Object
readonly
Returns the value of attribute micro.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
Class Method Summary collapse
- .is_valid?(version_string) ⇒ Boolean
- .parse(version_string) ⇒ Object
-
.read ⇒ Object
Reads the current version (from the VERSION FILE), returning an instance of the Version class.
- .write(version) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(major, minor, micro, opts = {}) ⇒ Version
constructor
A new instance of Version.
-
#next_major ⇒ Object
Returns the next major version.
-
#next_micro ⇒ Object
Returns the next micro version.
-
#next_minor ⇒ Object
Returns the next minor version.
- #to_version_string ⇒ Object
Constructor Details
#initialize(major, minor, micro, opts = {}) ⇒ Version
Returns a new instance of Version.
9 10 11 12 13 14 15 16 17 |
# File 'lib/schema-evolution-manager/version.rb', line 9 def initialize(major, minor, micro, opts={}) @major = major.to_i @minor = minor.to_i @micro = micro.to_i @prefix = opts.delete(:prefix) || nil if !opts.empty? raise "Invalid keys: " + opts.keys end end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
7 8 9 |
# File 'lib/schema-evolution-manager/version.rb', line 7 def major @major end |
#micro ⇒ Object (readonly)
Returns the value of attribute micro.
7 8 9 |
# File 'lib/schema-evolution-manager/version.rb', line 7 def micro @micro end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
7 8 9 |
# File 'lib/schema-evolution-manager/version.rb', line 7 def minor @minor end |
Class Method Details
.is_valid?(version_string) ⇒ Boolean
75 76 77 78 |
# File 'lib/schema-evolution-manager/version.rb', line 75 def Version.is_valid?(version_string) Preconditions.check_not_blank(version_string, "version_string cannot be blank") version_string.match(/^\w*\d+\.\d+\.\d+$/) ? true : false end |
.parse(version_string) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/schema-evolution-manager/version.rb', line 19 def Version.parse(version_string) Preconditions.check_not_blank(version_string, "version_string cannot be blank") Library.assert_valid_tag(version_string) if md = version_string.match(/^(\w*)(\d+)\.(\d+)\.(\d+)$/) Version.new(md[2], md[3], md[4], :prefix => md[1]) else raise "ERROR: Bug in version string parser for version[%s]" % version_string end end |
.read ⇒ Object
Reads the current version (from the VERSION FILE), returning an instance of the Version class
62 63 64 65 66 |
# File 'lib/schema-evolution-manager/version.rb', line 62 def Version.read Preconditions.check_state(File.exist?(VERSION_FILE), "Version file at path[%s] not found" % VERSION_FILE) version = IO.read(VERSION_FILE).strip Version.parse(version) end |
.write(version) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/schema-evolution-manager/version.rb', line 68 def Version.write(version) Preconditions.assert_class(version, Version) File.open(VERSION_FILE, "w") do |out| out << "%s\n" % version.to_version_string end end |
Instance Method Details
#<=>(other) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/schema-evolution-manager/version.rb', line 48 def <=>(other) Preconditions.assert_class(other, Version) value = major <=> other.major if value == 0 value = minor <=> other.minor if value == 0 value = micro <=> other.micro end end value end |
#next_major ⇒ Object
Returns the next major version
34 35 36 |
# File 'lib/schema-evolution-manager/version.rb', line 34 def next_major Version.new(major+1, 0, 0, :prefix => @prefix) end |
#next_micro ⇒ Object
Returns the next micro version
44 45 46 |
# File 'lib/schema-evolution-manager/version.rb', line 44 def next_micro Version.new(major, minor, micro+1, :prefix => @prefix) end |
#next_minor ⇒ Object
Returns the next minor version
39 40 41 |
# File 'lib/schema-evolution-manager/version.rb', line 39 def next_minor Version.new(major, minor+1, 0, :prefix => @prefix) end |
#to_version_string ⇒ Object
29 30 31 |
# File 'lib/schema-evolution-manager/version.rb', line 29 def to_version_string "%s%s.%s.%s" % [@prefix, major, minor, micro] end |