Class: Datapipes::Source

Inherits:
Object
  • Object
show all
Includes:
Composable
Defined in:
lib/datapipes/source.rb

Overview

Build your own source logic in ‘run` method. Use `produce` method to emitt data to pipe.

def run
  10.times {|i| produce(i) }
end

You can use infinitie stream like:

def run
  twitter_client.userstream do |event|
    produce(event)
  end
end

Instance Attribute Summary collapse

Attributes included from Composable

#accumulated

Instance Method Summary collapse

Methods included from Composable

#+

Instance Attribute Details

#pipeObject

For internal uses. Do not touch.



35
36
37
# File 'lib/datapipes/source.rb', line 35

def pipe
  @pipe
end

Instance Method Details

#runObject

Override in sub class.



21
22
# File 'lib/datapipes/source.rb', line 21

def run
end

#run_allObject

For internal used.

Run accumulated sources which are set by composition. Each source works in new thread.



28
29
30
31
32
# File 'lib/datapipes/source.rb', line 28

def run_all
  @accumulated ||= [self]
  set_pipe
  @accumulated.map {|s| Thread.new { s.run } }
end