Class: Streamer::StreamBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/streamer/stream_builder.rb

Overview

StreamBuilder takes a stream configuration and builds the stream defined in it. StreamBuilder then performs the stream, given a document.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ StreamBuilder

Returns a new instance of StreamBuilder.



6
7
8
# File 'lib/streamer/stream_builder.rb', line 6

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/streamer/stream_builder.rb', line 5

def config
  @config
end

#payloadObject (readonly)

Returns the value of attribute payload.



5
6
7
# File 'lib/streamer/stream_builder.rb', line 5

def payload
  @payload
end

Instance Method Details

#filter_valueObject



25
26
27
28
29
30
# File 'lib/streamer/stream_builder.rb', line 25

def filter_value
  config[:filter].inject(true) do |val, f|
    val &&= stream.filter(function: f[:function]).payload['filter_value']
    val
  end
end

#process(payload) ⇒ Object



10
11
12
13
14
15
# File 'lib/streamer/stream_builder.rb', line 10

def process(payload)
  @payload = payload
  stream.payload['filter_value'] = filter_value
  transform if stream.payload['filter_value']
  stream
end

#streamObject



32
33
34
# File 'lib/streamer/stream_builder.rb', line 32

def stream
  @stream ||= Stream.new(payload)
end

#transformObject



17
18
19
20
21
22
23
# File 'lib/streamer/stream_builder.rb', line 17

def transform
  config[:transform].each do |tx|
    tx.each do |k, v|
      stream.send(k, v)
    end
  end
end