Module: EventSource::Read

Included in:
Controls::Read::Example
Defined in:
lib/event_source/read.rb

Defined Under Namespace

Modules: Build, Call, Configure Classes: Error

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(cls) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/event_source/read.rb', line 3

def self.included(cls)
  cls.class_exec do
    include Log::Dependency

    cls.extend Build
    cls.extend Call
    cls.extend Configure

    dependency :iterator, Iterator
    dependency :get, Get

    initializer :stream_name

    abstract :configure
  end
end

Instance Method Details

#call(&action) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/event_source/read.rb', line 46

def call(&action)
  logger.trace { "Reading (Stream Name: #{stream_name})" }

  if action.nil?
    error_message = "Reader must be actuated with a block"
    logger.error error_message
    raise Error, error_message
  end

  enumerate_event_data(&action)

  logger.info { "Reading completed (Stream Name: #{stream_name})" }

  return AsyncInvocation::Incorrect
end

#enumerate_event_data(&action) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/event_source/read.rb', line 62

def enumerate_event_data(&action)
  logger.trace { "Enumerating (Stream Name: #{stream_name})" }

  event_data = nil

  loop do
    event_data = iterator.next

    break if event_data.nil?

    action.(event_data)
  end

  logger.debug { "Enumerated (Stream Name: #{stream_name})" }
end