Class: Clickwrap::ReceiptVerifier::Result
- Inherits:
-
Object
- Object
- Clickwrap::ReceiptVerifier::Result
- Defined in:
- lib/clickwrap/receipt_verifier.rb
Overview
The result object. success? is true only when every check that ran
passed; a skipped check never makes a result succeed and never makes it
fail, it just stays visible in checks.
Instance Attribute Summary collapse
-
#checks ⇒ Object
readonly
Returns the value of attribute checks.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #failed? ⇒ Boolean
- #failures ⇒ Object
- #incomplete? ⇒ Boolean
-
#initialize(schema:, checks:) ⇒ Result
constructor
A new instance of Result.
- #inspect ⇒ Object
- #passed ⇒ Object
- #skipped ⇒ Object
- #status ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
- #verified? ⇒ Boolean (also: #success?)
Constructor Details
#initialize(schema:, checks:) ⇒ Result
Returns a new instance of Result.
113 114 115 116 117 |
# File 'lib/clickwrap/receipt_verifier.rb', line 113 def initialize(schema:, checks:) @schema = schema @checks = checks.freeze freeze end |
Instance Attribute Details
#checks ⇒ Object (readonly)
Returns the value of attribute checks.
111 112 113 |
# File 'lib/clickwrap/receipt_verifier.rb', line 111 def checks @checks end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
111 112 113 |
# File 'lib/clickwrap/receipt_verifier.rb', line 111 def schema @schema end |
Instance Method Details
#failed? ⇒ Boolean
122 |
# File 'lib/clickwrap/receipt_verifier.rb', line 122 def failed? = failures.any? |
#failures ⇒ Object
133 |
# File 'lib/clickwrap/receipt_verifier.rb', line 133 def failures = checks.select(&:failed?) |
#incomplete? ⇒ Boolean
123 |
# File 'lib/clickwrap/receipt_verifier.rb', line 123 def incomplete? = failures.empty? && skipped.any? |
#inspect ⇒ Object
156 |
# File 'lib/clickwrap/receipt_verifier.rb', line 156 def inspect = "#<Clickwrap::ReceiptVerifier::Result #{status}>" |
#passed ⇒ Object
135 |
# File 'lib/clickwrap/receipt_verifier.rb', line 135 def passed = checks.select(&:passed?) |
#skipped ⇒ Object
134 |
# File 'lib/clickwrap/receipt_verifier.rb', line 134 def skipped = checks.select(&:skipped?) |
#status ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/clickwrap/receipt_verifier.rb', line 125 def status if failed? "failed" else (incomplete? ? "incomplete" : "verified") end end |
#to_h ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/clickwrap/receipt_verifier.rb', line 137 def to_h { "success" => success?, "status" => status, "schema" => schema, "verifier_version" => Clickwrap::VERIFIER_VERSION, "checks" => checks.map do |check| { "name" => check.name, "passed" => check.passed, "detail" => check.detail } end } end |
#to_s ⇒ Object
149 150 151 152 153 154 |
# File 'lib/clickwrap/receipt_verifier.rb', line 149 def to_s lines = ["#{status.upcase} (#{schema || "unknown schema"})"] lines.concat(checks.map { |check| " #{check}" }) lines << " note: #{PROVES}" lines.join("\n") end |
#verified? ⇒ Boolean Also known as: success?
119 |
# File 'lib/clickwrap/receipt_verifier.rb', line 119 def verified? = failures.empty? && skipped.empty? |