Class: Pluggaloid::StreamGenerator::Yielder

Inherits:
Object
  • Object
show all
Defined in:
lib/pluggaloid/stream_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(event, args:) ⇒ Yielder



61
62
63
64
65
# File 'lib/pluggaloid/stream_generator.rb', line 61

def initialize(event, args:)
  @event = event
  @args = args.freeze
  @alive = true
end

Instance Method Details

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



74
75
76
# File 'lib/pluggaloid/stream_generator.rb', line 74

def add(value)
  bulk_add([value])
end

#bulk_add(lst) ⇒ Object



67
68
69
70
71
72
# File 'lib/pluggaloid/stream_generator.rb', line 67

def bulk_add(lst)
  raise Pluggaloid::NoReceiverError, "All event listener of #{self.class} already detached." if die?
  args = @args.dup
  args.insert(@event.stream_index, lst)
  @event.call(*args)
end

#dieObject



83
84
85
86
# File 'lib/pluggaloid/stream_generator.rb', line 83

def die
  @alive = false
  freeze
end

#die?Boolean



79
80
81
# File 'lib/pluggaloid/stream_generator.rb', line 79

def die?
  !@alive
end