class RequestRepeater::Endpoint

Constants

InvalidURL
NoEndpointToCall

Attributes

last_execution[RW]
sleepfor[R]
timer[W]

Public Class Methods

new(url:, sleepfor:) click to toggle source
# File lib/request_repeater/endpoint.rb, line 10
def initialize(url:, sleepfor:)
  @sleepfor = sleepfor.to_i
  @url = url
end

Public Instance Methods

==(other_endpoint) click to toggle source
# 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?() click to toggle source
# File lib/request_repeater/endpoint.rb, line 22
def executable?
  timer.now > last_execution + RequestRepeater.sleeptime(sleepfor)
end
execute() { || ... } click to toggle source
# File lib/request_repeater/endpoint.rb, line 15
def execute
  if executable?
    yield
    executed
  end
end
executed() click to toggle source
# File lib/request_repeater/endpoint.rb, line 26
def executed
  @last_execution = timer.now
end
inspect() click to toggle source
# 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
timer() click to toggle source
# File lib/request_repeater/endpoint.rb, line 36
def timer
  @timer ||= Time
end
uri() click to toggle source
# 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() click to toggle source
# File lib/request_repeater/endpoint.rb, line 40
def url
   @url || raise(NoEndpointToCall)
end