Class: RemoteRuby::RemoteContext
- Inherits:
-
Object
- Object
- RemoteRuby::RemoteContext
- Defined in:
- lib/remote_ruby/remote_context.rb
Overview
This class is inlined to the remote script and used to collect errors and other information about the remote run. It is serialized and sent back to the client.
Instance Attribute Summary collapse
-
#error_backtrace ⇒ Object
readonly
Returns the value of attribute error_backtrace.
-
#error_class ⇒ Object
readonly
Returns the value of attribute error_class.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#has_error ⇒ Object
readonly
Returns the value of attribute has_error.
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #dump ⇒ Object
- #error? ⇒ Boolean
- #execute(&block) ⇒ Object
- #handle_error(err) ⇒ Object
-
#initialize(filename) ⇒ RemoteContext
constructor
A new instance of RemoteContext.
- #unmarshal(name, data) ⇒ Object
Constructor Details
#initialize(filename) ⇒ RemoteContext
12 13 14 15 16 |
# File 'lib/remote_ruby/remote_context.rb', line 12 def initialize(filename) @file_name = filename @has_error = false @locals = {} end |
Instance Attribute Details
#error_backtrace ⇒ Object (readonly)
Returns the value of attribute error_backtrace.
10 11 12 |
# File 'lib/remote_ruby/remote_context.rb', line 10 def error_backtrace @error_backtrace end |
#error_class ⇒ Object (readonly)
Returns the value of attribute error_class.
10 11 12 |
# File 'lib/remote_ruby/remote_context.rb', line 10 def error_class @error_class end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
10 11 12 |
# File 'lib/remote_ruby/remote_context.rb', line 10 def end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
10 11 12 |
# File 'lib/remote_ruby/remote_context.rb', line 10 def file_name @file_name end |
#has_error ⇒ Object (readonly)
Returns the value of attribute has_error.
10 11 12 |
# File 'lib/remote_ruby/remote_context.rb', line 10 def has_error @has_error end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
10 11 12 |
# File 'lib/remote_ruby/remote_context.rb', line 10 def locals @locals end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
10 11 12 |
# File 'lib/remote_ruby/remote_context.rb', line 10 def result @result end |
Instance Method Details
#dump ⇒ Object
41 42 43 |
# File 'lib/remote_ruby/remote_context.rb', line 41 def dump Marshal.dump(self) end |
#error? ⇒ Boolean
18 19 20 |
# File 'lib/remote_ruby/remote_context.rb', line 18 def error? @has_error end |
#execute(&block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/remote_ruby/remote_context.rb', line 29 def execute(&block) @result = begin block.call rescue StandardError => e handle_error(e) ensure locals.each_key do |name| locals[name] = block.binding.local_variable_get(name) end end end |
#handle_error(err) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/remote_ruby/remote_context.rb', line 22 def handle_error(err) @error_class = err.class.to_s = err. @error_backtrace = err.backtrace @has_error = true end |
#unmarshal(name, data) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/remote_ruby/remote_context.rb', line 45 def unmarshal(name, data) locals[name] = Marshal.load(Base64.strict_decode64(data)) # rubocop:disable Security/MarshalLoad rescue ArgumentError warn("Warning: could not resolve type for '#{name}' variable") nil end |