Class: Jade::Diagnostics::List

Inherits:
Data
  • Object
show all
Defined in:
lib/jade/diagnostics.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items

Returns:

  • (Object)

    the current value of items



26
27
28
# File 'lib/jade/diagnostics.rb', line 26

def items
  @items
end

Class Method Details

.emptyObject



27
28
29
# File 'lib/jade/diagnostics.rb', line 27

def self.empty
  new(items: [])
end

Instance Method Details

#add(diagnostic) ⇒ Object



31
32
33
# File 'lib/jade/diagnostics.rb', line 31

def add(diagnostic)
  with(items: items + [diagnostic])
end

#any_errors?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/jade/diagnostics.rb', line 56

def any_errors?
  items.any?(&:error?)
end

#empty?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/jade/diagnostics.rb', line 60

def empty?
  items.empty?
end

#error(message, source:, span:, label: nil, secondary: [], annotations: []) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/jade/diagnostics.rb', line 35

def error(message, source:, span:, label: nil, secondary: [], annotations: [])
  add(Diagnostic.error(
    message,
    primary: Label[source, span, label],
    secondary:,
    annotations:,
  ))
end

#help(text) ⇒ Object



48
49
50
# File 'lib/jade/diagnostics.rb', line 48

def help(text)
  update_last { _1.annotate(:help, text) }
end

#merge(other) ⇒ Object



52
53
54
# File 'lib/jade/diagnostics.rb', line 52

def merge(other)
  with(items: items + other.items)
end

#note(text) ⇒ Object



44
45
46
# File 'lib/jade/diagnostics.rb', line 44

def note(text)
  update_last { _1.annotate(:note, text) }
end

#to_result(value) ⇒ Object



64
65
66
# File 'lib/jade/diagnostics.rb', line 64

def to_result(value)
  any_errors? ? Err.new(self) : Ok.new(value)
end