Class: Fragmentary::RequestQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/fragmentary/request_queue.rb

Defined Under Namespace

Classes: Sender

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_type, host_root_url) ⇒ RequestQueue

Returns a new instance of RequestQueue.



11
12
13
14
15
16
17
18
19
# File 'lib/fragmentary/request_queue.rb', line 11

def initialize(user_type, host_root_url)
  @user_type = user_type
  # host_root_url represents where the queued *requests* are to be processed. For internal sessions it also represents where
  # the *queue* will be processed by delayed_job. For external requests, the queue will be processed by the host creating the
  # queue and the requests will be explicitly sent to the host_root_url.
  @host_root_url = host_root_url
  @requests = []
  self.class.all << self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



52
53
54
# File 'lib/fragmentary/request_queue.rb', line 52

def method_missing(method, *args)
  sender.send(method, *args)
end

Instance Attribute Details

#host_root_urlObject (readonly)

Returns the value of attribute host_root_url.



9
10
11
# File 'lib/fragmentary/request_queue.rb', line 9

def host_root_url
  @host_root_url
end

#requestsObject (readonly)

Returns the value of attribute requests.



9
10
11
# File 'lib/fragmentary/request_queue.rb', line 9

def requests
  @requests
end

#user_typeObject (readonly)

Returns the value of attribute user_type.



9
10
11
# File 'lib/fragmentary/request_queue.rb', line 9

def user_type
  @user_type
end

Class Method Details

.allObject



5
6
7
# File 'lib/fragmentary/request_queue.rb', line 5

def self.all
  @@all ||= []
end

Instance Method Details

#<<(request) ⇒ Object



21
22
23
24
25
26
# File 'lib/fragmentary/request_queue.rb', line 21

def <<(request)
  unless @requests.find{|r| r == request}
    @requests << request
  end
  self
end

#clearObject



36
37
38
# File 'lib/fragmentary/request_queue.rb', line 36

def clear
  @requests = []
end

#next_requestObject



32
33
34
# File 'lib/fragmentary/request_queue.rb', line 32

def next_request
  @requests.shift
end

#remove_path(path) ⇒ Object



40
41
42
# File 'lib/fragmentary/request_queue.rb', line 40

def remove_path(path)
  requests.delete_if{|r| r.path == path}
end

#send(**args) ⇒ Object



48
49
50
# File 'lib/fragmentary/request_queue.rb', line 48

def send(**args)
  sender.start(args)
end

#senderObject



44
45
46
# File 'lib/fragmentary/request_queue.rb', line 44

def sender
  @sender ||= Sender.new(self)
end

#sizeObject



28
29
30
# File 'lib/fragmentary/request_queue.rb', line 28

def size
  @requests.size
end