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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vcoworkflows/workflowpresentation.rb', line 31 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
19 20 21 |
# File 'lib/vcoworkflows/workflowpresentation.rb', line 19 def presentation_data @presentation_data end |
#required ⇒ String[] (readonly)
Get the list of required parameters for the workflow
23 24 25 |
# File 'lib/vcoworkflows/workflowpresentation.rb', line 23 def required @required end |
Instance Method Details
#to_json ⇒ String
JSON document
59 60 61 |
# File 'lib/vcoworkflows/workflowpresentation.rb', line 59 def to_json JSON.pretty_generate(@presentation_data) end |
#to_s ⇒ String
String representation of the presentation
53 54 55 |
# File 'lib/vcoworkflows/workflowpresentation.rb', line 53 def to_s @presentation_data.to_s end |