Class: Omnitest::Psychic::Execution::DefaultStrategy
Instance Attribute Summary collapse
#psychic
Instance Method Summary
collapse
#command
Constructor Details
Returns a new instance of DefaultStrategy.
7
8
9
10
11
|
# File 'lib/omnitest/psychic/execution/default_strategy.rb', line 7
def initialize(script)
@script = script
@psychic = script.psychic
super(script.psychic, build_command)
end
|
Instance Attribute Details
#script ⇒ Object
Returns the value of attribute script.
5
6
7
|
# File 'lib/omnitest/psychic/execution/default_strategy.rb', line 5
def script
@script
end
|
Instance Method Details
#build_command ⇒ Object
rubocop:disable Metrics/AbcSize
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/omnitest/psychic/execution/default_strategy.rb', line 23
def build_command return @command if defined? @command
script_factory = psychic.script_factory_manager.factories_for(script).last
fail Omnitest::Psychic::ScriptNotRunnable, script if script_factory.nil?
@command = script_factory.script(script)
if script.arguments
arguments = script.arguments.map do | arg |
Tokens.replace_tokens(arg, script.params)
end
@arguments = quote(arguments)
end
@command = "#{@command}" if script.arguments
@command = @command.call if @command.respond_to? :call
@command = [@command, @arguments].join(' ')
end
|
#confirm_or_update_parameters(required_parameters) ⇒ Object
52
53
54
55
56
|
# File 'lib/omnitest/psychic/execution/default_strategy.rb', line 52
def confirm_or_update_parameters(required_parameters)
required_parameters.each do | key |
script.params[key] = prompt(key)
end if interactive?
end
|
#execute(*args) ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/omnitest/psychic/execution/default_strategy.rb', line 13
def execute(*args)
shell_opts = args.shift if args.first.is_a? Hash
shell_opts ||= { env: script.env }
expand_parameters
params = script.params
command_params = { script: script.name, script_file: script.source_file }
command_params.merge!(params) unless params.nil?
super(command_params, shell_opts, *args)
end
|
#expand_parameters ⇒ Object
58
59
60
61
62
|
# File 'lib/omnitest/psychic/execution/default_strategy.rb', line 58
def expand_parameters
if script.params.is_a? String
script.params = YAML.load(Tokens.replace_tokens(script.params, script.env))
end
end
|
#prompt(key) ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/omnitest/psychic/execution/default_strategy.rb', line 41
def prompt(key)
value = script.params[key]
if value
return value unless psychic.opts[:interactive] == 'always'
new_value = cli.ask "Please set a value for #{key} (or enter to confirm #{value.inspect}): "
new_value.empty? ? value : new_value
else
cli.ask "Please set a value for #{key}: "
end
end
|