class PryRemoteEm::Sandbox

See Readme for Sandbox using guide

Attributes

pry[RW]
server[RW]

Public Class Methods

add_error(exception, source_binding = nil) click to toggle source
# File lib/pry-remote-em/sandbox.rb, line 32
def self.add_error(exception, source_binding = nil)
  unless exception.kind_of?(Exception) && (source_binding.nil? || source_binding.kind_of?(Binding))
    raise ArgumentError, 'exception and optional binding expected'
  end

  return if @@last_errors.map(&:object_id).include?(exception.object_id) || @@ignore_errors.include?(exception.class)

  timestamp = Time.now
  exception.define_singleton_method(:source_timestamp) { timestamp }

  exception.define_singleton_method(:source_binding) { source_binding } if source_binding

  @@last_errors.push(exception)
  @@error_classes[exception.class] += 1
  Metrics.add(:errors)

  maximum_errors = ENV['PRYEMSANDBOXERRORS'].nil? || ENV['PRYEMSANDBOXERRORS'].empty? ? MAXIMUM_ERRORS_IN_SANDBOX : ENV['PRYEMSANDBOXERRORS'].to_i
  @@last_errors.shift if @@last_errors.size > maximum_errors
end
any_errors?() click to toggle source
# File lib/pry-remote-em/sandbox.rb, line 56
def self.any_errors?
  @@last_errors.any?
end
ignore_errors() click to toggle source
# File lib/pry-remote-em/sandbox.rb, line 64
def self.ignore_errors
  @@ignore_errors
end
last_error() click to toggle source
# File lib/pry-remote-em/sandbox.rb, line 60
def self.last_error
  @@last_errors.last
end
last_errors() click to toggle source
# File lib/pry-remote-em/sandbox.rb, line 52
def self.last_errors
  @@last_errors
end

Public Instance Methods

error_classes() click to toggle source
# File lib/pry-remote-em/sandbox.rb, line 22
def error_classes
  return puts 'No errors, yay!' if @@error_classes.empty?
  puts @@error_classes.map { |key, value| "#{key}: #{value}" }
end
error_history() click to toggle source
# File lib/pry-remote-em/sandbox.rb, line 27
def error_history
  return puts 'No errors, yay!' unless any_errors?
  puts @@last_errors.map { |error| "#{error.source_timestamp} #{"#{error.class}: #{error.message}".sub(/(?<=^.{51}).{4,}$/, '...')}" }
end
inspect() click to toggle source

Safely show in Pry prompt

# File lib/pry-remote-em/sandbox.rb, line 82
def inspect
  'sandbox'
end
show_metrics() click to toggle source

Metrics related methods

# File lib/pry-remote-em/sandbox.rb, line 76
def show_metrics
  puts Metrics.list.map { |key, value| "#{key}: #{value}" }
end