Class: Ryo::Plugin::Dir
- Inherits:
-
Object
- Object
- Ryo::Plugin::Dir
- Defined in:
- lib/ryo/plugin/dir.rb
Instance Attribute Summary collapse
-
#threads ⇒ Object
readonly
Returns the value of attribute threads.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #discover ⇒ Object
-
#initialize(uri) ⇒ Dir
constructor
A new instance of Dir.
- #paths ⇒ Object
- #url_for(path) ⇒ Object
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
#threads ⇒ Object (readonly)
Returns the value of attribute threads.
8 9 10 |
# File 'lib/ryo/plugin/dir.rb', line 8 def threads @threads end |
#uri ⇒ Object (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
#discover ⇒ Object
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 |
#paths ⇒ Object
14 15 16 |
# File 'lib/ryo/plugin/dir.rb', line 14 def paths File.readlines(File.("./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 |