Method: PDK::Validate::BaseValidator.invoke

Defined in:
lib/pdk/validators/base_validator.rb

.invoke(report, options = {}) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/pdk/validators/base_validator.rb', line 101

def self.invoke(report, options = {})
  targets, skipped, invalid = parse_targets(options)

  process_skipped(report, skipped)
  process_invalid(report, invalid)

  return 0 if targets.empty?

  PDK::Util::Bundler.ensure_binstubs!(cmd)

  # If invoking :per_target, split the targets array into an array of
  # single element arrays (one per target). If invoking :once, wrap the
  # targets array in another array. This is so we can loop through the
  # invokes with the same logic, regardless of which invoke style is
  # needed.
  targets = (self::INVOKE_STYLE == :per_target) ? targets.combination(1).to_a : Array[targets]
  exit_codes = []

  targets.each do |invokation_targets|
    cmd_argv = parse_options(options, invokation_targets).unshift(cmd_path)
    cmd_argv.unshift('ruby', '-W0') if Gem.win_platform?

    command = PDK::CLI::Exec::Command.new(*cmd_argv).tap do |c|
      c.context = :module
      exec_group = options[:exec_group]
      if exec_group
        sub_spinner = exec_group.add_spinner(spinner_text(invokation_targets))
        c.register_spinner(sub_spinner)
      else
        c.add_spinner(spinner_text(invokation_targets))
      end
    end

    result = command.execute!
    exit_codes << result[:exit_code]

    parse_output(report, result, invokation_targets)
  end

  exit_codes.max
end