Class: Senko::Result
- Inherits:
-
Object
- Object
- Senko::Result
- Defined in:
- lib/senko/result.rb
Instance Attribute Summary collapse
-
#annotations ⇒ Object
readonly
Returns the value of attribute annotations.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #add_annotation(annotation) ⇒ Object
- #add_error(error) ⇒ Object
- #fail_fast? ⇒ Boolean
-
#initialize(fail_fast: false) ⇒ Result
constructor
A new instance of Result.
- #to_basic ⇒ Object
- #to_detailed ⇒ Object
- #to_verbose ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(fail_fast: false) ⇒ Result
Returns a new instance of Result.
9 10 11 12 13 |
# File 'lib/senko/result.rb', line 9 def initialize(fail_fast: false) @fail_fast = fail_fast @errors = [] @annotations = [] end |
Instance Attribute Details
#annotations ⇒ Object (readonly)
Returns the value of attribute annotations.
7 8 9 |
# File 'lib/senko/result.rb', line 7 def annotations @annotations end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/senko/result.rb', line 7 def errors @errors end |
Instance Method Details
#add_annotation(annotation) ⇒ Object
27 28 29 |
# File 'lib/senko/result.rb', line 27 def add_annotation(annotation) @annotations << annotation end |
#add_error(error) ⇒ Object
23 24 25 |
# File 'lib/senko/result.rb', line 23 def add_error(error) @errors << error end |
#fail_fast? ⇒ Boolean
19 20 21 |
# File 'lib/senko/result.rb', line 19 def fail_fast? @fail_fast end |
#to_basic ⇒ Object
31 32 33 34 35 |
# File 'lib/senko/result.rb', line 31 def to_basic payload = { 'valid' => valid? } payload['errors'] = @errors.map(&:to_h) unless valid? payload end |
#to_detailed ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/senko/result.rb', line 37 def to_detailed { 'valid' => valid?, 'keywordLocation' => '', 'instanceLocation' => '', 'errors' => @errors.map(&:to_h) }.tap do |payload| payload.delete('errors') if valid? end end |
#to_verbose ⇒ Object
48 49 50 51 52 53 |
# File 'lib/senko/result.rb', line 48 def to_verbose payload = to_detailed payload['annotations'] = @annotations unless @annotations.empty? payload['errors'] = @errors.map { |error| verbose_error(error) } unless valid? payload end |
#valid? ⇒ Boolean
15 16 17 |
# File 'lib/senko/result.rb', line 15 def valid? @errors.empty? end |