Class: Cassie::Schema::Version
- Includes:
- Comparable
- Defined in:
- lib/cassie/schema/version.rb
Constant Summary collapse
- PARTS =
[:major, :minor, :patch, :build].freeze
Instance Attribute Summary collapse
-
#build ⇒ Object
readonly
The build part of the semantic version.
-
#description ⇒ String
The description of the changes introduced in this version.
-
#executed_at ⇒ DateTime
The time this version was migrated up.
-
#executor ⇒ String
The OS username of the user that migrated this version up.
-
#id ⇒ Cassandra::TimeUuid
The version uuid, if persisted.
-
#major ⇒ Object
readonly
The major part of the semantic version.
-
#migration ⇒ Cassie::Schema::Migration?
readonly
The migration associated with this version.
-
#minor ⇒ Object
readonly
The minor part of the semantic version.
-
#parts ⇒ Array<Fixnum>
The major, minor, patch, and build parts making up the semantic version.
-
#patch ⇒ Object
readonly
The patch part of the semantic version.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compares versions by semantic version number.
- #hash ⇒ Object
-
#initialize(version_number, description = nil, id = nil, executor = nil, executed_at = nil) ⇒ Version
constructor
A new instance of Version.
-
#migration_class_name ⇒ Object
The migration class name, as implied by the version number.
-
#next(bump_type = nil) ⇒ Version
Builds a new version, wiht a version number incremented from this object’s version.
- #number ⇒ Object
-
#recorded? ⇒ Boolean
Indicating whether the version has been persisted in the schema metatdata versions persistence store.
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(version_number, description = nil, id = nil, executor = nil, executed_at = nil) ⇒ Version
Returns a new instance of Version.
23 24 25 26 27 28 29 |
# File 'lib/cassie/schema/version.rb', line 23 def initialize(version_number, description=nil, id=nil, executor=nil, executed_at=nil) @parts = build_parts(version_number) @description = description @id = id @executor = executor @executed_at = executed_at end |
Instance Attribute Details
#build ⇒ Object (readonly)
The build part of the semantic version
55 56 57 |
# File 'lib/cassie/schema/version.rb', line 55 def build parts[3].to_i end |
#description ⇒ String
The description of the changes introduced in this version
14 15 16 |
# File 'lib/cassie/schema/version.rb', line 14 def description @description end |
#executed_at ⇒ DateTime
The time this version was migrated up
20 21 22 |
# File 'lib/cassie/schema/version.rb', line 20 def executed_at @executed_at end |
#executor ⇒ String
The OS username of the user that migrated this version up
17 18 19 |
# File 'lib/cassie/schema/version.rb', line 17 def executor @executor end |
#id ⇒ Cassandra::TimeUuid
The version uuid, if persisted
8 9 10 |
# File 'lib/cassie/schema/version.rb', line 8 def id @id end |
#major ⇒ Object (readonly)
The major part of the semantic version
37 38 39 |
# File 'lib/cassie/schema/version.rb', line 37 def major parts[0].to_i end |
#migration ⇒ Cassie::Schema::Migration? (readonly)
The migration associated with this version
114 115 116 117 118 119 120 |
# File 'lib/cassie/schema/version.rb', line 114 def migration @migration ||= begin migration_class_name.constantize.new rescue NameError nil end end |
#minor ⇒ Object (readonly)
The minor part of the semantic version
43 44 45 |
# File 'lib/cassie/schema/version.rb', line 43 def minor parts[1].to_i end |
#parts ⇒ Array<Fixnum>
The major, minor, patch, and build parts making up the semantic version
11 12 13 |
# File 'lib/cassie/schema/version.rb', line 11 def parts @parts end |
#patch ⇒ Object (readonly)
The patch part of the semantic version
49 50 51 |
# File 'lib/cassie/schema/version.rb', line 49 def patch parts[2].to_i end |
Instance Method Details
#<=>(other) ⇒ Object
Compares versions by semantic version number
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cassie/schema/version.rb', line 81 def <=>(other) case other when Version Gem::Version.new(self.number) <=> Gem::Version.new(other.number) when String Gem::Version.new(self.number) <=> Gem::Version.new(other) else nil end end |
#hash ⇒ Object
99 100 101 |
# File 'lib/cassie/schema/version.rb', line 99 def hash parts.hash end |
#migration_class_name ⇒ Object
The migration class name, as implied by the version number
107 108 109 |
# File 'lib/cassie/schema/version.rb', line 107 def migration_class_name "Migration_#{major}_#{minor}_#{patch}_#{build}" end |
#next(bump_type = nil) ⇒ Version
Builds a new version, wiht a version number incremented from this object’s version. Does not propogate any other attributes
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cassie/schema/version.rb', line 67 def next(bump_type=nil) bump_type ||= :patch bump_index = PARTS.index(bump_type.to_sym) # 0.2.1 - > 0.2 bumped_parts = parts.take(bump_index + 1) # 0.2 - > 0.3 bumped_parts[bump_index] = bumped_parts[bump_index].to_i + 1 # 0.3 - > 0.3.0.0 bumped_parts += [0]*(PARTS.length - (bump_index + 1)) self.class.new(bumped_parts.join('.')) end |
#number ⇒ Object
31 32 33 |
# File 'lib/cassie/schema/version.rb', line 31 def number parts.join('.') end |
#recorded? ⇒ Boolean
Returns indicating whether the version has been persisted in the schema metatdata versions persistence store.
95 96 97 |
# File 'lib/cassie/schema/version.rb', line 95 def recorded? !!self.id end |
#to_h ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/cassie/schema/version.rb', line 122 def to_h { id: id, number: number, description: description, executor: executor, executed_at: executed_at } end |
#to_s ⇒ Object
132 133 134 |
# File 'lib/cassie/schema/version.rb', line 132 def to_s number end |