class Omnitest::Psychic::Execution::DefaultStrategy
Attributes
script[R]
Public Class Methods
new(script)
click to toggle source
Calls superclass method
Omnitest::Psychic::CommandTemplate::new
# File lib/omnitest/psychic/execution/default_strategy.rb, line 7 def initialize(script) @script = script @psychic = script.psychic super(script.psychic, build_command) end
Public Instance Methods
build_command()
click to toggle source
# File lib/omnitest/psychic/execution/default_strategy.rb, line 23 def build_command # rubocop:disable Metrics/AbcSize 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)
click to toggle source
# 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)
click to toggle source
Calls superclass method
Omnitest::Psychic::CommandTemplate#execute
# 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()
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
cli()
click to toggle source
# File lib/omnitest/psychic/execution/default_strategy.rb, line 72 def cli psychic.cli end
interactive?()
click to toggle source
# File lib/omnitest/psychic/execution/default_strategy.rb, line 76 def interactive? psychic.interactive? end
quote(values)
click to toggle source
# File lib/omnitest/psychic/execution/default_strategy.rb, line 66 def quote(values) values.map do | value | value.split.size > 1 ? "\"#{value}\"" : value end end