Class: Senko::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/senko/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#annotationsObject (readonly)

Returns the value of attribute annotations.



7
8
9
# File 'lib/senko/result.rb', line 7

def annotations
  @annotations
end

#errorsObject (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

Returns:

  • (Boolean)


19
20
21
# File 'lib/senko/result.rb', line 19

def fail_fast?
  @fail_fast
end

#to_basicObject



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_detailedObject



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_verboseObject



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

Returns:

  • (Boolean)


15
16
17
# File 'lib/senko/result.rb', line 15

def valid?
  @errors.empty?
end