Class: Rundoc::CodeCommand::Repl

Inherits:
Rundoc::CodeCommand show all
Defined in:
lib/rundoc/code_command/repl.rb

Instance Attribute Summary

Attributes inherited from Rundoc::CodeCommand

#command, #contents, #keyword, #original_args, #render_command, #render_result

Instance Method Summary collapse

Methods inherited from Rundoc::CodeCommand

#hidden?, #not_hidden?, #push

Constructor Details

#initialize(command) ⇒ Repl

Returns a new instance of Repl.



6
7
8
9
# File 'lib/rundoc/code_command/repl.rb', line 6

def initialize(command)
  @command     = command
  @contents = ""
end

Instance Method Details

#call(env = {}) ⇒ Object



21
22
23
24
25
26
# File 'lib/rundoc/code_command/repl.rb', line 21

def call(env = {})
  puts "Running '#{@command}'' with repl: #{keyword}"
  repl    = ReplRunner.new(:"#{keyword}", @command)
  @result = repl.zip(contents.strip).flatten.join("\n")
  return @result
end

#keyword=(keyword) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/rundoc/code_command/repl.rb', line 11

def keyword=(keyword)
  @keyword = keyword
  if keyword.to_s == "repl"
    command_array = @command.split(" ")
    @keyword      = command_array.first
  else
    @command = "#{keyword} #{@command}"
  end
end

#to_md(env = {}) ⇒ Object



28
29
30
# File 'lib/rundoc/code_command/repl.rb', line 28

def to_md(env = {})
  return "$ #{@command}"
end