Class: LanguageProtocol

Inherits:
Object
  • Object
show all
Defined in:
lib/raka/protocol.rb

Overview

There are two methods to provide code to a language protocol, either a string literal OR a ruby block. Cannot choose both.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language_impl, script_template: '<code>') ⇒ LanguageProtocol

Returns a new instance of LanguageProtocol.



40
41
42
43
44
45
46
# File 'lib/raka/protocol.rb', line 40

def initialize(language_impl, script_template: '<code>')
  # contextual variables, will be passed later
  @impl = language_impl
  @script_template = script_template
  @block = nil
  @text = nil
end

Instance Attribute Details

#block=(value) ⇒ Object (writeonly)

Sets the attribute block

Parameters:

  • value

    the value to set the attribute block to.



30
31
32
# File 'lib/raka/protocol.rb', line 30

def block=(value)
  @block = value
end

Instance Method Details

#*(text) ⇒ Object

for syntax sugar like shell* <code text>



49
50
51
52
# File 'lib/raka/protocol.rb', line 49

def *(text)
  @text = text
  [self]
end

#call(env, task) ⇒ Object

a block::str -> str should be given to resolve the bindings in code text



55
56
57
58
59
60
61
62
63
64
# File 'lib/raka/protocol.rb', line 55

def call(env, task)
  code = yield @text if @text
  code = @block.call(task) if @block # do not resolve

  env.logger.debug code.chomp
  script_text = @impl.build(wrap_template(remove_common_indent(code)), task)
  temp_script = create_tmp(script_text)
  @impl.run_script env, temp_script, task
  env.logger.debug script_text.chomp
end