Class: GoApiClient::Stage

Inherits:
Object
  • Object
show all
Includes:
Helpers::SimpleAttributesSupport
Defined in:
lib/go_api_client/stage.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, attributes = {}) ⇒ Stage

Returns a new instance of Stage.



8
9
10
11
# File 'lib/go_api_client/stage.rb', line 8

def initialize(root, attributes={})
  @root = root
  super(attributes)
end

Instance Attribute Details

#authorsObject

Returns the value of attribute authors.



4
5
6
# File 'lib/go_api_client/stage.rb', line 4

def authors
  @authors
end

#completed_atObject

Returns the value of attribute completed_at.



4
5
6
# File 'lib/go_api_client/stage.rb', line 4

def completed_at
  @completed_at
end

#counterObject

Returns the value of attribute counter.



4
5
6
# File 'lib/go_api_client/stage.rb', line 4

def counter
  @counter
end

#http_fetcherObject

Returns the value of attribute http_fetcher.



4
5
6
# File 'lib/go_api_client/stage.rb', line 4

def http_fetcher
  @http_fetcher
end

#identifierObject

Returns the value of attribute identifier.



4
5
6
# File 'lib/go_api_client/stage.rb', line 4

def identifier
  @identifier
end

#jobsObject

Returns the value of attribute jobs.



4
5
6
# File 'lib/go_api_client/stage.rb', line 4

def jobs
  @jobs
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/go_api_client/stage.rb', line 4

def name
  @name
end

#pipelineObject

Returns the value of attribute pipeline.



4
5
6
# File 'lib/go_api_client/stage.rb', line 4

def pipeline
  @pipeline
end

#pipeline_cacheObject

Returns the value of attribute pipeline_cache.



4
5
6
# File 'lib/go_api_client/stage.rb', line 4

def pipeline_cache
  @pipeline_cache
end

#resultObject

Returns the value of attribute result.



4
5
6
# File 'lib/go_api_client/stage.rb', line 4

def result
  @result
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/go_api_client/stage.rb', line 4

def url
  @url
end

Class Method Details

.from(url, attributes = {}) ⇒ Object



14
15
16
17
18
# File 'lib/go_api_client/stage.rb', line 14

def from(url, attributes = {})
  attributes[:http_fetcher] ||= GoApiClient::HttpFetcher.new
  doc = Nokogiri::XML(attributes[:http_fetcher].get!(url))
  self.new(doc.root, attributes).parse!
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/go_api_client/stage.rb', line 42

def failed?
  "Failed" == @result
end

#parse!Object



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

def parse!
  self.name         = @root.attributes['name'].value
  self.counter      = @root.attributes['counter'].value.to_i
  self.url          = href_from(@root.xpath("./link[@rel='self']"))
  self.result       = @root.xpath("./result").first.content
  self.completed_at = Time.parse(@root.xpath("./updated").first.content).utc
  self.jobs         = @root.xpath("./jobs/job").collect do |job_element|
                        Job.from(job_element.attributes["href"].value, :http_fetcher => http_fetcher)
                      end
  self.identifier   = @root.xpath('./id').first.content

  pipeline_link     = @root.xpath("./pipeline").first.attributes["href"].value

  pipeline = @pipeline_cache[pipeline_link] || Pipeline.from(pipeline_link, :http_fetcher => http_fetcher)
  pipeline.stages << self

  self.pipeline_cache[pipeline_link] ||= pipeline
  @root = nil
  self
end

#passed?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/go_api_client/stage.rb', line 46

def passed?
  !failed?
end