Class: Qravan::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/qravan/query/request.rb

Overview

Requests processing class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, cargo = {}) ⇒ Request

Returns a new instance of Request.



10
11
12
13
14
15
16
17
18
# File 'lib/qravan/query/request.rb', line 10

def initialize(request, cargo = {})
  @query = request["query"]
  @credentials = request["credentials"]
  @resources = []
  @cargo ||= cargo

  validate
  extract_resources
end

Instance Attribute Details

#cargoObject

Returns the value of attribute cargo.



8
9
10
# File 'lib/qravan/query/request.rb', line 8

def cargo
  @cargo
end

#resourcesObject

Returns the value of attribute resources.



8
9
10
# File 'lib/qravan/query/request.rb', line 8

def resources
  @resources
end

#sourcesObject

Returns the value of attribute sources.



8
9
10
# File 'lib/qravan/query/request.rb', line 8

def sources
  @sources
end

Instance Method Details

#credentialsObject



36
37
38
# File 'lib/qravan/query/request.rb', line 36

def credentials
  @credentials
end

#extract_resourcesObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/qravan/query/request.rb', line 24

def extract_resources
  barrier = Async::Barrier.new
  barrier.async do
    @query.each do |key, resource|
      @resources << { key => Qravan::Resource.new(key, resource, cargo).extract }
    end
  ensure
    @resources
  end
  barrier.wait
end

#validateObject



20
21
22
# File 'lib/qravan/query/request.rb', line 20

def validate
  @query
end