Class: Tap::Tasks::Stream::Yaml

Inherits:
Tap::Tasks::Stream show all
Defined in:
lib/tap/tasks/stream/yaml.rb

Overview

:startdoc::task streams data as YAML

Stream loads data from the input IO as YAML.

[example.yml]
--- 
:sym
--- 
- 1
- 2
- 3
--- 
key: value

% tap stream/yaml --file example.yml -: inspect
:sym
[1, 2, 3]
{"key"=>"value"}

Instance Method Summary collapse

Instance Method Details

#load(io) ⇒ Object

Streams data from io as YAML.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tap/tasks/stream/yaml.rb', line 29

def load(io)
  lines = []
  
  while !io.eof?
    line = io.readline

    if line =~ /^---/ && !lines.empty?
      io.pos = io.pos - line.length
      break
    else
      lines << line
    end
  end

  YAML.load(lines.join)
end