class Flexirest::ResultIterator
Attributes
Public Class Methods
Source
# File lib/flexirest/result_iterator.rb, line 10 def initialize(response = nil) @_status = response.try :status @_headers = response.try :response_headers @items = [] end
Public Instance Methods
Source
# File lib/flexirest/result_iterator.rb, line 62 def []=(key, value) @items[key] = value end
Source
# File lib/flexirest/result_iterator.rb, line 20 def _clean! @items.map(&:_clean!) end
Source
# File lib/flexirest/result_iterator.rb, line 71 def delete_if(&block) @items = @items.delete_if &block self end
Source
# File lib/flexirest/result_iterator.rb, line 48 def each @items.each do |el| yield el end end
Source
# File lib/flexirest/result_iterator.rb, line 36 def index(...) @items.index(...) end
Source
# File lib/flexirest/result_iterator.rb, line 32 def join(*args) @items.join(*args) end
Source
# File lib/flexirest/result_iterator.rb, line 107 def paginate(options = {}) raise WillPaginateNotAvailableException.new unless Object.constants.include?(:WillPaginate) page = options[:page] || 1 per_page = options[:per_page] || WillPaginate.per_page total = options[:total_entries] || @items.length WillPaginate::Collection.create(page, per_page, total) do |pager| pager.replace @items[pager.offset, pager.per_page].to_a end end
Source
# File lib/flexirest/result_iterator.rb, line 90 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
Source
# File lib/flexirest/result_iterator.rb, line 44 def reverse @reversed_items ||= @items.reverse end
Source
# File lib/flexirest/result_iterator.rb, line 66 def shuffle @items = @items.shuffle self end
Source
# File lib/flexirest/result_iterator.rb, line 76 def where(criteria={}) @items.select do |object| select = true criteria.each do |k, v| if v.is_a?(Regexp) select = false if !object[k][v] else select = false if object[k] != v end end select end end