Exception: NRSER::AbstractMethodError
- Includes:
- Log::Mixin, NicerError
- Defined in:
- lib/nrser/errors/abstract_method_error.rb
Overview
Extension of Ruby’s NotImplementedError to provide a useful message and convenient constructor for abstract methods.
This is a NicerError.
Constant Summary
Constants included from NicerError
NicerError::DEFAULT_COLUMN_WIDTH
Instance Attribute Summary collapse
-
#instance ⇒ attr_type
readonly
TODO document ‘instance` attribute.
-
#method_instance ⇒ Method
readonly
TODO document ‘method_instance` attribute.
-
#method_name ⇒ Symbol
readonly
The abstract method’s name that was called¹.
Instance Method Summary collapse
- #context ⇒ Object
- #default_message ⇒ Object
- #details ⇒ Object
-
#initialize(instance, method_name) ⇒ AbstractMethodError
constructor
Construct a new ‘AbstractMethodError`.
- #method_full_name ⇒ Object
- #method_owner ⇒ Object
- #method_owner_name ⇒ Object
Methods included from Log::Mixin
Methods included from NicerError
#add_extended_message?, column_width, #context_section, #details_section, #extended_message, #format_message, #format_message_segment, included, #to_s
Constructor Details
#initialize(instance, method_name) ⇒ AbstractMethodError
Construct a new ‘AbstractMethodError`.
65 66 67 68 69 70 71 |
# File 'lib/nrser/errors/abstract_method_error.rb', line 65 def initialize instance, method_name @instance = instance @method_name = method_name @method_instance = instance.method @method_name super() end |
Instance Attribute Details
#instance ⇒ attr_type (readonly)
TODO document ‘instance` attribute.
53 54 55 |
# File 'lib/nrser/errors/abstract_method_error.rb', line 53 def instance @instance end |
#method_instance ⇒ Method (readonly)
TODO document ‘method_instance` attribute.
45 46 47 |
# File 'lib/nrser/errors/abstract_method_error.rb', line 45 def method_instance @method_instance end |
#method_name ⇒ Symbol (readonly)
The abstract method’s name that was called¹.
> ¹ I mean, that’s what it should be, it’s really just what was passed > as the ‘method_name:` keyword to #initialize.
38 39 40 |
# File 'lib/nrser/errors/abstract_method_error.rb', line 38 def method_name @method_name end |
Instance Method Details
#context ⇒ Object
113 114 115 116 117 118 |
# File 'lib/nrser/errors/abstract_method_error.rb', line 113 def context { instance: instance, method_name: method_name, } end |
#default_message ⇒ Object
121 122 123 |
# File 'lib/nrser/errors/abstract_method_error.rb', line 121 def "Method ##{ method_name.to_s } is abstract" end |
#details ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/nrser/errors/abstract_method_error.rb', line 126 def details @details ||= if method_owner == instance.class <<~END Method #{ method_full_name } is abstract, meaning #{ method_owner_name } is an abstract class and the invoking instance #{ instance } should NOT have been constructed. END else <<~END Method #{ method_full_name } is abstract and has not been implemented in invoking class #{ instance.class }. If you *are* developing the invoking class #{ instance.class } it (or a parent class between it and #{ method_owner_name }) must implement ##{ method_name.to_s }. If you *are not* developing #{ instance.class } it should be treated as an abstract base class and should NOT be constructed. You need to find a subclass of #{ instance.class } to instantiate or write your own. END end end |
#method_full_name ⇒ Object
106 107 108 109 110 |
# File 'lib/nrser/errors/abstract_method_error.rb', line 106 def method_full_name lazy_var :@method_full_name do "#{ method_owner_name }##{ method_name.to_s }" end end |
#method_owner ⇒ Object
88 89 90 91 92 |
# File 'lib/nrser/errors/abstract_method_error.rb', line 88 def method_owner lazy_var :@method_owner do method_instance && method_instance.owner end end |
#method_owner_name ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/nrser/errors/abstract_method_error.rb', line 95 def method_owner_name lazy_var :@method_owner_name do if method_owner method_owner.safe_name else '???' end end end |