class RemoteRuby::Compiler
Receives client Ruby code, locals and their values and creates Ruby code to be executed on the remote host.
Attributes
client_locals[R]
flavours[R]
ruby_code[R]
Public Class Methods
new(ruby_code, client_locals: {}, flavours: [])
click to toggle source
# File lib/remote_ruby/compiler.rb, line 9 def initialize(ruby_code, client_locals: {}, flavours: []) @ruby_code = ruby_code @client_locals = client_locals @flavours = flavours end
Public Instance Methods
client_locals_base64()
click to toggle source
# File lib/remote_ruby/compiler.rb, line 28 def client_locals_base64 return @client_locals_base64 if @client_locals_base64 @client_locals_base64 = {} client_locals.each do |name, data| base64_data = process_local(name, data) next if base64_data.nil? @client_locals_base64[name] = base64_data end @client_locals_base64 end
code_hash()
click to toggle source
# File lib/remote_ruby/compiler.rb, line 15 def code_hash @code_hash ||= Digest::SHA256.hexdigest(compiled_code) end
compiled_code()
click to toggle source
# File lib/remote_ruby/compiler.rb, line 19 def compiled_code return @compiled_code if @compiled_code template_file = ::RemoteRuby.lib_path('remote_ruby/code_templates/compiler/main.rb.erb') template = ERB.new(File.read(template_file)) @compiled_code = template.result(binding) end
Private Instance Methods
code_headers()
click to toggle source
# File lib/remote_ruby/compiler.rb, line 54 def code_headers flavours.map(&:code_header) end
process_local(name, data)
click to toggle source
# File lib/remote_ruby/compiler.rb, line 47 def process_local(name, data) bin_data = Marshal.dump(data) Base64.strict_encode64(bin_data) rescue TypeError => e warn "Cannot send variable '#{name}': #{e.message}" end