Class: Izanami::Channel::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/izanami/channel.rb

Overview

Handles the input written to the channel.

Instance Method Summary collapse

Constructor Details

#initialize(mapper, id) ⇒ Input

Returns a new instance of Input.

Parameters:

  • mapper (Izanami::Mapper::Command)

    the instance which talks to redis.

  • id (String)

    the command id.



24
25
26
27
28
# File 'lib/izanami/channel.rb', line 24

def initialize(mapper, id)
  @mapper  = mapper
  @id      = id
  @content = []
end

Instance Method Details

#<<(payload) ⇒ Object Also known as: add

Add new content to the channel.

Parameters:

  • payload (String)

    the new content to add.



33
34
35
36
# File 'lib/izanami/channel.rb', line 33

def <<(payload)
  @mapper.publish(@id, payload)
  @content << payload
end

#closeString

Closes the channel.

It stores all the content sent and sends an EOC signal

Returns:

  • (String)

    all the written content.



44
45
46
47
48
49
50
# File 'lib/izanami/channel.rb', line 44

def close
  string = to_s
  @mapper.update(@id, 'output', string)
  @mapper.publish(@id, EOC)

  string
end

#to_sString Also known as: read

Note:

each line of the content is separated by SEPARATOR.

Content that has been written.

Returns:

  • (String)


57
58
59
# File 'lib/izanami/channel.rb', line 57

def to_s
  @content.join(SEPARATOR)
end