Class: Inferno::DSL::Configurable::Configuration
- Inherits:
-
Object
- Object
- Inferno::DSL::Configurable::Configuration
- 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
-
#configuration ⇒ Object
Returns the value of attribute configuration.
Instance Method Summary collapse
- #add_input(identifier, new_config = {}) ⇒ Object
- #add_output(identifier, new_config = {}) ⇒ Object
- #add_request(identifier) ⇒ Object
- #apply(new_configuration) ⇒ Object
-
#deep_dup(value) ⇒ Object
Recursively duplicate arrays/hashes to prevent them from being shared across different runnables.
- #default_input_params(identifier) ⇒ Object
- #default_output_config(identifier) ⇒ Object
- #default_request_config(identifier) ⇒ Object
-
#initialize(configuration = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #input(identifier) ⇒ Object
- #input_exists?(identifier) ⇒ Boolean
- #input_name(identifier) ⇒ Object
- #input_optional?(identifier) ⇒ Boolean
- #input_type(identifier) ⇒ Object
-
#inputs ⇒ Hash
The input configuration for this runnable.
-
#options ⇒ Hash
The configuration options defined for this runnable.
- #output_config(identifier) ⇒ Object
- #output_config_exists?(identifier) ⇒ Boolean
- #output_name(identifier) ⇒ Object
- #output_type(identifier) ⇒ Object
-
#outputs ⇒ Hash
The output configuration for this runnable.
- #request_config(identifier) ⇒ Object
- #request_config_exists?(identifier) ⇒ Boolean
- #request_name(identifier) ⇒ Object
-
#requests ⇒ Hash
The request configuration for this runnable.
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
#configuration ⇒ Object
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
155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/inferno/dsl/configurable.rb', line 155 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(**deep_dup(existing_config.to_hash)) .merge(Entities::Input.new(**new_config)) end |
#add_output(identifier, new_config = {}) ⇒ Object
208 209 210 211 |
# File 'lib/inferno/dsl/configurable.rb', line 208 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
248 249 250 251 252 |
# File 'lib/inferno/dsl/configurable.rb', line 248 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 |
#deep_dup(value) ⇒ Object
Recursively duplicate arrays/hashes to prevent them from being shared across different runnables
144 145 146 147 148 149 150 151 152 |
# File 'lib/inferno/dsl/configurable.rb', line 144 def deep_dup(value) if value.is_a? Array value.map { |element| deep_dup(element) } elsif value.is_a? Hash value.transform_values { |element| deep_dup(element) } else value.dup end end |
#default_input_params(identifier) ⇒ Object
169 170 171 |
# File 'lib/inferno/dsl/configurable.rb', line 169 def default_input_params(identifier) { name: identifier, type: 'text' } end |
#default_output_config(identifier) ⇒ Object
214 215 216 |
# File 'lib/inferno/dsl/configurable.rb', line 214 def default_output_config(identifier) { name: identifier, type: 'text' } end |
#default_request_config(identifier) ⇒ Object
255 256 257 |
# File 'lib/inferno/dsl/configurable.rb', line 255 def default_request_config(identifier) { name: identifier } end |
#input(identifier) ⇒ Object
179 180 181 |
# File 'lib/inferno/dsl/configurable.rb', line 179 def input(identifier) inputs[identifier] end |
#input_exists?(identifier) ⇒ Boolean
174 175 176 |
# File 'lib/inferno/dsl/configurable.rb', line 174 def input_exists?(identifier) inputs.key? identifier end |
#input_name(identifier) ⇒ Object
184 185 186 |
# File 'lib/inferno/dsl/configurable.rb', line 184 def input_name(identifier) inputs[identifier]&.name end |
#input_optional?(identifier) ⇒ Boolean
194 195 196 |
# File 'lib/inferno/dsl/configurable.rb', line 194 def input_optional?(identifier) inputs[identifier]&.optional end |
#input_type(identifier) ⇒ Object
189 190 191 |
# File 'lib/inferno/dsl/configurable.rb', line 189 def input_type(identifier) inputs[identifier]&.type end |
#inputs ⇒ Hash
The input configuration for this runnable.
137 138 139 |
# File 'lib/inferno/dsl/configurable.rb', line 137 def inputs configuration[:inputs] ||= {} end |
#options ⇒ Hash
The configuration options defined for this runnable.
128 129 130 |
# File 'lib/inferno/dsl/configurable.rb', line 128 def configuration[:options] ||= {} end |
#output_config(identifier) ⇒ Object
224 225 226 |
# File 'lib/inferno/dsl/configurable.rb', line 224 def output_config(identifier) outputs[identifier] end |
#output_config_exists?(identifier) ⇒ Boolean
219 220 221 |
# File 'lib/inferno/dsl/configurable.rb', line 219 def output_config_exists?(identifier) outputs.key? identifier end |
#output_name(identifier) ⇒ Object
229 230 231 |
# File 'lib/inferno/dsl/configurable.rb', line 229 def output_name(identifier) outputs.dig(identifier, :name) || identifier end |
#output_type(identifier) ⇒ Object
234 235 236 |
# File 'lib/inferno/dsl/configurable.rb', line 234 def output_type(identifier) outputs.dig(identifier, :type) end |
#outputs ⇒ Hash
The output configuration for this runnable.
203 204 205 |
# File 'lib/inferno/dsl/configurable.rb', line 203 def outputs configuration[:outputs] ||= {} end |
#request_config(identifier) ⇒ Object
265 266 267 |
# File 'lib/inferno/dsl/configurable.rb', line 265 def request_config(identifier) requests[identifier] end |
#request_config_exists?(identifier) ⇒ Boolean
260 261 262 |
# File 'lib/inferno/dsl/configurable.rb', line 260 def request_config_exists?(identifier) requests.key? identifier end |
#request_name(identifier) ⇒ Object
270 271 272 |
# File 'lib/inferno/dsl/configurable.rb', line 270 def request_name(identifier) requests.dig(identifier, :name) || identifier end |
#requests ⇒ Hash
The request configuration for this runnable.
243 244 245 |
# File 'lib/inferno/dsl/configurable.rb', line 243 def requests configuration[:requests] ||= {} end |