Class: GoApiClient::Parsers::Config::Stage

Inherits:
Helper
  • Object
show all
Defined in:
lib/go_api_client/parsers/config/stage_parser.rb

Class Method Summary collapse

Methods inherited from Helper

href_from

Class Method Details

.parse(root) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/go_api_client/parsers/config/stage_parser.rb', line 6

def parse(root)

  jobs = root.xpath('./jobs/job').collect do |element|
    GoApiClient::Parsers::Config::Job.parse(element)
  end if root.xpath('./jobs/job')

  env_vars = root.xpath('./environmentvariables/variable').collect do |element|
    secure = true if element.attributes['name']
    value_element = element.xpath('./value').first ? element.xpath('./value') : element.xpath('./encryptedValue')
    {:name => element.attributes['name'].value, :secure => secure, :value => value_element.first.content}
  end if root.xpath('./params/param')

  GoApiClient::Domain::Config::Stage.new(
      {
          :name => root.attributes['name'].value,
          :clean_working_dir => root.attributes['cleanWorkingDir'] ? root.attributes['cleanWorkingDir'].value : 'false',
          :fetch_materials => root.attributes['fetchMaterials'] ? root.attributes['fetchMaterials'].value : 'false',
          :approval =>  root.xpath('./approval').first ? root.xpath('./approval').first.attributes['type'].value : 'automatic',
          :parsed_jobs => jobs,
          :parsed_env_vars => env_vars
      })
end