Class: ActiveRestClient::ResultIterator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_rest_client/result_iterator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#_statusObject

Returns the value of attribute _status.



5
6
7
# File 'lib/active_rest_client/result_iterator.rb', line 5

def _status
  @_status
end

#itemsObject (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

#eachObject



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

Returns:

  • (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

#lastObject



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

#shuffleObject



43
44
45
46
# File 'lib/active_rest_client/result_iterator.rb', line 43

def shuffle
  @items = @items.shuffle
  self
end

#sizeObject



17
18
19
# File 'lib/active_rest_client/result_iterator.rb', line 17

def size
  @items.size
end