Class: Steplib::WorkflowUpdater
- Inherits:
-
Object
- Object
- Steplib::WorkflowUpdater
- Defined in:
- lib/steplib/workflow_updater.rb
Class Method Summary collapse
-
.set_defaults_for_missing_properties_in_workflow(workflow_data) ⇒ Object
of course this can only fill-out properties which have a pre-defined valid default value.
-
.set_defaults_for_missing_properties_in_workflow_step(workflow_step_data) ⇒ Object
similar to a set_defaults_for_missing_properties_in_workflow but for a single workflow-step.
-
.update_workflow_step_with_steplib_step_version!(workflow_step, steplib_step_version) ⇒ Object
The input steplib_step_version have to be a valid step-version! The input workflow_step is not copied, modified in-inline! Also: inputs which can’t be found in the steplib-step-version WILL BE REMOVED and inputs which can be found in the steplib-step-version but not in the workflow-step inputs WILL BE ADDED Because of the potential destructive nature of this method you should use it carefully and you can expect an exception/error raised for: * steplib-step-version is not valid * steplib-step-version’s version_tag doesn’t match the workflow_step’s version_tag * missing ‘version_tag’ in workflow_step.
Class Method Details
.set_defaults_for_missing_properties_in_workflow(workflow_data) ⇒ Object
of course this can only fill-out properties
which have a pre-defined valid default value
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/steplib/workflow_updater.rb', line 11 def set_defaults_for_missing_properties_in_workflow(workflow_data) workflow_data = HashUtils.set_missing_defaults(workflow_data, [ # main arrays {key: 'environments', value: []}, {key: 'steps', value: []}, ]) # # environments workflow_data['environments'] = workflow_data['environments'].map { |an_env| an_env = HashUtils.set_missing_defaults(an_env, [ {key: 'title', value: ''}, {key: 'is_expand', value: true}, ]) # return: an_env } # # steps workflow_data['steps'] = workflow_data['steps'].map { |a_step| a_step = set_defaults_for_missing_properties_in_workflow_step(a_step) # return: a_step } return workflow_data end |
.set_defaults_for_missing_properties_in_workflow_step(workflow_step_data) ⇒ Object
similar to a set_defaults_for_missing_properties_in_workflow
but for a single workflow-step
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/steplib/workflow_updater.rb', line 40 def set_defaults_for_missing_properties_in_workflow_step(workflow_step_data) workflow_step_data = HashUtils.set_missing_defaults(workflow_step_data, [ {key: 'name', value: ''}, {key: 'description', value: ''}, {key: 'icon_url_256', value: nil}, {key: 'project_type_tags', value: []}, {key: 'type_tags', value: []}, # main arrays {key: 'inputs', value: []}, {key: 'outputs', value: []}, {key: 'log_highlights', value: []}, ]) workflow_step_data['inputs'] = workflow_step_data['inputs'].map { |a_step_inp| a_step_inp = HashUtils.set_missing_defaults(a_step_inp, [ {key: 'title', value: ''}, {key: 'description', value: ''}, {key: 'is_expand', value: true}, {key: 'is_required', value: false}, {key: 'value_options', value: []}, {key: 'is_dont_change_value', value: false}, ]) # return: a_step_inp } workflow_step_data['outputs'] = workflow_step_data['outputs'].map { |a_step_output| a_step_output = HashUtils.set_missing_defaults(a_step_output, [ {key: 'description', value: ''} ]) # return: a_step_output } return workflow_step_data end |
.update_workflow_step_with_steplib_step_version!(workflow_step, steplib_step_version) ⇒ Object
The input steplib_step_version have to be a valid step-version! The input workflow_step is not copied, modified in-inline! Also: inputs which can’t be found in the steplib-step-version
WILL BE REMOVED and inputs which can be found in the steplib-step-version
but not in the workflow-step inputs WILL BE ADDED
Because of the potential destructive nature of this method you
should use it carefully and you can expect an exception/error raised for:
* steplib-step-version is not valid
* steplib-step-version's version_tag doesn't match the workflow_step's version_tag
* missing 'version_tag' in workflow_step
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/steplib/workflow_updater.rb', line 85 def update_workflow_step_with_steplib_step_version!(workflow_step, steplib_step_version) # SteplibValidator.validate_step_version!(steplib_step_version) raise "Missing 'version_tag'" if workflow_step['version_tag'].nil? if workflow_step['version_tag'] != steplib_step_version['version_tag'] raise "Workflow-step 'version_tag' doesn't match the steplib-step-version's" end # # copy all except the ones which are used for identifying the input inside a step(-version): # * steplib_source # * id # * version_tag # # copy no-matter-what: workflow_step = HashUtils.copy_attributes( workflow_step, steplib_step_version, ['description', 'website', 'fork_url', 'source', 'host_os_tags', 'project_type_tags', 'type_tags', 'is_requires_admin_user', 'icon_url_256'] ) # # copy only if missing (user defined attributes) # see "@WorkflowUserMod" in the steplib format spec for more information workflow_step = HashUtils.copy_missing_attributes( workflow_step, steplib_step_version, ['name'] ) # update inputs and remove the ones which can't be # found in the steplib step version's inputs # and add the missing ones steplib_step_version_inputs = steplib_step_version['inputs'] workflow_step['inputs'] = workflow_step['inputs'].map { |a_wf_step_inp| # search for the same input in the steplib-step-version = steplib_step_version_inputs.find do |possible_inp| if possible_inp['mapped_to'] == a_wf_step_inp['mapped_to'] true else false end end if .nil? # not found - remove (w/ .compact) # return: nil else # copy all except the ones which are used for identifying the input inside a step(-version): # * mapped_to # # copy no matter what a_wf_step_inp = HashUtils.copy_attributes( a_wf_step_inp, , ['title', 'description', 'is_required', 'value_options', 'is_dont_change_value'] ) # copy only if missing (user defined attributes) # see "@WorkflowUserMod" in the steplib format spec for more information a_wf_step_inp = HashUtils.copy_missing_attributes( a_wf_step_inp, , ['value', 'is_expand'] ) # return: a_wf_step_inp end }.compact # .compact removes nil elements # add missing ones wf_step_inputs = workflow_step['inputs'] missing_inputs = steplib_step_version_inputs.select { |a_steplib_input| wf_step_input = wf_step_inputs.find do |a_wf_inp| if a_wf_inp['mapped_to'] == a_steplib_input['mapped_to'] true else false end end # add, if not found # return: wf_step_input.nil? } workflow_step['inputs'] = wf_step_inputs.concat(missing_inputs) # update outputs to match the steplib-step-version's # output list workflow_step['outputs'] = Steplib::HashUtils.deep_copy(steplib_step_version['outputs']) return workflow_step end |