Class: RequestRepeater::Endpoint
- Inherits:
-
Object
- Object
- RequestRepeater::Endpoint
- Defined in:
- lib/request_repeater/endpoint.rb
Constant Summary collapse
- NoEndpointToCall =
Class.new(StandardError)
- InvalidURL =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#last_execution ⇒ Object
Returns the value of attribute last_execution.
-
#sleepfor ⇒ Object
readonly
Returns the value of attribute sleepfor.
- #timer ⇒ Object
Instance Method Summary collapse
- #==(other_endpoint) ⇒ Object
- #executable? ⇒ Boolean
- #execute ⇒ Object
- #executed ⇒ Object
-
#initialize(url:, sleepfor:) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #inspect ⇒ Object
- #uri ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(url:, sleepfor:) ⇒ Endpoint
Returns a new instance of Endpoint.
10 11 12 13 |
# File 'lib/request_repeater/endpoint.rb', line 10 def initialize(url:, sleepfor:) @sleepfor = sleepfor.to_i @url = url end |
Instance Attribute Details
#last_execution ⇒ Object
Returns the value of attribute last_execution.
8 9 10 |
# File 'lib/request_repeater/endpoint.rb', line 8 def last_execution @last_execution end |
#sleepfor ⇒ Object (readonly)
Returns the value of attribute sleepfor.
6 7 8 |
# File 'lib/request_repeater/endpoint.rb', line 6 def sleepfor @sleepfor end |
#timer ⇒ Object
36 37 38 |
# File 'lib/request_repeater/endpoint.rb', line 36 def timer @timer ||= Time end |
Instance Method Details
#==(other_endpoint) ⇒ Object
30 31 32 33 34 |
# File 'lib/request_repeater/endpoint.rb', line 30 def ==(other_endpoint) self.url == other_endpoint.url \ && self.sleepfor == other_endpoint.sleepfor \ && self.last_execution == other_endpoint.last_execution end |
#executable? ⇒ Boolean
22 23 24 |
# File 'lib/request_repeater/endpoint.rb', line 22 def executable? timer.now > last_execution + RequestRepeater.sleeptime(sleepfor) end |
#execute ⇒ Object
15 16 17 18 19 20 |
# File 'lib/request_repeater/endpoint.rb', line 15 def execute if executable? yield executed end end |
#executed ⇒ Object
26 27 28 |
# File 'lib/request_repeater/endpoint.rb', line 26 def executed @last_execution = timer.now end |
#inspect ⇒ Object
53 54 55 |
# File 'lib/request_repeater/endpoint.rb', line 53 def inspect "#<#{self.class}:#{object_id.to_s(16)} url=#{url.to_s[0..16]}... sleepfor=#{sleepfor}>" end |
#uri ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/request_repeater/endpoint.rb', line 44 def uri @uri ||= begin uri = URI.parse(url) raise InvalidURL, "#{url} is not valid url. Expecting format 'http://myapp/endpoint" unless uri.host uri.path = uri.path.to_s == '' ? '/' : uri.path uri end end |
#url ⇒ Object
40 41 42 |
# File 'lib/request_repeater/endpoint.rb', line 40 def url @url || raise(NoEndpointToCall) end |