Class: WSDirector::ScenarioReader
- Inherits:
-
Object
- Object
- WSDirector::ScenarioReader
- Includes:
- Utils
- Defined in:
- lib/wsdirector/scenario_reader.rb
Overview
Read and parse different scenarios
Constant Summary
Constants included from Utils
Instance Attribute Summary collapse
-
#default_connections_options ⇒ Object
readonly
Returns the value of attribute default_connections_options.
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
Attributes included from Utils
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(scale: 1, connection_options: {}, locals: {}) ⇒ ScenarioReader
constructor
A new instance of ScenarioReader.
- #parse(scenario) ⇒ Object
Methods included from Utils
Constructor Details
#initialize(scale: 1, connection_options: {}, locals: {}) ⇒ ScenarioReader
Returns a new instance of ScenarioReader.
22 23 24 25 26 |
# File 'lib/wsdirector/scenario_reader.rb', line 22 def initialize(scale: 1, connection_options: {}, locals: {}) @scale = scale @default_connections_options = @locals = locals end |
Instance Attribute Details
#default_connections_options ⇒ Object (readonly)
Returns the value of attribute default_connections_options.
20 21 22 |
# File 'lib/wsdirector/scenario_reader.rb', line 20 def @default_connections_options end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
20 21 22 |
# File 'lib/wsdirector/scenario_reader.rb', line 20 def locals @locals end |
Class Method Details
.parse(scenario, **options) ⇒ Object
15 16 17 |
# File 'lib/wsdirector/scenario_reader.rb', line 15 def parse(scenario, **) new(**).parse(scenario) end |
Instance Method Details
#parse(scenario) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/wsdirector/scenario_reader.rb', line 28 def parse(scenario) contents = if scenario.is_a?(String) if File.file?(scenario) parse_file(scenario) else parse_from_str(scenario).then do next _1 if _1.is_a?(Array) [_1] end end.flatten else scenario end contents.map! do |item| item.is_a?(String) ? {item => {}} : item end if contents.first&.key?("client") contents = transform_with_loop(contents, multiple: true) parse_multiple_scenarios(contents) else contents = transform_with_loop(contents) {"total" => 1, "clients" => [parse_simple_scenario(contents)]} end end |