Class: Gitlab::Database::Migrations::Version

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/gitlab/database/migrations/version.rb

Constant Summary collapse

InvalidTypeError =
Class.new(StandardError)
TYPE_VALUES =
{
  regular: 0,
  post: 1
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timestamp, milestone, type) ⇒ Version

Returns a new instance of Version.



18
19
20
21
22
# File 'lib/gitlab/database/migrations/version.rb', line 18

def initialize(timestamp, milestone, type)
  @timestamp = timestamp
  @milestone = Gitlab::VersionInfo.parse_from_milestone(milestone)
  self.type = type
end

Instance Attribute Details

#milestoneObject

Returns the value of attribute milestone.



16
17
18
# File 'lib/gitlab/database/migrations/version.rb', line 16

def milestone
  @milestone
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



16
17
18
# File 'lib/gitlab/database/migrations/version.rb', line 16

def timestamp
  @timestamp
end

#type_valueObject (readonly)

Returns the value of attribute type_value.



16
17
18
# File 'lib/gitlab/database/migrations/version.rb', line 16

def type_value
  @type_value
end

Instance Method Details

#<=>(other) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gitlab/database/migrations/version.rb', line 44

def <=>(other)
  return 0 if other.is_a?(Integer) && @timestamp == other

  return 1 unless other.is_a?(self.class)

  compare_milestones = milestone <=> other.milestone
  return compare_milestones if compare_milestones != 0

  return @type_value <=> other.type_value if @type_value != other.type_value

  @timestamp <=> other.timestamp
end

#==(other) ⇒ Object



73
74
75
# File 'lib/gitlab/database/migrations/version.rb', line 73

def ==(other)
  eql?(other)
end

#coerce(_) ⇒ Object



65
66
67
# File 'lib/gitlab/database/migrations/version.rb', line 65

def coerce(_)
  [-1, timestamp.to_i]
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/gitlab/database/migrations/version.rb', line 69

def eql?(other)
  (self <=> other) == 0
end

#hashObject



77
78
79
# File 'lib/gitlab/database/migrations/version.rb', line 77

def hash
  timestamp.hash
end

#post_deployment?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/gitlab/database/migrations/version.rb', line 40

def post_deployment?
  @type_value == TYPE_VALUES[:post]
end

#regular?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/gitlab/database/migrations/version.rb', line 36

def regular?
  @type_value == TYPE_VALUES[:regular]
end

#to_iObject



61
62
63
# File 'lib/gitlab/database/migrations/version.rb', line 61

def to_i
  @timestamp.to_i
end

#to_sObject



57
58
59
# File 'lib/gitlab/database/migrations/version.rb', line 57

def to_s
  @timestamp.to_s
end

#typeObject



24
25
26
# File 'lib/gitlab/database/migrations/version.rb', line 24

def type
  TYPE_VALUES.key(@type_value)
end

#type=(value) ⇒ Object



28
29
30
# File 'lib/gitlab/database/migrations/version.rb', line 28

def type=(value)
  @type_value = TYPE_VALUES.fetch(value.to_sym) { raise InvalidTypeError }
end