Class: Drum::StdioService

Inherits:
Service show all
Includes:
Log, YAMLUtils
Defined in:
lib/drum/service/stdio.rb

Overview

A service that reads from stdin and writes to stdout.

Instance Method Summary collapse

Methods included from Log

#log

Methods included from YAMLUtils

#from_yaml

Methods inherited from Service

#remove

Instance Method Details

#download(playlist_ref) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/drum/service/stdio.rb', line 32

def download(playlist_ref)
  if playlist_ref.resource_location.include?(:stdin)
    # TODO: Support multiple, --- delimited playlists?
    [Playlist.deserialize(from_yaml(STDIN.read))]
  else
    []
  end
end

#nameObject



13
14
15
# File 'lib/drum/service/stdio.rb', line 13

def name
  'stdio'
end

#parse_ref(raw_ref) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/drum/service/stdio.rb', line 17

def parse_ref(raw_ref)
  if raw_ref.is_token
    location = case raw_ref.text
    when 'stdout' then :stdout
    when 'stdin' then :stdin
    else return nil
    end
    Ref.new(self.name, :any, [location])
  elsif raw_ref.text == '-'
    Ref.new(self.name, :any, [:stdin, :stdout])
  else
    nil
  end
end

#upload(playlist_ref, playlists) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/drum/service/stdio.rb', line 41

def upload(playlist_ref, playlists)
  if playlist_ref.resource_location.include?(:stdout)
    playlists.each do |playlist|
      log.all playlist.serialize.to_yaml
    end
    nil
  else
    raise 'Cannot upload to somewhere other than stdout!'
  end
end