Skip to content

Instantly share code, notes, and snippets.

@skylerto
Created December 19, 2017 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skylerto/0d180c1fb61bfce52db0ffdfd7f8cd57 to your computer and use it in GitHub Desktop.
Save skylerto/0d180c1fb61bfce52db0ffdfd7f8cd57 to your computer and use it in GitHub Desktop.
Structs and attributes: wrapping a Struct in a class
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
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