Class: Inferno::Utils::PresetTemplateGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/inferno/utils/preset_template_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runnable) ⇒ PresetTemplateGenerator

Returns a new instance of PresetTemplateGenerator.



6
7
8
# File 'lib/inferno/utils/preset_template_generator.rb', line 6

def initialize(runnable)
  self.runnable = runnable
end

Instance Attribute Details

#runnableObject

Returns the value of attribute runnable.



4
5
6
# File 'lib/inferno/utils/preset_template_generator.rb', line 4

def runnable
  @runnable
end

Instance Method Details

#available_inputsObject



10
11
12
# File 'lib/inferno/utils/preset_template_generator.rb', line 10

def available_inputs
  @available_inputs ||= runnable.available_inputs.transform_values(&:to_hash)
end

#generateObject



34
35
36
37
38
# File 'lib/inferno/utils/preset_template_generator.rb', line 34

def generate
  .merge(
    inputs:
  )
end

#inputsObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/inferno/utils/preset_template_generator.rb', line 14

def inputs
  # The rubocop rule is disabled because `each_value` returns the hash,
  # while `values.each` will return the array of values. We want the array
  # of values here.
  available_inputs.values.map do |original_input|
    {}.tap do |input|
      input[:name] = original_input.delete(:name)
      input[:value] = (original_input.delete(:default) if original_input.key? :default)
      original_input.each { |key, value| input[:"_#{key}"] = value }
    end
  end
end

#metadataObject



27
28
29
30
31
32
# File 'lib/inferno/utils/preset_template_generator.rb', line 27

def 
  {
    title: "Preset for #{runnable.title}",
    id: nil
  }.merge(runnable.reference_hash)
end