Class: GoFigure::GoConfig

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

Defined Under Namespace

Classes: PipelineConfig

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GoConfig

Returns a new instance of GoConfig.



9
10
11
12
13
14
# File 'lib/go_figure/go_config.rb', line 9

def initialize(options = {})
  @original_md5 = options[:md5]
  @original_xml = options[:xml]
  @doc = Nokogiri.XML(@original_xml, nil, 'utf-8')
  @params = {}
end

Instance Attribute Details

#original_md5Object

Returns the value of attribute original_md5.



6
7
8
# File 'lib/go_figure/go_config.rb', line 6

def original_md5
  @original_md5
end

#original_xmlObject (readonly)

Returns the value of attribute original_xml.



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

def original_xml
  @original_xml
end

Instance Method Details

#pipeline_template(git_url, working_dir) ⇒ Object



42
43
44
45
# File 'lib/go_figure/go_config.rb', line 42

def pipeline_template(git_url, working_dir)
  template = ERB.new(File.read(File.expand_path('../../go-pipelines.xml.erb', __FILE__)))
  template.result(PipelineConfig.new(git_url, working_dir, @params).get_binding)
end

#set_auto_registration_key(key) ⇒ Object



16
17
18
# File 'lib/go_figure/go_config.rb', line 16

def set_auto_registration_key(key)
  @doc.root.xpath('server').first["agentAutoRegisterKey"] = key
end

#set_pipeline(git_url, working_dir) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/go_figure/go_config.rb', line 20

def set_pipeline(git_url, working_dir)
  @doc.root.xpath('pipelines').remove
  agents = @doc.root.xpath('agents')

  if agents.any?
    agents.before(pipeline_template(git_url, working_dir))
  else
    @doc.root << pipeline_template(git_url, working_dir)
  end

  @doc = Nokogiri.XML(@doc.to_s) do |config|
    config.default_xml.noblanks
  end

  puts "************************************"
  puts "Set new pipeline:"
  puts xml_content
  puts "************************************"

  @doc
end

#set_rspecObject



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

def set_rspec
  @params[:rspec] = true
end

#set_test_unitObject



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

def set_test_unit
  @params[:test_unit] = true
end

#xml_contentObject



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

def xml_content
  @doc.to_s
end