Sha256: a8fd35e09dacde2ff5cbf151638462e6c771ad493c1b409a59b3f5a445c0c9c5

Contents?: true

Size: 1.36 KB

Versions: 8

Compression:

Stored size: 1.36 KB

Contents

require 'rollbar/notifier'
require 'rollbar/scrubbers/params'

module Rollbar
  class Item
    class Locals # :nodoc:
      class << self
        def exception_frames
          Rollbar.notifier.exception_bindings
        end

        def locals_for_location(filename, lineno)
          if (frame = frame_for_location(filename, lineno))
            scrub(locals_for(frame[:binding]))
          else
            {}
          end
        end

        def frame_for_location(filename, lineno)
          while (frame = exception_frames.pop)
            return nil unless frame
            return frame if matching_frame?(frame, filename, lineno)
          end
          nil
        end

        private

        def matching_frame?(frame, filename, lineno)
          frame[:path] == filename && frame[:lineno].to_i <= lineno.to_i
        end

        def locals_for(frame)
          {}.tap do |hash|
            frame.local_variables.map do |var|
              hash[var] = prepare_value(frame.local_variable_get(var))
            end
          end
        end

        def prepare_value(value)
          value.to_s
        end

        def scrub(hash)
          Rollbar::Scrubbers::Params.call(
            :params => hash,
            :config => Rollbar.configuration.scrub_fields,
            :whitelist => Rollbar.configuration.scrub_whitelist
          )
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rollbar-2.22.1 lib/rollbar/item/locals.rb
rollbar-2.22.0 lib/rollbar/item/locals.rb
rollbar-2.21.0 lib/rollbar/item/locals.rb
rollbar-2.20.2 lib/rollbar/item/locals.rb
rollbar-2.20.1 lib/rollbar/item/locals.rb
rollbar-2.20.0 lib/rollbar/item/locals.rb
rollbar-2.19.4 lib/rollbar/item/locals.rb
rollbar-2.19.3 lib/rollbar/item/locals.rb