Class: Scc::DeployInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/scc/deploy_info.rb,
lib/scc/deploy_info/extractor/git.rb,
lib/scc/deploy_info/extractor/file.rb,
lib/scc/deploy_info/extractor/dummy.rb,
lib/scc/deploy_info/extractor/error.rb

Defined Under Namespace

Modules: Extractor

Constant Summary collapse

NULLABLE_ATTRS =
i[deploy_ref commit_sha commit_date commit_subject origin]
SENTINEL =
"UNKNOWN"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(extractor: nil) ⇒ DeployInfo

Returns a new instance of DeployInfo.



14
15
16
17
18
19
20
21
# File 'lib/scc/deploy_info.rb', line 14

def initialize(extractor: nil)
  @deploy_ref = deploy_ref
  @commit_sha = commit_sha
  @commit_date = commit_date
  @commit_subject = commit_subject
  @origin = origin
  @extractor = extractor || Extractor::Dummy.new
end

Instance Attribute Details

#formatted_dateObject (readonly)

Returns the value of attribute formatted_date.



12
13
14
# File 'lib/scc/deploy_info.rb', line 12

def formatted_date
  @formatted_date
end

Class Method Details

.for_env(env, root: nil, filename: nil) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/scc/deploy_info.rb', line 61

def self.for_env(env, root: nil, filename: nil)
  if %w[test development].include?(env)
    return from_git(root: root).extract!
  end
  from_file(filename: filename).extract!
rescue DeployInfo::Extractor::Error
  new.extract!
end

.from_file(filename: nil) ⇒ Object



56
57
58
59
# File 'lib/scc/deploy_info.rb', line 56

def self.from_file(filename: nil)
  filename ||= "deploy_info.yml"
  new(extractor: Extractor::File.new(filename: filename))
end

.from_git(root: nil) ⇒ Object



51
52
53
54
# File 'lib/scc/deploy_info.rb', line 51

def self.from_git(root: nil)
  root ||= "."
  new(extractor: Extractor::Git.new(root: root))
end

Instance Method Details

#extract!Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/scc/deploy_info.rb', line 39

def extract!
  attrs = @extractor.call
  NULLABLE_ATTRS.each do |key|
    value = attrs[key]
    value = SENTINEL if value.nil? || (value.is_a?(String) && value.empty?)

    send("#{key}=".to_sym, value)
  end

  self
end

#short_shaObject



23
# File 'lib/scc/deploy_info.rb', line 23

def short_sha = commit_sha.to_s[..7]

#to_poroObject



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

def to_poro
  {
    "deploy_ref" => deploy_ref,
    "commit_sha" => commit_sha,
    "commit_date" => commit_date,
    "commit_subject" => commit_subject,
    "origin" => origin
  }
end

#version_stringObject



25
26
27
# File 'lib/scc/deploy_info.rb', line 25

def version_string
  "#{deploy_ref}/#{short_sha} @ #{formatted_date}"
end