Class: Fragmentary::RequestQueue
- Inherits:
-
Object
- Object
- Fragmentary::RequestQueue
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.
23
24
25
26
27
28
29
30
31
|
# File 'lib/fragmentary/request_queue.rb', line 23
def initialize(user_type, host_root_url)
@user_type = user_type
@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
64
65
66
|
# File 'lib/fragmentary/request_queue.rb', line 64
def method_missing(method, *args)
sender.send(method, *args)
end
|
Instance Attribute Details
#host_root_url ⇒ Object
Returns the value of attribute host_root_url.
21
22
23
|
# File 'lib/fragmentary/request_queue.rb', line 21
def host_root_url
@host_root_url
end
|
#requests ⇒ Object
Returns the value of attribute requests.
21
22
23
|
# File 'lib/fragmentary/request_queue.rb', line 21
def requests
@requests
end
|
#user_type ⇒ Object
Returns the value of attribute user_type.
21
22
23
|
# File 'lib/fragmentary/request_queue.rb', line 21
def user_type
@user_type
end
|
Class Method Details
.all ⇒ Object
5
6
7
|
# File 'lib/fragmentary/request_queue.rb', line 5
def self.all
@@all ||= []
end
|
.send_all(between: nil) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/fragmentary/request_queue.rb', line 9
def self.send_all(between: nil)
unless between
all.each{|q| q.start}
else
unless between.is_a? ActiveSupport::Duration
raise TypeError, "Fragmentary::RequestQueue.send_all requires the keyword argument :between to be of class ActiveSupport::Duration. The value provided is of class #{between.class.name}."
end
delay = 0.seconds
all.each{|q| q.start(:delay => delay += between)}
end
end
|
Instance Method Details
#<<(request) ⇒ Object
33
34
35
36
37
38
|
# File 'lib/fragmentary/request_queue.rb', line 33
def <<(request)
unless @requests.find{|r| r == request}
@requests << request
end
self
end
|
#clear ⇒ Object
48
49
50
|
# File 'lib/fragmentary/request_queue.rb', line 48
def clear
@requests = []
end
|
#next_request ⇒ Object
44
45
46
|
# File 'lib/fragmentary/request_queue.rb', line 44
def next_request
@requests.shift
end
|
#remove_path(path) ⇒ Object
52
53
54
|
# File 'lib/fragmentary/request_queue.rb', line 52
def remove_path(path)
requests.delete_if{|r| r.path == path}
end
|
#send(**args) ⇒ Object
60
61
62
|
# File 'lib/fragmentary/request_queue.rb', line 60
def send(**args)
sender.start(args)
end
|
#sender ⇒ Object
56
57
58
|
# File 'lib/fragmentary/request_queue.rb', line 56
def sender
@sender ||= Sender.new(self)
end
|
#size ⇒ Object
40
41
42
|
# File 'lib/fragmentary/request_queue.rb', line 40
def size
@requests.size
end
|