Class: RemoteRuby::Compiler
- Inherits:
-
Object
- Object
- RemoteRuby::Compiler
- 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
- #client_locals_base64 ⇒ Object
- #code_hash ⇒ Object
- #compiled_code ⇒ Object
-
#initialize(ruby_code, client_locals: {}, flavours: []) ⇒ Compiler
constructor
A new instance of Compiler.
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_base64 ⇒ Object
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_hash ⇒ Object
17 18 19 |
# File 'lib/remote_ruby/compiler.rb', line 17 def code_hash @code_hash ||= Digest::SHA256.hexdigest(compiled_code) end |
#compiled_code ⇒ Object
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 |