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.



11
12
13
14
15
# File 'lib/remote_ruby/compiler.rb', line 11

def initialize(ruby_code, client_locals: {}, flavours: [])
  @ruby_code = ruby_code
  @client_locals = client_locals
  @flavours = flavours
end

Instance Method Details

#client_locals_base64Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/remote_ruby/compiler.rb', line 30

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



17
18
19
# File 'lib/remote_ruby/compiler.rb', line 17

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

#compiled_codeObject



21
22
23
24
25
26
27
28
# File 'lib/remote_ruby/compiler.rb', line 21

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