Created
December 19, 2017 13:42
-
-
Save skylerto/0d180c1fb61bfce52db0ffdfd7f8cd57 to your computer and use it in GitHub Desktop.
Structs and attributes: wrapping a Struct in a class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ostruct' | |
module AutomateSoup | |
## | |
# Class to represent operations on a change. | |
# | |
class Change | |
def initialize(hash) | |
@source = OpenStruct.new hash | |
end | |
## | |
# Delegate method missing to the underlying OpenStruct | |
# | |
def method_missing(method, *args, &block) | |
@source.send(method, *args, &block) | |
end | |
## | |
# Determing the current stage of the change. | |
# @return [AutomateSoup::Stage] the current stage. | |
def current_stage | |
Stage.new @source.stages.last | |
end | |
## | |
# Determine if the change has been delivered successfully. | |
# | |
# @return [Boolean] if this change is delivered | |
def delivered? | |
(current_stage.stage.eql?('delivered') && | |
current_stage.status.eql?('passed') && | |
!AutomateSoup.url.nil? && | |
!AutomateSoup.credentials.nil?) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
change = soup.change | |
if wait && !change.approvable? && !change.deliverable? | |
times = 1 | |
while times <= retries | |
change = soup.change | |
break if change.approvable? | |
return false if change.current_stage.failed? | |
puts "Stage #{change.current_stage.stage}: #{change.current_stage.status} retries #{times}/#{retries}" | |
sleep timeout | |
times += 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment