Module: Inferno::DSL::InputOutputHandling
- Defined in:
- lib/inferno/dsl/input_output_handling.rb
Instance Method Summary collapse
- #all_outputs ⇒ Object
-
#available_inputs(selected_suite_options = nil) ⇒ Object
Inputs available for the user for this runnable and all its children.
-
#children_available_inputs(selected_suite_options = nil) ⇒ Object
Inputs available for this runnable’s children.
-
#input(identifier, *other_identifiers, **input_params) ⇒ void
Define inputs.
-
#input_order(*new_input_order) ⇒ Array<String, Symbol>
Define a particular order for inputs to be presented in the API/UI.
- #inputs ⇒ Object
- #missing_inputs(submitted_inputs, selected_suite_options) ⇒ Object
- #order_available_inputs(original_inputs) ⇒ Object
-
#output(identifier, *other_identifiers, **output_definition) ⇒ void
Define outputs.
- #output_definitions ⇒ Object
- #outputs ⇒ Object
- #required_inputs(selected_suite_options) ⇒ Object
Instance Method Details
#all_outputs ⇒ Object
147 148 149 150 151 152 |
# File 'lib/inferno/dsl/input_output_handling.rb', line 147 def all_outputs outputs .map { |output_identifier| config.output_name(output_identifier) } .concat(all_children.flat_map(&:all_outputs)) .uniq end |
#available_inputs(selected_suite_options = nil) ⇒ Object
Inputs available for the user for this runnable and all its children.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/inferno/dsl/input_output_handling.rb', line 183 def available_inputs( = nil) available_inputs = config.inputs .slice(*inputs) .each_with_object({}) do |(_, input), inputs| inputs[input.name.to_sym] = Entities::Input.new(**input.to_hash) end available_inputs.each do |input, current_definition| child_definition = children_available_inputs()[input] current_definition.merge_with_child(child_definition) end available_inputs = children_available_inputs().merge(available_inputs) order_available_inputs(available_inputs) end |
#children_available_inputs(selected_suite_options = nil) ⇒ Object
Inputs available for this runnable’s children. A running list of outputs created by the children is used to exclude any inputs which are provided by an earlier child’s output.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/inferno/dsl/input_output_handling.rb', line 158 def children_available_inputs( = nil) child_outputs = [] children().each_with_object({}) do |child, definitions| new_definitions = child.available_inputs().map(&:dup) new_definitions.each do |input, new_definition| existing_definition = definitions[input] updated_definition = if existing_definition.present? existing_definition.merge_with_child(new_definition) else new_definition end next if child_outputs.include?(updated_definition.name.to_sym) definitions[updated_definition.name.to_sym] = updated_definition end child_outputs.concat(child.all_outputs).uniq! end end |
#input(identifier, *other_identifiers, **input_params) ⇒ void
This method returns an undefined value.
Define inputs
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/inferno/dsl/input_output_handling.rb', line 24 def input(identifier, *other_identifiers, **input_params) if other_identifiers.present? [identifier, *other_identifiers].compact.each do |input_identifier| inputs << input_identifier config.add_input(input_identifier) children .reject { |child| child.inputs.include? input_identifier } .each do |child| child.input(input_identifier) end end else inputs << identifier config.add_input(identifier, input_params) children .reject { |child| child.inputs.include? identifier } .each do |child| child.input(identifier, **input_params) end end end |
#input_order(*new_input_order) ⇒ Array<String, Symbol>
Define a particular order for inputs to be presented in the API/UI
116 117 118 119 120 |
# File 'lib/inferno/dsl/input_output_handling.rb', line 116 def input_order(*new_input_order) return @input_order = new_input_order if new_input_order.present? @input_order ||= [] end |
#inputs ⇒ Object
80 81 82 |
# File 'lib/inferno/dsl/input_output_handling.rb', line 80 def inputs @inputs ||= [] end |
#missing_inputs(submitted_inputs, selected_suite_options) ⇒ Object
102 103 104 105 106 |
# File 'lib/inferno/dsl/input_output_handling.rb', line 102 def missing_inputs(submitted_inputs, ) submitted_inputs = [] if submitted_inputs.nil? required_inputs().map(&:to_s) - submitted_inputs.map { |input| input[:name] } end |
#order_available_inputs(original_inputs) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/inferno/dsl/input_output_handling.rb', line 123 def order_available_inputs(original_inputs) input_names = original_inputs.map { |_, input| input.name }.join(', ') ordered_inputs = input_order.each_with_object({}) do |input_name, inputs| key, input = original_inputs.find { |_, input| input.name == input_name.to_s } if input.nil? Inferno::Application[:logger].error <<~ERROR Error trying to order inputs in #{id}: #{title}: - Unable to find input #{input_name} in available inputs: #{input_names} ERROR next end inputs[key] = original_inputs.delete(key) end original_inputs.each do |key, input| ordered_inputs[key] = input end ordered_inputs end |
#output(identifier, *other_identifiers, **output_definition) ⇒ void
This method returns an undefined value.
Define outputs
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/inferno/dsl/input_output_handling.rb', line 57 def output(identifier, *other_identifiers, **output_definition) if other_identifiers.present? [identifier, *other_identifiers].compact.each do |output_identifier| outputs << output_identifier config.add_output(output_identifier) children .reject { |child| child.outputs.include? output_identifier } .each do |child| child.output(output_identifier) end end else outputs << identifier config.add_output(identifier, output_definition) children .reject { |child| child.outputs.include? identifier } .each do |child| child.output(identifier, **output_definition) end end end |
#output_definitions ⇒ Object
90 91 92 |
# File 'lib/inferno/dsl/input_output_handling.rb', line 90 def output_definitions config.outputs.slice(*outputs) end |
#outputs ⇒ Object
85 86 87 |
# File 'lib/inferno/dsl/input_output_handling.rb', line 85 def outputs @outputs ||= [] end |
#required_inputs(selected_suite_options) ⇒ Object
95 96 97 98 99 |
# File 'lib/inferno/dsl/input_output_handling.rb', line 95 def required_inputs() available_inputs() .reject { |_, input| input.optional } .map { |_, input| input.name } end |