Class: JSONAPIonify::CustomRescue
- Inherits:
-
Object
- Object
- JSONAPIonify::CustomRescue
- Defined in:
- lib/jsonapionify/custom_rescue.rb
Defined Under Namespace
Classes: Error
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(remove: [], source: nil, formatter:, &block) ⇒ CustomRescue
constructor
A new instance of CustomRescue.
- #perform ⇒ Object
- #source_location ⇒ Object
Constructor Details
#initialize(remove: [], source: nil, formatter:, &block) ⇒ CustomRescue
Returns a new instance of CustomRescue.
10 11 12 13 14 15 16 17 |
# File 'lib/jsonapionify/custom_rescue.rb', line 10 def initialize(remove: [], source: nil, formatter:, &block) @block = block @formatter = formatter @source = source || block @locs = Array.wrap remove f, l = self.class.method(:perform).source_location @locs << [f, l+1].join(':') end |
Class Method Details
.perform(**opts, &block) ⇒ Object
6 7 8 |
# File 'lib/jsonapionify/custom_rescue.rb', line 6 def self.perform(**opts, &block) new(**opts, &block).perform end |
Instance Method Details
#perform ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jsonapionify/custom_rescue.rb', line 23 def perform @block.call rescue => e loc = [__FILE__, __LINE__-2].join(':') formatted_value = @formatter.unstrict.call(Error.new(e, @source)) index = e.backtrace.index { |l| l.include? loc } e.backtrace[index] = formatted_value if index && formatted_value e.backtrace.delete_if { |l| @locs.any? { |rl| l.include? rl } } raise e end |
#source_location ⇒ Object
19 20 21 |
# File 'lib/jsonapionify/custom_rescue.rb', line 19 def source_location source.source_location end |