Sha256: 5415aad01ef04cb282b4bdc09fdd64aee7ee7e65eaee4d646ad3fa49479f626b

Contents?: true

Size: 668 Bytes

Versions: 5

Compression:

Stored size: 668 Bytes

Contents

module PipeRpc
  class ResultResponse
    def initialize(args = {})
      @result = sanitize(args.fetch(:result))
      @id = args.fetch(:id)
    end

    attr_reader :result, :id

    def result_for(request)
      result
    end

    def to_h
      { id: id, result: result }
    end

    private

    def sanitize(result)
      if true == result or false == result or nil == result or result.is_a?(String) or result.is_a?(Numeric)
        result
      elsif result.is_a?(Array)
        result.map{ |v| sanitize(v) }
      elsif result.is_a?(Hash)
        Hash[result.map{ |k,v| [sanitize(k), sanitize(v)] }]
      else
        result.to_s
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pipe_rpc-0.3.2 lib/pipe_rpc/result_response.rb
pipe_rpc-0.3.1 lib/pipe_rpc/result_response.rb
pipe_rpc-0.3.0 lib/pipe_rpc/result_response.rb
pipe_rpc-0.2.2 lib/pipe_rpc/result_response.rb
pipe_rpc-0.2.0 lib/pipe_rpc/result_response.rb