class Rundoc::CodeCommand::Pipe

Public Class Methods

new(line) click to toggle source
:

ls

:

| tail -n 2

> “testntmp.filen”

# File lib/rundoc/code_command/pipe.rb, line 7
def initialize(line)
  @delegate = parse(line)
end

Public Instance Methods

call(env = {}) click to toggle source

before: “”, after: “”, commands:

[[cmd, output], [cmd, output]]
# File lib/rundoc/code_command/pipe.rb, line 15
def call(env = {})
  last_command = env[:commands].last
  puts "Piping: results of '#{last_command[:command]}' to '#{@delegate}'"

  @delegate.push(last_command[:output])
  @delegate.call(env)
end
to_md(env = {}) click to toggle source
# File lib/rundoc/code_command/pipe.rb, line 23
def to_md(env = {})
  ""
end

Private Instance Methods

parse(code) click to toggle source
# File lib/rundoc/code_command/pipe.rb, line 27
        def parse(code)
  parser = Rundoc::PegParser.new.method_call
  tree = parser.parse(code)
  actual = Rundoc::PegTransformer.new.apply(tree)

  actual = actual.first if actual.is_a?(Array)

  actual = Rundoc::CodeCommand::Bash.new(code) if actual.is_a?(Rundoc::CodeCommand::NoSuchCommand)
  actual

# Since `| tail -n 2` does not start with a `$` assume any "naked" commands
# are bash
rescue Parslet::ParseFailed
  Rundoc::CodeCommand::Bash.new(code)
end