class Released::PipelineReader

Public Class Methods

new(filename) click to toggle source
# File lib/released/pipeline_reader.rb, line 3
def initialize(filename)
  @filename = filename
end

Public Instance Methods

read() click to toggle source
# File lib/released/pipeline_reader.rb, line 7
def read
  yaml = transform_root(YAML.load_file(@filename))

  goals = []

  yaml['goals'].each do |goal_yaml|
    name = goal_yaml.keys.first
    config = goal_yaml[name]
    # TODO: what if there are more?

    goals << Released::Goal.named(name.to_sym).new(config)
  end

  goals
end

Private Instance Methods

decrypt(string) click to toggle source
# File lib/released/pipeline_reader.rb, line 70
def decrypt(string)
  stdout = ''
  stderr = ''

  piper = Released::Piper.new(stdout: stdout, stderr: stderr)
  piper.run(['gpg', '--decrypt', '--no-tty'], string)

  stdout
end
transform(obj, vars) click to toggle source
# File lib/released/pipeline_reader.rb, line 30
def transform(obj, vars)
  case obj
  when Hash
    transform_hash(obj, vars)
  when Array
    transform_array(obj, vars)
  when String
    transform_string(obj, vars)
  else
    obj
  end
end
transform_array(array, vars) click to toggle source
# File lib/released/pipeline_reader.rb, line 49
def transform_array(array, vars)
  array.map do |elem|
    transform(elem, vars)
  end
end
transform_hash(hash, vars) click to toggle source
# File lib/released/pipeline_reader.rb, line 43
def transform_hash(hash, vars)
  hash.each_with_object({}) do |(key, value), memo|
    memo[key] = transform(value, vars)
  end
end
transform_root(obj) click to toggle source
# File lib/released/pipeline_reader.rb, line 25
def transform_root(obj)
  vars = transform(obj['vars'], {})
  { 'goals' => transform(obj['goals'], vars) }
end
transform_string(string, vars) click to toggle source
# File lib/released/pipeline_reader.rb, line 55
def transform_string(string, vars)
  case string
  when /\Aenv!(.*)/
    ENV.fetch(Regexp.last_match(1))
  when /\Ash!(.*)/
    `#{Regexp.last_match(1)}`
  when /\Avar!(.*)/
    vars[Regexp.last_match(1)]
  when /\A-----BEGIN PGP MESSAGE-----/
    decrypt(string)
  else
    string
  end
end