Class: Stormbreaker::AxeResultsSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/stormbreaker/axe_results_serializer.rb

Constant Summary collapse

ALLOWED_CLASSES =
[Stormbreaker::AxeViolation, Set, Symbol].freeze

Class Method Summary collapse

Class Method Details

.combine_results(path = Dir.pwd, prefix = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/stormbreaker/axe_results_serializer.rb', line 17

def self.combine_results(path = Dir.pwd, prefix = nil)
  prefix ||= Stormbreaker.configuration.serialize_prefix
  results_files = Dir.glob(File.join(path, "#{prefix}*"))
  raise "No results matching /#{prefix}* found in #{path}" if results_files.empty?

  combined_manager = Stormbreaker::AxeViolationManager.new
  results_files.each do |file|
    puts "Loading #{file}"
    total_violations = YAML.safe_load_file(file, permitted_classes: ALLOWED_CLASSES, aliases: true)
    total_violations.each do |violation|
      combined_manager.add_failure_to_total(violation)
    end
  end

  combined_manager
end

.serialize_results(total_violations) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/stormbreaker/axe_results_serializer.rb', line 9

def self.serialize_results(total_violations)
  dump = YAML.dump(total_violations)
  prefix = Stormbreaker.configuration.serialize_prefix
  filename = "#{prefix}_#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_#{Digest::SHA2.hexdigest(dump)}"
  File.write(filename, dump)
  puts "Serialized results written to #{filename}"
end