Class: ActiveRestClient::ResultIterator
- Inherits:
-
Object
- Object
- ActiveRestClient::ResultIterator
- Includes:
- Enumerable
- Defined in:
- lib/active_rest_client/result_iterator.rb
Instance Attribute Summary collapse
-
#_status ⇒ Object
Returns the value of attribute _status.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #[](key) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #index(value) ⇒ Object
-
#initialize(status = nil) ⇒ ResultIterator
constructor
A new instance of ResultIterator.
- #last ⇒ Object
- #parallelise(method = nil) ⇒ Object
- #shuffle ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(status = nil) ⇒ ResultIterator
Returns a new instance of ResultIterator.
8 9 10 11 |
# File 'lib/active_rest_client/result_iterator.rb', line 8 def initialize(status = nil) @_status = status @items = [] end |
Instance Attribute Details
#_status ⇒ Object
Returns the value of attribute _status.
5 6 7 |
# File 'lib/active_rest_client/result_iterator.rb', line 5 def _status @_status end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
6 7 8 |
# File 'lib/active_rest_client/result_iterator.rb', line 6 def items @items end |
Instance Method Details
#<<(item) ⇒ Object
13 14 15 |
# File 'lib/active_rest_client/result_iterator.rb', line 13 def <<(item) @items << item end |
#[](key) ⇒ Object
39 40 41 |
# File 'lib/active_rest_client/result_iterator.rb', line 39 def [](key) @items[key] end |
#each ⇒ Object
29 30 31 32 33 |
# File 'lib/active_rest_client/result_iterator.rb', line 29 def each @items.each do |el| yield el end end |
#empty? ⇒ Boolean
25 26 27 |
# File 'lib/active_rest_client/result_iterator.rb', line 25 def empty? size == 0 end |
#index(value) ⇒ Object
21 22 23 |
# File 'lib/active_rest_client/result_iterator.rb', line 21 def index(value) @items.index(value) end |
#last ⇒ Object
35 36 37 |
# File 'lib/active_rest_client/result_iterator.rb', line 35 def last @items.last end |
#parallelise(method = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/active_rest_client/result_iterator.rb', line 48 def parallelise(method=nil) collected_responses = [] threads = [] @items.each do |item| threads << Thread.new do ret = item.send(method) if method ret = yield(item) if block_given? Thread.current[:response] = ret end end threads.each do |t| t.join collected_responses << t[:response] end collected_responses end |
#shuffle ⇒ Object
43 44 45 46 |
# File 'lib/active_rest_client/result_iterator.rb', line 43 def shuffle @items = @items.shuffle self end |
#size ⇒ Object
17 18 19 |
# File 'lib/active_rest_client/result_iterator.rb', line 17 def size @items.size end |