Class: ProxyService::Proxy
- Inherits:
-
Object
- Object
- ProxyService::Proxy
- Defined in:
- lib/proxy_service/proxy.rb
Instance Attribute Summary collapse
- #failures ⇒ Object
- #ip ⇒ Object
- #message ⇒ Object
- #port ⇒ Object
-
#worker ⇒ Object
Returns the value of attribute worker.
Instance Method Summary collapse
- #blocked! ⇒ Object
- #blocked? ⇒ Boolean
- #increment_failures ⇒ Object
-
#initialize(worker) ⇒ Proxy
constructor
A new instance of Proxy.
- #release ⇒ Object
- #reset_failures ⇒ Object
-
#to_h ⇒ Object
Coercion overrides.
- #to_json ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(worker) ⇒ Proxy
Returns a new instance of Proxy.
7 8 9 |
# File 'lib/proxy_service/proxy.rb', line 7 def initialize(worker) @worker = worker end |
Instance Attribute Details
#failures ⇒ Object
19 20 21 |
# File 'lib/proxy_service/proxy.rb', line 19 def failures @failures ||= ['failures'] end |
#ip ⇒ Object
11 12 13 |
# File 'lib/proxy_service/proxy.rb', line 11 def ip @ip ||= ['ip'] end |
#message ⇒ Object
23 24 25 |
# File 'lib/proxy_service/proxy.rb', line 23 def @message ||= { 'failures' => 0 }.merge(JSON.parse(worker..body)) end |
#port ⇒ Object
15 16 17 |
# File 'lib/proxy_service/proxy.rb', line 15 def port @port ||= ['port'] end |
#worker ⇒ Object
Returns the value of attribute worker.
3 4 5 |
# File 'lib/proxy_service/proxy.rb', line 3 def worker @worker end |
Instance Method Details
#blocked! ⇒ Object
43 44 45 |
# File 'lib/proxy_service/proxy.rb', line 43 def blocked! @blocked = true end |
#blocked? ⇒ Boolean
39 40 41 |
# File 'lib/proxy_service/proxy.rb', line 39 def blocked? !!@blocked end |
#increment_failures ⇒ Object
31 32 33 |
# File 'lib/proxy_service/proxy.rb', line 31 def increment_failures @failures += 1 end |
#release ⇒ Object
27 28 29 |
# File 'lib/proxy_service/proxy.rb', line 27 def release worker.release(self, blocked?) end |
#reset_failures ⇒ Object
35 36 37 |
# File 'lib/proxy_service/proxy.rb', line 35 def reset_failures @failures = 0 end |
#to_h ⇒ Object
Coercion overrides
51 52 53 54 55 56 57 |
# File 'lib/proxy_service/proxy.rb', line 51 def to_h { ip: ip, port: port, failures: failures } end |
#to_json ⇒ Object
59 60 61 |
# File 'lib/proxy_service/proxy.rb', line 59 def to_json to_h.to_json end |
#to_s ⇒ Object Also known as: inspect
63 64 65 |
# File 'lib/proxy_service/proxy.rb', line 63 def to_s %(#<Proxy:#{object_id} @ip="#{ip}", @port="#{port}", @failures=#{failures}, @blocked=#{blocked?}, @message=#{}, @worker="...">) end |