class Boechat::Core::Service::RequestList

Class to save all user request objects to execute them one at a time or all in parallel

Attributes

requests[R]

Public Class Methods

new(requests = {}) click to toggle source
# File lib/boechat/core/service/request_list.rb, line 10
def initialize(requests = {})
  @requests = requests
end

Public Instance Methods

[](key) click to toggle source
# File lib/boechat/core/service/request_list.rb, line 30
def [](key)
  requests[key]
end
[]=(key, requester) click to toggle source
# File lib/boechat/core/service/request_list.rb, line 26
def []=(key, requester)
  requests[key] = requester
end
call(request_identifier = nil) click to toggle source
# File lib/boechat/core/service/request_list.rb, line 14
def call(request_identifier = nil)
  if request_identifier.nil?
    hydra = Typhoeus::Hydra.hydra
    requests.each_pair { |_key, request| hydra.queue(request.call) }
    hydra.run
  elsif requests.key?(request_identifier)
    requests[request_identifier].call
  end

  self
end