Class: Scc::DeployInfo::Extractor::File

Inherits:
Dummy
  • Object
show all
Defined in:
lib/scc/deploy_info/extractor/file.rb

Defined Under Namespace

Classes: ManifestEmpty, ManifestInvalid, ManifestNotFound

Instance Method Summary collapse

Constructor Details

#initialize(filename: "deploy_info.yml") ⇒ File

Returns a new instance of File.



20
21
22
23
# File 'lib/scc/deploy_info/extractor/file.rb', line 20

def initialize(filename: "deploy_info.yml")
  @filename = filename
  @origin = "file"
end

Instance Method Details

#callObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/scc/deploy_info/extractor/file.rb', line 25

def call
  loaded_yaml = YAML.safe_load_file(@filename, permitted_classes: [::Date, ::Time, ::DateTime],
    symbolize_names: true)

  raise ManifestEmpty, "Deploy manifest is empty" unless loaded_yaml
  raise ManifestInvalid, "Deploy manifest is not a hash" unless loaded_yaml.is_a?(Hash)

  deploy_info = super.merge(loaded_yaml.compact)

  deploy_info[:origin] = "FILE"
  deploy_info[:commit_date] = Scc::Utils.try_parse_date(deploy_info[:commit_date])
  deploy_info
rescue ::Errno::ENOENT, Errno::EISDIR
  raise ManifestNotFound, "Could not find manifest file in #{@filename}"
rescue ::Psych::Exception # YAML parsing errors
  raise ManifestInvalid, "Could not parse YAML from manifest file"
end