Class: Skynet::TaskIterator
- Inherits:
-
Object
- Object
- Skynet::TaskIterator
- Includes:
- Enumerable, GuidGenerator, SkynetDebugger
- Defined in:
- lib/skynet/job.rb
Overview
class LocalMessageQueue
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#task_options ⇒ Object
Returns the value of attribute task_options.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each ⇒ Object
- #each_method ⇒ Object
- #first ⇒ Object
-
#initialize(task_options, data) ⇒ TaskIterator
constructor
A new instance of TaskIterator.
- #size ⇒ Object
- #to_a ⇒ Object
Methods included from Enumerable
Methods included from GuidGenerator
Methods included from SkynetDebugger
#args_pp, #debug, #debug_header, #error, #fatal, included, #info, #log, #printlog, #stderr, #stdout, #warn
Constructor Details
#initialize(task_options, data) ⇒ TaskIterator
Returns a new instance of TaskIterator.
830 831 832 833 |
# File 'lib/skynet/job.rb', line 830 def initialize(, data) @task_options = @data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
828 829 830 |
# File 'lib/skynet/job.rb', line 828 def data @data end |
#task_options ⇒ Object
Returns the value of attribute task_options.
828 829 830 |
# File 'lib/skynet/job.rb', line 828 def @task_options end |
Instance Method Details
#[](index) ⇒ Object
851 852 853 854 855 856 857 |
# File 'lib/skynet/job.rb', line 851 def [](index) if data.respond_to?(:[]) Skynet::Task.new(.merge(:data => data[index], :task_id => get_unique_id(1).to_i)) else raise Error.new("#{data.class} does not implement '[]'") end end |
#each ⇒ Object
867 868 869 870 871 872 873 874 875 876 877 878 879 880 |
# File 'lib/skynet/job.rb', line 867 def each iteration = 0 data.send(each_method) do |task_data| task = nil if @first and iteration == 0 task = @first else task = Skynet::Task.new(.merge(:data => task_data, :task_id => (get_unique_id(1).to_i))) @first = task if iteration == 0 end iteration += 1 yield task end end |
#each_method ⇒ Object
859 860 861 |
# File 'lib/skynet/job.rb', line 859 def each_method each_method = data.respond_to?(:next) ? :next : :each end |
#first ⇒ Object
835 836 837 838 839 840 841 |
# File 'lib/skynet/job.rb', line 835 def first if data.respond_to?(:first) @first ||= Skynet::Task.new(.merge(:data => data.first, :task_id => get_unique_id(1).to_i)) else raise Error.new("#{data.class} does not implement 'first'") end end |
#size ⇒ Object
843 844 845 846 847 848 849 |
# File 'lib/skynet/job.rb', line 843 def size if data.respond_to?(:size) data.size else raise Error.new("#{data.class} does not implement 'size'") end end |
#to_a ⇒ Object
863 864 865 |
# File 'lib/skynet/job.rb', line 863 def to_a self.collect { |task| task } end |