Module: ZQ::Orchestra
- Included in:
- Echo
- Defined in:
- lib/zq/orchestra.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #initialize ⇒ Object
- #process_forever(interval = 1) ⇒ Object
- #process_until_exhausted ⇒ Object
- #process_with_interval(interval) ⇒ Object
Class Method Details
.included(base) ⇒ Object
53 54 55 56 |
# File 'lib/zq/orchestra.rb', line 53 def self.included(base) ::ZQ.autoregister_orchestra(base) base.extend ClassMethods end |
Instance Method Details
#initialize ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/zq/orchestra.rb', line 83 def initialize @source, @composers = [:@source, :@composers].map do |m| self.class.instance_variable_get(m) end fail NoSourceProvided unless @source fail NoComposerProvided unless @composers end |
#process_forever(interval = 1) ⇒ Object
91 92 93 94 95 |
# File 'lib/zq/orchestra.rb', line 91 def process_forever(interval = 1) loop do process_with_interval(interval) end end |
#process_until_exhausted ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/zq/orchestra.rb', line 102 def process_until_exhausted loop do item = @source.read_next break if item.nil? composite = nil @composers.each do |c| composite = c.compose item, composite end end end |
#process_with_interval(interval) ⇒ Object
97 98 99 100 |
# File 'lib/zq/orchestra.rb', line 97 def process_with_interval(interval) process_until_exhausted Kernel.sleep(interval) end |