Module: Foobara::CommandPatternImplementation::Concerns::ErrorsType::ClassMethods
- Defined in:
- foobara-0.2.7/projects/command/src/command_pattern_implementation/concerns/errors_type.rb
Instance Method Summary collapse
-
#error_context_type_map ⇒ Object
TODO: kill this method in favor of possible_errors.
- #manually_added_possible_input_errors ⇒ Object
- #possible_error(*args) ⇒ Object
- #possible_errors ⇒ Object
- #possible_input_error(path, symbol_or_error_class, error_class_or_subclass_parameters = {}, data = nil) ⇒ Object
- #process_error_constants ⇒ Object
- #register_possible_error_class(possible_error) ⇒ Object
- #unregister_possible_error_if_registered(possible_error) ⇒ Object
Instance Method Details
#error_context_type_map ⇒ Object
TODO: kill this method in favor of possible_errors
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'projects/command/src/command_pattern_implementation/concerns/errors_type.rb', line 100 def error_context_type_map return @error_context_type_map if defined?(@error_context_type_map) process_error_constants map = if superclass < Foobara::Command superclass.error_context_type_map.dup end || {} @error_context_type_map = if @error_context_type_map map.merge(@error_context_type_map) else map end inputs_association_paths&.each do |data_path| possible_input_error(data_path.to_sym, CommandPatternImplementation::NotFoundError) end @error_context_type_map end |
#manually_added_possible_input_errors ⇒ Object
95 96 97 |
# File 'projects/command/src/command_pattern_implementation/concerns/errors_type.rb', line 95 def manually_added_possible_input_errors @manually_added_possible_input_errors ||= [] end |
#possible_error(*args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'projects/command/src/command_pattern_implementation/concerns/errors_type.rb', line 26 def possible_error(*args) possible_error = case args.size when 1 arg = args.first if arg.is_a?(PossibleError) # TODO: test this code path # :nocov: arg # :nocov: elsif arg.is_a?(::Class) && arg < Foobara::Error PossibleError.new(arg) elsif arg.is_a?(::Symbol) error_class = Foobara::RuntimeError.subclass(mod: self, symbol: arg) PossibleError.new(error_class, symbol: arg) else # :nocov: raise ArgumentError, "Expected a PossibleError or an Error but got #{arg}" # :nocov: end when 2 symbol, subclass_parameters, data = args error_class = Foobara::RuntimeError.subclass( mod: self, **subclass_parameters, symbol: ) PossibleError.new(error_class, symbol:, data:) else # :nocov: raise ArgumentError, "Expected an error or a symbol and error context type declaration" # :nocov: end register_possible_error_class(possible_error) end |
#possible_errors ⇒ Object
22 23 24 |
# File 'projects/command/src/command_pattern_implementation/concerns/errors_type.rb', line 22 def possible_errors error_context_type_map.values end |
#possible_input_error(path, symbol_or_error_class, error_class_or_subclass_parameters = {}, data = nil) ⇒ Object
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 91 92 93 |
# File 'projects/command/src/command_pattern_implementation/concerns/errors_type.rb', line 65 def possible_input_error( path, symbol_or_error_class, error_class_or_subclass_parameters = {}, data = nil ) error_class = if symbol_or_error_class.is_a?(Class) symbol_or_error_class else Foobara::DataError.subclass( mod: self, **error_class_or_subclass_parameters, symbol: symbol_or_error_class ) end symbol = error_class.symbol possible_error = PossibleError.new(error_class, symbol:, data:) if path.is_a?(::String) || path.is_a?(::Symbol) path = path.to_s.split(".") end possible_error.prepend_path!(path) possible_error.manually_added = true register_possible_error_class(possible_error) end |
#process_error_constants ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'projects/command/src/command_pattern_implementation/concerns/errors_type.rb', line 8 def process_error_constants return if @error_constants_processed @error_constants_processed = true Util.constant_values(self, extends: Foobara::RuntimeError).each do |error_class| key = PossibleError.new(error_class).key.to_s unless error_context_type_map.key?(key) possible_error error_class end end end |
#register_possible_error_class(possible_error) ⇒ Object
121 122 123 124 125 126 127 |
# File 'projects/command/src/command_pattern_implementation/concerns/errors_type.rb', line 121 def register_possible_error_class(possible_error) if possible_error.manually_added manually_added_possible_input_errors << possible_error end error_context_type_map[possible_error.key.to_s] = possible_error end |
#unregister_possible_error_if_registered(possible_error) ⇒ Object
129 130 131 132 |
# File 'projects/command/src/command_pattern_implementation/concerns/errors_type.rb', line 129 def unregister_possible_error_if_registered(possible_error) key = possible_error.key.to_s error_context_type_map.delete(key) end |