Class: PryRemoteEm::Sandbox
Overview
See Readme for Sandbox using guide
Constant Summary collapse
- @@last_errors =
Working with errors
[]
- @@ignore_errors =
[]
- @@error_classes =
Hash.new { |hash, key| hash[key] = 0 }
Instance Attribute Summary collapse
-
#pry ⇒ Object
Returns the value of attribute pry.
-
#server ⇒ Object
Returns the value of attribute server.
Class Method Summary collapse
- .add_error(exception, source_binding = nil) ⇒ Object
- .any_errors? ⇒ Boolean
- .ignore_errors ⇒ Object
- .last_error ⇒ Object
- .last_errors ⇒ Object
Instance Method Summary collapse
- #error_classes ⇒ Object
- #error_history ⇒ Object
-
#inspect ⇒ Object
Safely show in Pry prompt.
-
#show_metrics ⇒ Object
Metrics related methods.
Instance Attribute Details
#pry ⇒ Object
Returns the value of attribute pry.
6 7 8 |
# File 'lib/pry-remote-em/sandbox.rb', line 6 def pry @pry end |
#server ⇒ Object
Returns the value of attribute server.
6 7 8 |
# File 'lib/pry-remote-em/sandbox.rb', line 6 def server @server end |
Class Method Details
.add_error(exception, source_binding = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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) = Time.now exception.define_singleton_method(:source_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? ⇒ Boolean
56 57 58 |
# File 'lib/pry-remote-em/sandbox.rb', line 56 def self.any_errors? @@last_errors.any? end |
.ignore_errors ⇒ Object
64 65 66 |
# File 'lib/pry-remote-em/sandbox.rb', line 64 def self.ignore_errors @@ignore_errors end |
.last_error ⇒ Object
60 61 62 |
# File 'lib/pry-remote-em/sandbox.rb', line 60 def self.last_error @@last_errors.last end |
.last_errors ⇒ Object
52 53 54 |
# File 'lib/pry-remote-em/sandbox.rb', line 52 def self.last_errors @@last_errors end |
Instance Method Details
#error_classes ⇒ Object
22 23 24 25 |
# 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 ⇒ Object
27 28 29 30 |
# 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.} #{"#{error.class}: #{error.}".sub(/(?<=^.{51}).{4,}$/, '...')}" } end |
#inspect ⇒ Object
Safely show in Pry prompt
82 83 84 |
# File 'lib/pry-remote-em/sandbox.rb', line 82 def inspect 'sandbox' end |