Class: Anvil::Workflow
- Inherits:
-
Resources::Base
- Object
- Resources::Base
- Anvil::Workflow
- Defined in:
- lib/anvil/resources/workflow.rb
Instance Attribute Summary
Attributes inherited from Resources::Base
Class Method Summary collapse
-
.create(name:, **options) ⇒ Workflow
Create a new workflow.
-
.find(workflow_eid, client: nil) ⇒ Workflow
Find a workflow by EID.
Instance Method Summary collapse
- #draft? ⇒ Boolean
- #eid ⇒ Object
- #id ⇒ Object
- #name ⇒ Object
- #published? ⇒ Boolean
-
#reload! ⇒ Object
Reload from API.
- #slug ⇒ Object
-
#start(data: {}) ⇒ Hash
Start the workflow with initial data.
- #status ⇒ Object
-
#submissions(limit: 10, offset: 0) ⇒ Array<Hash>
Get submissions for this workflow.
Methods inherited from Resources::Base
#==, build_from_response, #initialize, #inspect, list, #method_missing, #respond_to_missing?, #to_h, #to_json, with_client
Constructor Details
This class inherits a constructor from Anvil::Resources::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Anvil::Resources::Base
Class Method Details
.create(name:, **options) ⇒ Workflow
Create a new workflow
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/anvil/resources/workflow.rb', line 79 def create(name:, **) api_key = .delete(:api_key) client = api_key ? Client.new(api_key: api_key) : self.client payload = { name: name } payload[:slug] = [:slug] if [:slug] payload[:forges] = [:forges] if [:forges] payload[:casts] = [:casts] if [:casts] result = client.graphql(create_weld_mutation, variables: { input: payload }) raise APIError, "Failed to create workflow: #{result}" unless result && result[:createWeld] new(result[:createWeld], client: client) end |
.find(workflow_eid, client: nil) ⇒ Workflow
Find a workflow by EID
99 100 101 102 103 104 105 106 |
# File 'lib/anvil/resources/workflow.rb', line 99 def find(workflow_eid, client: nil) client ||= self.client result = client.graphql(weld_query, variables: { eid: workflow_eid }) raise NotFoundError, "Workflow not found: #{workflow_eid}" unless result && result[:weld] new(result[:weld], client: client) end |
Instance Method Details
#draft? ⇒ Boolean
29 30 31 |
# File 'lib/anvil/resources/workflow.rb', line 29 def draft? status == 'draft' end |
#eid ⇒ Object
9 10 11 |
# File 'lib/anvil/resources/workflow.rb', line 9 def eid attributes[:eid] end |
#id ⇒ Object
5 6 7 |
# File 'lib/anvil/resources/workflow.rb', line 5 def id attributes[:eid] || attributes[:id] end |
#name ⇒ Object
13 14 15 |
# File 'lib/anvil/resources/workflow.rb', line 13 def name attributes[:name] end |
#published? ⇒ Boolean
25 26 27 |
# File 'lib/anvil/resources/workflow.rb', line 25 def published? status == 'published' end |
#reload! ⇒ Object
Reload from API
67 68 69 70 71 |
# File 'lib/anvil/resources/workflow.rb', line 67 def reload! refreshed = self.class.find(eid, client: client) @attributes = refreshed.attributes self end |
#slug ⇒ Object
21 22 23 |
# File 'lib/anvil/resources/workflow.rb', line 21 def slug attributes[:slug] end |
#start(data: {}) ⇒ Hash
Start the workflow with initial data
37 38 39 40 41 42 43 44 45 |
# File 'lib/anvil/resources/workflow.rb', line 37 def start(data: {}) result = client.graphql(self.class.send(:create_weld_data_mutation), variables: { eid: eid, input: data }) raise APIError, "Failed to start workflow: #{eid}" unless result && result[:createWeldData] result[:createWeldData] end |
#status ⇒ Object
17 18 19 |
# File 'lib/anvil/resources/workflow.rb', line 17 def status attributes[:status] end |
#submissions(limit: 10, offset: 0) ⇒ Array<Hash>
Get submissions for this workflow
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/anvil/resources/workflow.rb', line 52 def submissions(limit: 10, offset: 0) result = client.graphql(self.class.send(:weld_data_query), variables: { eid: eid, limit: limit, offset: offset }) if result && result[:weldData] Array(result[:weldData]) else [] end end |