class Rspec::Bash::CallConfiguration
Attributes
call_configuration[RW]
Public Class Methods
new()
click to toggle source
# File lib/rspec/bash/command/call_configuration.rb, line 8 def initialize @call_configuration = [] end
Public Instance Methods
add_output(content, target, args = [])
click to toggle source
# File lib/rspec/bash/command/call_configuration.rb, line 17 def add_output(content, target, args = []) current_conf = create_or_get_conf(args) type = determine_output_type(target) current_conf[:outputs][target] = { target: target, type: type, content: content.to_s } end
get_best_call_conf(args = [])
click to toggle source
# File lib/rspec/bash/command/call_configuration.rb, line 27 def get_best_call_conf(args = []) call_conf_arg_matcher = Util::CallConfArgumentListMatcher.new(@call_configuration) best_call_conf = call_conf_arg_matcher.get_best_call_conf(args) remove_args_from_conf( interpolate_output_targets( copy_conf(best_call_conf), args ) ) end
set_exitcode(exitcode, args = [])
click to toggle source
# File lib/rspec/bash/command/call_configuration.rb, line 12 def set_exitcode(exitcode, args = []) current_conf = create_or_get_conf(args) current_conf[:exitcode] = exitcode end
Private Instance Methods
copy_conf(configuration)
click to toggle source
# File lib/rspec/bash/command/call_configuration.rb, line 83 def copy_conf(configuration) Marshal.load(Marshal.dump(configuration)) end
create_or_get_conf(args)
click to toggle source
# File lib/rspec/bash/command/call_configuration.rb, line 72 def create_or_get_conf(args) new_conf = { args: args, exitcode: 0, outputs: {} } current_conf = @call_configuration.select { |conf| conf[:args] == args } @call_configuration << new_conf if current_conf.empty? current_conf.first || new_conf end
determine_output_type(target)
click to toggle source
# File lib/rspec/bash/command/call_configuration.rb, line 87 def determine_output_type(target) is_a_file_target = !([:stdout, :stderr].include? target) is_a_file_target ? :file : target end
interpolate_argument(name, args)
click to toggle source
# File lib/rspec/bash/command/call_configuration.rb, line 61 def interpolate_argument(name, args) matching_arg_index = /^arg(\d+)$/.match(name.to_s) return name.to_s unless matching_arg_index args[matching_arg_index[1].to_i - 1] end
interpolate_output_targets(conf, args)
click to toggle source
# File lib/rspec/bash/command/call_configuration.rb, line 40 def interpolate_output_targets(conf, args) return conf if conf.empty? conf[:outputs].keys.each do |target| interpolated_target = interpolate_target(target, args) next if interpolated_target == target conf[:outputs][interpolated_target] = conf[:outputs][target] conf[:outputs][interpolated_target][:target] = interpolated_target conf[:outputs].delete(target) end conf end
interpolate_target(target, args)
click to toggle source
# File lib/rspec/bash/command/call_configuration.rb, line 53 def interpolate_target(target, args) return target unless target.is_a? Array target.map do |target_element| next target_element if target_element.is_a? String interpolate_argument(target_element, args) end.join end
remove_args_from_conf(conf)
click to toggle source
# File lib/rspec/bash/command/call_configuration.rb, line 67 def remove_args_from_conf(conf) conf.delete(:args) conf end