Class: Deployed::RepoData

Inherits:
Object
  • Object
show all
Defined in:
lib/deployed.rb

Instance Method Summary collapse

Instance Method Details

#branch ⇒ Object



15
16
17
# File 'lib/deployed.rb', line 15

def branch
  @branch ||= git_branch || read_file('BRANCH').strip.presence
end

#extra ⇒ Object



59
60
61
# File 'lib/deployed.rb', line 59

def extra
  @extra ||= version(:extra)
end

#label ⇒ Object



43
44
45
# File 'lib/deployed.rb', line 43

def label
  tag.presence || branch
end

#major ⇒ Object



47
48
49
# File 'lib/deployed.rb', line 47

def major
  @major ||= version(:major)
end

#minor ⇒ Object



51
52
53
# File 'lib/deployed.rb', line 51

def minor
  @minor ||= version(:minor)
end

#patch ⇒ Object



55
56
57
# File 'lib/deployed.rb', line 55

def patch
  @patch ||= version(:patch)
end

#release ⇒ Object



19
20
21
# File 'lib/deployed.rb', line 19

def release
  @release ||= read_file('RELEASE').strip
end

#release_timestamp ⇒ Object

Return the time of the release as a modified ISO 8601 string. If the release name is a 14 digit string (e.g. 20231025123000), it is assumed to be a timestamp. If no RELEASE file exists or the content is not a valid timestamp, the current time is returned.



30
31
32
33
34
35
36
37
# File 'lib/deployed.rb', line 30

def release_timestamp
  timestamp = if release.match?(/^\d{14}$/)
    DateTime.strptime(release, '%Y%m%d%H%M%S')
  else
    DateTime.now
  end
  timestamp.strftime('%FT%H:%M:%S')
end

#release_url ⇒ Object



23
24
25
# File 'lib/deployed.rb', line 23

def release_url
  @release_url ||= read_file('REPO').strip
end

#revision ⇒ Object



11
12
13
# File 'lib/deployed.rb', line 11

def revision
  @revision ||= git_rev || read_file('REVISION').strip.presence
end

#revision_short ⇒ Object



39
40
41
# File 'lib/deployed.rb', line 39

def revision_short
  @revision_short ||= revision&.slice 0..6
end

#tag ⇒ Object



7
8
9
# File 'lib/deployed.rb', line 7

def tag
  @tag ||= git_tag || read_file('TAG').strip.presence
end

#version_hash ⇒ Object



63
64
65
# File 'lib/deployed.rb', line 63

def version_hash
  @version_hash ||= /\Av(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?<extra>\S*)/.match(label)
end

#version_label ⇒ Object



67
68
69
# File 'lib/deployed.rb', line 67

def version_label
  major == 0 && minor == 0 && patch == 0 ? 'WIP' : "#{major}.#{minor}.#{patch}"
end