Class: AutomateSoup::Change
- Inherits:
-
Object
- Object
- AutomateSoup::Change
- Defined in:
- lib/automate_soup/change.rb
Overview
Class to represent operations on a change.
Instance Method Summary collapse
-
#approvable? ⇒ Boolean
Determine if the change is approvable.
-
#approve ⇒ Object
Approve this change.
-
#current_stage ⇒ AutomateSoup::Stage
Determing the current stage of the change.
-
#deliver ⇒ Object
Deliver this change.
-
#deliverable? ⇒ Boolean
Determine if the change is deliverable.
-
#delivered? ⇒ Boolean
Determine if the change has been delivered successfully.
-
#initialize(hash) ⇒ Change
constructor
A new instance of Change.
-
#links ⇒ Object
Wrapper for the _links property on the struct.
-
#method_missing(method, *args, &block) ⇒ Object
Delegate method missing to the underlying OpenStruct.
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.
62 63 64 65 66 67 68 69 70 |
# File 'lib/automate_soup/change.rb', line 62 def approvable? (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 ⇒ Object
Approve this change.
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/automate_soup/change.rb', line 74 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' 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_stage ⇒ AutomateSoup::Stage
Determing the current stage of the change.
22 23 24 |
# File 'lib/automate_soup/change.rb', line 22 def current_stage Stage.new @source.stages.last end |
#deliver ⇒ Object
Deliver this change.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/automate_soup/change.rb', line 90 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' 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.
48 49 50 51 52 53 54 55 56 |
# File 'lib/automate_soup/change.rb', line 48 def deliverable? (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.
37 38 39 40 41 42 |
# File 'lib/automate_soup/change.rb', line 37 def delivered? (current_stage.stage.eql?('delivered') && current_stage.status.eql?('passed') && !AutomateSoup.url.nil? && !AutomateSoup.credentials.nil?) end |
#links ⇒ Object
Wrapper for the _links property on the struct
29 30 31 |
# File 'lib/automate_soup/change.rb', line 29 def links @source._links end |