Class: SchemaEvolutionManager::Version
- Inherits:
-
Object
- Object
- SchemaEvolutionManager::Version
- Defined in:
- lib/schema-evolution-manager/version.rb
Constant Summary collapse
- VERSION_FILE =
File.join(Library.base_dir, "VERSION")
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
-
.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(version_string) ⇒ 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(version_string) ⇒ Version
Returns a new instance of Version.
9 10 11 12 13 14 15 16 |
# File 'lib/schema-evolution-manager/version.rb', line 9 def initialize(version_string) Preconditions.check_not_blank(version_string, "version_string cannot be blank") Library.assert_valid_tag(version_string) pieces = version_string.split(".", 3) @major = pieces[0].to_i @minor = pieces[1].to_i @micro = pieces[2].to_i 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
64 65 66 67 |
# File 'lib/schema-evolution-manager/version.rb', line 64 def Version.is_valid?(version_string) Preconditions.check_not_blank(version_string, "version_string cannot be blank") version_string.match(/^\d+\.\d+\.\d+$/) end |
.read ⇒ Object
Reads the current version (from the VERSION FILE), returning an instance of the Version class
51 52 53 54 55 |
# File 'lib/schema-evolution-manager/version.rb', line 51 def Version.read Preconditions.check_state(File.exists?(VERSION_FILE), "Version file at path[%s] not found" % VERSION_FILE) version = IO.read(VERSION_FILE).strip Version.new(version) end |
.write(version) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/schema-evolution-manager/version.rb', line 57 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
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/schema-evolution-manager/version.rb', line 37 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
23 24 25 |
# File 'lib/schema-evolution-manager/version.rb', line 23 def next_major Version.new("%s.%s.%s" % [major+1, 0, 0]) end |
#next_micro ⇒ Object
Returns the next micro version
33 34 35 |
# File 'lib/schema-evolution-manager/version.rb', line 33 def next_micro Version.new("%s.%s.%s" % [major, minor, micro+1]) end |
#next_minor ⇒ Object
Returns the next minor version
28 29 30 |
# File 'lib/schema-evolution-manager/version.rb', line 28 def next_minor Version.new("%s.%s.%s" % [major, minor+1, 0]) end |
#to_version_string ⇒ Object
18 19 20 |
# File 'lib/schema-evolution-manager/version.rb', line 18 def to_version_string "%s.%s.%s" % [major, minor, micro] end |