Class: Ryo::Plugin::Dir

Inherits:
Object
  • Object
show all
Defined in:
lib/ryo/plugin/dir.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Dir

Returns a new instance of Dir.



9
10
11
12
# File 'lib/ryo/plugin/dir.rb', line 9

def initialize(uri)
  @uri = uri.is_a?(URI::HTTP) ? uri : URI.parse(uri)
  @threads = 10
end

Instance Attribute Details

#threadsObject (readonly)

Returns the value of attribute threads.



8
9
10
# File 'lib/ryo/plugin/dir.rb', line 8

def threads
  @threads
end

#uriObject (readonly)

Returns the value of attribute uri.



8
9
10
# File 'lib/ryo/plugin/dir.rb', line 8

def uri
  @uri
end

Class Method Details

.discover(uri) ⇒ Object



35
36
37
# File 'lib/ryo/plugin/dir.rb', line 35

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

Instance Method Details

#discoverObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ryo/plugin/dir.rb', line 22

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

#pathsObject



14
15
16
# File 'lib/ryo/plugin/dir.rb', line 14

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

#url_for(path) ⇒ Object



18
19
20
# File 'lib/ryo/plugin/dir.rb', line 18

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