Class: Inferno::DSL::Configurable::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/inferno/dsl/configurable.rb

Overview

This class stores a runnable’s configuration. It should never be directly instantiated within a test suite. Instead, a runnable’s configuration can be modified or retrieved using the ‘config` method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration = {}) ⇒ Configuration

Returns a new instance of Configuration.



105
106
107
# File 'lib/inferno/dsl/configurable.rb', line 105

def initialize(configuration = {})
  self.configuration = configuration
end

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



102
103
104
# File 'lib/inferno/dsl/configurable.rb', line 102

def configuration
  @configuration
end

Instance Method Details

#add_input(identifier, new_config = {}) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/inferno/dsl/configurable.rb', line 142

def add_input(identifier, new_config = {})
  existing_config = input(identifier)

  if existing_config.nil?
    return inputs[identifier] = Entities::Input.new(**default_input_params(identifier).merge(new_config))
  end

  inputs[identifier] =
    Entities::Input
      .new(**existing_config.to_hash)
      .merge(Entities::Input.new(**new_config))
end

#add_output(identifier, new_config = {}) ⇒ Object



195
196
197
198
# File 'lib/inferno/dsl/configurable.rb', line 195

def add_output(identifier, new_config = {})
  existing_config = output_config(identifier) || {}
  outputs[identifier] = default_output_config(identifier).merge(existing_config, new_config)
end

#add_request(identifier) ⇒ Object



235
236
237
238
239
# File 'lib/inferno/dsl/configurable.rb', line 235

def add_request(identifier)
  return if request_config_exists?(identifier)

  requests[identifier] = default_request_config(identifier)
end

#apply(new_configuration) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/inferno/dsl/configurable.rb', line 110

def apply(new_configuration)
  config_to_apply =
    if new_configuration.is_a? Configuration
      new_configuration.configuration
    else
      new_configuration
    end

  self.configuration = configuration.deep_merge(config_to_apply.except(:inputs))

  config_to_apply[:inputs]&.each do |identifier, new_input|
    add_input(identifier, new_input.to_hash)
  end
end

#default_input_params(identifier) ⇒ Object



156
157
158
# File 'lib/inferno/dsl/configurable.rb', line 156

def default_input_params(identifier)
  { name: identifier, type: 'text' }
end

#default_output_config(identifier) ⇒ Object



201
202
203
# File 'lib/inferno/dsl/configurable.rb', line 201

def default_output_config(identifier)
  { name: identifier, type: 'text' }
end

#default_request_config(identifier) ⇒ Object



242
243
244
# File 'lib/inferno/dsl/configurable.rb', line 242

def default_request_config(identifier)
  { name: identifier }
end

#input(identifier) ⇒ Object



166
167
168
# File 'lib/inferno/dsl/configurable.rb', line 166

def input(identifier)
  inputs[identifier]
end

#input_exists?(identifier) ⇒ Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/inferno/dsl/configurable.rb', line 161

def input_exists?(identifier)
  inputs.key? identifier
end

#input_name(identifier) ⇒ Object



171
172
173
# File 'lib/inferno/dsl/configurable.rb', line 171

def input_name(identifier)
  inputs[identifier]&.name
end

#input_optional?(identifier) ⇒ Boolean

Returns:

  • (Boolean)


181
182
183
# File 'lib/inferno/dsl/configurable.rb', line 181

def input_optional?(identifier)
  inputs[identifier]&.optional
end

#input_type(identifier) ⇒ Object



176
177
178
# File 'lib/inferno/dsl/configurable.rb', line 176

def input_type(identifier)
  inputs[identifier]&.type
end

#inputsHash

The input configuration for this runnable.

Returns:

  • (Hash)


137
138
139
# File 'lib/inferno/dsl/configurable.rb', line 137

def inputs
  configuration[:inputs] ||= {}
end

#optionsHash

The configuration options defined for this runnable.

Returns:

  • (Hash)


128
129
130
# File 'lib/inferno/dsl/configurable.rb', line 128

def options
  configuration[:options] ||= {}
end

#output_config(identifier) ⇒ Object



211
212
213
# File 'lib/inferno/dsl/configurable.rb', line 211

def output_config(identifier)
  outputs[identifier]
end

#output_config_exists?(identifier) ⇒ Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/inferno/dsl/configurable.rb', line 206

def output_config_exists?(identifier)
  outputs.key? identifier
end

#output_name(identifier) ⇒ Object



216
217
218
# File 'lib/inferno/dsl/configurable.rb', line 216

def output_name(identifier)
  outputs.dig(identifier, :name) || identifier
end

#output_type(identifier) ⇒ Object



221
222
223
# File 'lib/inferno/dsl/configurable.rb', line 221

def output_type(identifier)
  outputs.dig(identifier, :type)
end

#outputsHash

The output configuration for this runnable.

Returns:

  • (Hash)


190
191
192
# File 'lib/inferno/dsl/configurable.rb', line 190

def outputs
  configuration[:outputs] ||= {}
end

#request_config(identifier) ⇒ Object



252
253
254
# File 'lib/inferno/dsl/configurable.rb', line 252

def request_config(identifier)
  requests[identifier]
end

#request_config_exists?(identifier) ⇒ Boolean

Returns:

  • (Boolean)


247
248
249
# File 'lib/inferno/dsl/configurable.rb', line 247

def request_config_exists?(identifier)
  requests.key? identifier
end

#request_name(identifier) ⇒ Object



257
258
259
# File 'lib/inferno/dsl/configurable.rb', line 257

def request_name(identifier)
  requests.dig(identifier, :name) || identifier
end

#requestsHash

The request configuration for this runnable.

Returns:

  • (Hash)


230
231
232
# File 'lib/inferno/dsl/configurable.rb', line 230

def requests
  configuration[:requests] ||= {}
end