Class: Foobara::PossibleError

Inherits:
Object
  • Object
show all
Defined in:
foobara-0.1.7/projects/common/src/possible_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_class, key: nil, data: nil, symbol: error_class.symbol, category: error_class.category, processor: nil) ⇒ PossibleError

why can’t we set path here?



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'foobara-0.1.7/projects/common/src/possible_error.rb', line 6

def initialize(
  error_class,
  key: nil,
  data: nil,
  symbol: error_class.symbol,
  category: error_class.category,
  processor: nil
)
  self.error_class = error_class
  self.processor = processor
  self.data = if data
                data
              elsif processor
                { processor.symbol => processor.declaration_data }
              end
  self.key = if key
               if key.is_a?(ErrorKey)
                 key
               else
                 ErrorKey.parse(key)
               end
             else
               ErrorKey.new(symbol:, category:)
             end
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



3
4
5
# File 'foobara-0.1.7/projects/common/src/possible_error.rb', line 3

def data
  @data
end

#error_classObject

Returns the value of attribute error_class.



3
4
5
# File 'foobara-0.1.7/projects/common/src/possible_error.rb', line 3

def error_class
  @error_class
end

#keyObject

Returns the value of attribute key.



3
4
5
# File 'foobara-0.1.7/projects/common/src/possible_error.rb', line 3

def key
  @key
end

#manually_addedObject

Returns the value of attribute manually_added.



3
4
5
# File 'foobara-0.1.7/projects/common/src/possible_error.rb', line 3

def manually_added
  @manually_added
end

#processorObject

Returns the value of attribute processor.



3
4
5
# File 'foobara-0.1.7/projects/common/src/possible_error.rb', line 3

def processor
  @processor
end

Instance Method Details

#dupObject



32
33
34
35
36
37
38
# File 'foobara-0.1.7/projects/common/src/possible_error.rb', line 32

def dup
  PossibleError.new(
    error_class,
    key: key.dup,
    data:
  )
end

#foobara_manifestObject

TODO: technically does not belong in this project but maybe it should



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'foobara-0.1.7/projects/common/src/possible_error.rb', line 49

def foobara_manifest
  to_include = TypeDeclarations.foobara_manifest_context_to_include
  include_processors = TypeDeclarations.include_processors?

  if to_include
    to_include << error_class
  end

  h = key.to_h.merge(
    key: key.to_s,
    error: error_class.foobara_manifest_reference,
    manually_added:
  )

  if include_processors
    if processor
      processor_class = processor.class
      if to_include
        to_include << processor_class
      end

      if processor.scoped_path_set?
        # Unclear why nothing in the test suite passes through here.
        # TODO: either test this or delete it.
        # :nocov:
        to_include << processor
        processor_reference = processor.foobara_manifest_reference
        # :nocov:
      end
    end

    processor_manifest_data = data unless processor_reference

    h.merge!(
      processor: processor_reference,
      processor_class: processor_class&.foobara_manifest_reference,
      processor_manifest_data:
    )
  end

  Util.remove_blank(h)
end

#prepend_path!Object



40
41
42
# File 'foobara-0.1.7/projects/common/src/possible_error.rb', line 40

def prepend_path!(...)
  key.prepend_path!(...)
end

#prepend_runtime_path!Object



44
45
46
# File 'foobara-0.1.7/projects/common/src/possible_error.rb', line 44

def prepend_runtime_path!(...)
  key.prepend_runtime_path!(...)
end