Class: AxeCuprite::Results

Inherits:
Object
  • Object
show all
Defined in:
lib/axe/cuprite/results.rb

Overview

Wraps the (slimmed) payload returned by axe.run. We deliberately only carry ‘violations` and `incomplete` across the CDP boundary plus a little metadata — the full results object (with `passes`/`inapplicable`) can be huge.

The wrappers are read-only: ‘@raw` is deep-frozen at construction, so `raw` and `to_h` expose the live underlying hash safely (callers cannot mutate it).

Ownership note: ‘Results` (and the nested `Violation`/`Node`/`ContrastData` wrappers) **take ownership of the hash passed in and deep-freeze it in place** — they do not copy first. For the internal flow this is safe (the payload comes fresh off the CDP boundary), but if you construct `Results.new(hash)` yourself, don’t pass — or hold onto — a hash you intend to mutate afterward, or you’ll hit a ‘FrozenError`. Dup it first if you need a mutable copy.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Results

Returns a new instance of Results.



39
40
41
# File 'lib/axe/cuprite/results.rb', line 39

def initialize(raw)
  @raw = DeepFreeze.call(raw || {})
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



37
38
39
# File 'lib/axe/cuprite/results.rb', line 37

def raw
  @raw
end

Instance Method Details

#incompleteObject

Nodes axe could not decide on (needs review). Surfaced but never fails.



48
49
50
# File 'lib/axe/cuprite/results.rb', line 48

def incomplete
  @incomplete ||= Array(@raw["incomplete"]).map { |v| Violation.new(v) }
end

#passes?Boolean Also known as: clean?

Returns:

  • (Boolean)


52
53
54
# File 'lib/axe/cuprite/results.rb', line 52

def passes?
  violations.empty?
end

#test_engineObject



65
66
67
# File 'lib/axe/cuprite/results.rb', line 65

def test_engine
  @raw["testEngine"]
end

#timestampObject



61
62
63
# File 'lib/axe/cuprite/results.rb', line 61

def timestamp
  @raw["timestamp"]
end

#to_hObject



69
70
71
# File 'lib/axe/cuprite/results.rb', line 69

def to_h
  @raw
end

#urlObject



57
58
59
# File 'lib/axe/cuprite/results.rb', line 57

def url
  @raw["url"]
end

#violationsObject



43
44
45
# File 'lib/axe/cuprite/results.rb', line 43

def violations
  @violations ||= Array(@raw["violations"]).map { |v| Violation.new(v) }
end