class AutomateSoup::Change

Class to represent operations on a change.

Public Class Methods

new(hash) click to toggle source
# File lib/automate_soup/change.rb, line 8
def initialize(hash)
  @source = OpenStruct.new hash
end

Public Instance Methods

approvable?() click to toggle source

Determine if the change is approvable.

@return [Boolean] if this change is approvable

# File lib/automate_soup/change.rb, line 66
def approvable?
  (!current_stage.nil? &&
   current_stage.stage.eql?('verify') &&
   current_stage.status.eql?('passed') &&
   !AutomateSoup.url.nil? &&
   !AutomateSoup.credentials.nil? &&
   !links.nil? &&
   !links['approve'].nil? &&
   !links['approve']['href'].nil?)
end
approve() click to toggle source

Approve this change. Raise exceptions where applicable.

@return [Boolean] true if the change was approved, false otherwise.

# File lib/automate_soup/change.rb, line 81
def approve
  return nil if current_stage.stage != 'verify'
  raise 'Must run AutomateSoup.setup first' if AutomateSoup.url.nil? || AutomateSoup.credentials.nil?
  raise "Approve link not available, #{links.inspect}" if links.nil? || links['approve'].nil? || links['approve']['href'].nil?
  url = links['approve']['href']
  url = "#{AutomateSoup.url}#{url}" unless url.include?('http')
  res = AutomateSoup::Rest.post(
    url: url,
    username: AutomateSoup.credentials.username,
    token: AutomateSoup.credentials.token
  )
  raise "Failed to approve change: #{res.code}" if res.code != '204'
  true
end
current_stage() click to toggle source

Determing the current stage of the change. @return [AutomateSoup::Stage] the current stage.

# File lib/automate_soup/change.rb, line 22
def current_stage
  stages = @source.stages
  return Stage.new(stages.last) unless stages.nil? || stages.empty?
  nil
end
deliver() click to toggle source

Deliver this change. Raise exceptions where applicable.

@return [Boolean] true if the change was delivered, false otherwise.

# File lib/automate_soup/change.rb, line 100
def deliver
  raise 'Must approve change first' if current_stage.stage.eql? 'verify'
  return nil if current_stage.stage != 'acceptance'
  raise 'Must run AutomateSoup.setup first' if AutomateSoup.url.nil? || AutomateSoup.credentials.nil?
  raise "Deliver link not available, #{links.inspect}" if links.nil? || links['deliver'].nil? || links['deliver']['href'].nil?
  url = links['deliver']['href']
  url = "#{AutomateSoup.url}#{url}" unless url.include?('http')
  res = AutomateSoup::Rest.post(
    url: url,
    username: AutomateSoup.credentials.username,
    token: AutomateSoup.credentials.token
  )
  raise "Failed to deliver change: #{res.code}" if res.code != '204'
  true
end
deliverable?() click to toggle source

Determine if the change is deliverable.

@return [Boolean] if this change is deliverable

# File lib/automate_soup/change.rb, line 51
def deliverable?
  (!current_stage.nil? &&
   current_stage.stage.eql?('acceptance') &&
   current_stage.status.eql?('passed') &&
   !AutomateSoup.url.nil? &&
   !AutomateSoup.credentials.nil? &&
   !links.nil? &&
   !links['deliver'].nil? &&
   !links['deliver']['href'].nil?)
end
delivered?() click to toggle source

Determine if the change has been delivered successfully.

@return [Boolean] if this change is delivered

# File lib/automate_soup/change.rb, line 39
def delivered?
  (!current_stage.nil? &&
   current_stage.stage.eql?('delivered') &&
   current_stage.status.eql?('passed') &&
   !AutomateSoup.url.nil? &&
   !AutomateSoup.credentials.nil?)
end
method_missing(method, *args, &block) click to toggle source

Delegate method missing to the underlying OpenStruct

# File lib/automate_soup/change.rb, line 15
def method_missing(method, *args, &block)
  @source.send(method, *args, &block)
end