Sha256: c1104483cc9325228e68b847c1671c713557389e80dba6191217d87a30b41afe

Contents?: true

Size: 1022 Bytes

Versions: 12

Compression:

Stored size: 1022 Bytes

Contents

module Isomorfeus
  module Transport
    class RequestAgent
      class << self
        def agents
          @_agents ||= {}
        end

        def get(object_id)
          agents[object_id]
        end

        def get!(object_id)
          agents.delete(object_id.to_s)
        end
      end

      attr_accessor :processed
      attr_accessor :result
      attr_accessor :response
      attr_accessor :full_response
      attr_accessor :sent
      attr_reader :id
      attr_reader :promise
      attr_reader :request

      def initialize(request = nil)
        @id = object_id.to_s
        self.class.agents[@id] = self
        @promise = Promise.new
        @request = request
        @sent = false
      end

      def process(&block)
        return self.result if self.processed
        self.processed = true
        Isomorfeus.raise_error(message: self.response[:error]) if self.response.key?(:error)
        self.result = block.call(self)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
isomorfeus-transport-2.2.1 lib/isomorfeus/transport/request_agent.rb
isomorfeus-transport-2.2.0 lib/isomorfeus/transport/request_agent.rb
isomorfeus-transport-2.1.1 lib/isomorfeus/transport/request_agent.rb
isomorfeus-transport-2.1.0 lib/isomorfeus/transport/request_agent.rb
isomorfeus-transport-2.0.22 lib/isomorfeus/transport/request_agent.rb
isomorfeus-transport-2.0.21 lib/isomorfeus/transport/request_agent.rb
isomorfeus-transport-2.0.20 lib/isomorfeus/transport/request_agent.rb
isomorfeus-transport-2.0.19 lib/isomorfeus/transport/request_agent.rb
isomorfeus-transport-2.0.18 lib/isomorfeus/transport/request_agent.rb
isomorfeus-transport-2.0.17 lib/isomorfeus/transport/request_agent.rb
isomorfeus-transport-2.0.16 lib/isomorfeus/transport/request_agent.rb
isomorfeus-transport-2.0.15 lib/isomorfeus/transport/request_agent.rb