Class: VcoWorkflows::WorkflowPresentation
- Inherits:
-
Object
- Object
- VcoWorkflows::WorkflowPresentation
- Defined in:
- lib/vcoworkflows/workflowpresentation.rb
Overview
WorkflowPresentation is a helper class for Workflow and is primarily used internally to apply additional constraints to WorkflowParameters. Currently WorkflowPresentation examines the presentation JSON from vCO to determine whether input parameters for the workflow are required or not.
Instance Attribute Summary collapse
-
#presentation_data ⇒ Hash
readonly
Accessor for the data structure.
-
#required ⇒ String[]
readonly
Get the list of required parameters for the workflow.
Instance Method Summary collapse
-
#initialize(workflow_service, workflow_id) ⇒ VcoWorkflows::WorkflowPresentation
constructor
Create a new WorkflowPresentation.
-
#to_json ⇒ String
JSON document.
-
#to_s ⇒ String
String representation of the presentation.
Constructor Details
#initialize(workflow_service, workflow_id) ⇒ VcoWorkflows::WorkflowPresentation
Create a new WorkflowPresentation
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vcoworkflows/workflowpresentation.rb', line 29 def initialize(workflow_service, workflow_id) @required = [] @presentation_data = JSON.parse(workflow_service.get_presentation(workflow_id)) # Determine if there are any required input parameters # We're parsing this because we specifically want to know if any of # the input parameters are marked as required. This is very specifically # in the array of hashes in: # presentation_data[:steps][0][:step][:elements][0][:fields] fields = @presentation_data['steps'][0]['step']['elements'][0]['fields'] fields.each do |attribute| next unless attribute.key?('constraints') attribute['constraints'].each do |const| if const.key?('@type') && const['@type'].eql?('mandatory') @required << attribute['id'] end end end end |
Instance Attribute Details
#presentation_data ⇒ Hash (readonly)
Accessor for the data structure
17 18 19 |
# File 'lib/vcoworkflows/workflowpresentation.rb', line 17 def presentation_data @presentation_data end |
#required ⇒ String[] (readonly)
Get the list of required parameters for the workflow
21 22 23 |
# File 'lib/vcoworkflows/workflowpresentation.rb', line 21 def required @required end |
Instance Method Details
#to_json ⇒ String
JSON document
57 58 59 |
# File 'lib/vcoworkflows/workflowpresentation.rb', line 57 def to_json JSON.pretty_generate(@presentation_data) end |
#to_s ⇒ String
String representation of the presentation
51 52 53 |
# File 'lib/vcoworkflows/workflowpresentation.rb', line 51 def to_s @presentation_data.to_s end |