Class: AutomateSoup::Change

Inherits:
Object
  • Object
show all
Defined in:
lib/automate_soup/change.rb

Overview

Class to represent operations on a change.

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Change

Returns a new instance of Change.



8
9
10
# File 'lib/automate_soup/change.rb', line 8

def initialize(hash)
  @source = OpenStruct.new hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Delegate method missing to the underlying OpenStruct



15
16
17
# File 'lib/automate_soup/change.rb', line 15

def method_missing(method, *args, &block)
  @source.send(method, *args, &block)
end

Instance Method Details

#approvable?Boolean

Determine if the change is approvable.

Returns:

  • (Boolean)

    if this change is approvable



66
67
68
69
70
71
72
73
74
75
# 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

#approveBoolean

Approve this change. Raise exceptions where applicable.

Returns:

  • (Boolean)

    true if the change was approved, false otherwise.



81
82
83
84
85
86
87
88
89
90
91
92
93
# 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 = "#{AutomateSoup.url}#{links['approve']['href']}"
  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_stageAutomateSoup::Stage

Determing the current stage of the change.

Returns:



22
23
24
25
26
# 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

#deliverBoolean

Deliver this change. Raise exceptions where applicable.

Returns:

  • (Boolean)

    true if the change was delivered, false otherwise.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/automate_soup/change.rb', line 99

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 = "#{AutomateSoup.url}#{links['deliver']['href']}"
  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?Boolean

Determine if the change is deliverable.

Returns:

  • (Boolean)

    if this change is deliverable



51
52
53
54
55
56
57
58
59
60
# 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?Boolean

Determine if the change has been delivered successfully.

Returns:

  • (Boolean)

    if this change is delivered



39
40
41
42
43
44
45
# 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

Wrapper for the _links property on the struct



31
32
33
# File 'lib/automate_soup/change.rb', line 31

def links
  @source._links
end