Class: Rundoc::CodeCommand::Background::StdinWrite

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

Overview

Will send contents to the background process via STDIN along with a newline

Constant Summary

Constants inherited from Rundoc::CodeCommand

NEWLINE, RUNDOC_DEFAULT_ERB_BINDING, RUNDOC_ERB_BINDINGS

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(contents, name:, wait:, timeout: 5, ending: $/) ⇒ StdinWrite

Returns a new instance of StdinWrite.



6
7
8
9
10
11
12
13
14
# File 'lib/rundoc/code_command/background/stdin_write.rb', line 6

def initialize(contents, name:, wait:, timeout: 5, ending: $/)
  @contents = contents
  @ending = ending
  @wait = wait
  @name = name
  @timeout_value = Integer(timeout)
  @contents_written = nil
  @background = nil
end

Instance Method Details

#backgroundObject



16
17
18
# File 'lib/rundoc/code_command/background/stdin_write.rb', line 16

def background
  @background ||= Rundoc::CodeCommand::Background::ProcessSpawn.find(@name)
end

#call(env = {}) ⇒ Object

The contents produced by the command (‘:::->`) are rendered by the `def to_md` method.



26
27
28
29
# File 'lib/rundoc/code_command/background/stdin_write.rb', line 26

def call(env = {})
  writecontents
  background.log.read
end

#to_md(env = {}) ⇒ Object

The command is rendered (‘:::>-`) by the output of the `def call` method.



21
22
23
# File 'lib/rundoc/code_command/background/stdin_write.rb', line 21

def to_md(env = {})
  writecontents
end

#writecontentsObject



31
32
33
34
35
36
37
38
# File 'lib/rundoc/code_command/background/stdin_write.rb', line 31

def writecontents
  @contents_written ||= background.stdin_write(
    contents,
    wait: @wait,
    ending: @ending,
    timeout: @timeout_value
  )
end