Sha256: 5253e4a3ae378dbd59fbec13a3ca365fc07441d31935c3d2c4d09461e88e6cf0

Contents?: true

Size: 855 Bytes

Versions: 2

Compression:

Stored size: 855 Bytes

Contents

# frozen_string_literal: true

require "thread/pool"

module Ryo
  module Plugin
    class Dir
      attr_reader :uri, :threads
      def initialize(uri)
        @uri = uri.is_a?(URI::HTTP) ? uri : URI.parse(uri)
        @threads = 10
      end

      def paths
        File.readlines(File.expand_path("./aux/paths.txt", __dir__)).map(&:chomp).compact
      end

      def url_for(path)
        "#{uri.scheme}://#{uri.host}:#{uri.port}/#{path}"
      end

      def discover
        pool = Thread.pool(threads)
        results = []
        paths.map { |path| url_for(path) }.each do |url|
          pool.process {
            res = Client.http.get(url)
            results << url if res.code == 200
          }
        end
        pool.shutdown
        results
      end

      def self.discover(uri)
        new(uri).discover
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ryo-0.3.2 lib/ryo/plugin/dir.rb
ryo-0.3.1 lib/ryo/plugin/dir.rb