Module: FPM::Fry::WithData

Overview

Adds a data method to an exception. This overrides initialize so it may not work everywhere.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataHash (readonly)

Returns debugging/logging data.

Returns:

  • (Hash)

    debugging/logging data



24
25
26
# File 'lib/fpm/fry/with_data.rb', line 24

def data
  @data
end

Instance Method Details

#initialize(data = {}) ⇒ Object #initialize(cause, data = {}) ⇒ Object #initialize(message, data = {}) ⇒ Object

Overloads:

  • #initialize(data = {}) ⇒ Object

    Parameters:

    • data (Hash) (defaults to: {})
  • #initialize(cause, data = {}) ⇒ Object

    If cause responds to #data the data will be merged.

    Parameters:

    • cause (Exception)
    • data (Hash) (defaults to: {})
  • #initialize(message, data = {}) ⇒ Object

    Parameters:

    • message (String)
    • data (Hash) (defaults to: {})


38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fpm/fry/with_data.rb', line 38

def initialize(e=self.class.name, data = {})
  if e.kind_of? Exception
    if e.respond_to? :data
      @data = e.data.merge(data)
    else
      @data = data.dup.freeze
    end
    super(e.message)
  else
    @data = data.dup.freeze
    super(e.to_s)
  end
end