Class: RemoteRuby::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_ruby/compiler.rb

Overview

Receives client Ruby code, locals and their values and creates Ruby code to be executed on the remote host.

Instance Method Summary collapse

Constructor Details

#initialize(ruby_code, client_locals: {}, flavours: []) ⇒ Compiler

Returns a new instance of Compiler.


9
10
11
12
13
# 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

Instance Method Details

#client_locals_base64Object


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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_hashObject


15
16
17
# File 'lib/remote_ruby/compiler.rb', line 15

def code_hash
  @code_hash ||= Digest::SHA256.hexdigest(compiled_code)
end

#compiled_codeObject


19
20
21
22
23
24
25
26
# 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