Sha256: 139a783129e8555908d927b38bf783fce46a206d0457cc89c5a2face2a104935

Contents?: true

Size: 726 Bytes

Versions: 13

Compression:

Stored size: 726 Bytes

Contents

module ProconBypassMan
  class ServerPool
    def initialize(servers: )
      if servers.nil? || servers.empty?
        return
      end

      @servers = servers
      if @servers.size >= 1
        @index = 0
      else
        @index = nil
      end
    end

    def pick
      if @index.nil?
        return @servers&.first
      end
      @servers[@index] or raise "bug!!!"
    end
    def server; pick; end

    def next!
      inc_index
      if @servers[@index].nil?
        reset
        return
      end
    end

    private

    def reset
      @index = 0
    end

    def inc_index
      @index = @index + 1
    end
  end
end

if $0 == __FILE__
  ProconBypassMan::ServerPool.new(servers: ['http://example.com'])
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
procon_bypass_man-0.2.2 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.2.1 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.2.0 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.1.23 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.1.22 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.1.21 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.1.20.2 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.1.20.1 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.1.20 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.1.19.1 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.1.19 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.1.18 lib/procon_bypass_man/support/server_pool.rb
procon_bypass_man-0.1.17 lib/procon_bypass_man/support/server_pool.rb