lib/page_rankr/trackers.rb in PageRankr-3.2.1 vs lib/page_rankr/trackers.rb in PageRankr-4.0.0
- old
+ new
@@ -1,6 +1,6 @@
-require 'typhoeus'
+require 'thread'
module PageRankr
module Trackers
attr_accessor :site_trackers
@@ -8,30 +8,35 @@
@site_trackers = self.class.constants.collect{|tracker| symbol_for(tracker)}
end
def lookup(site, *trackers)
trackers = site_trackers if trackers.empty?
-
- tracked = {}
- hydra = Typhoeus::Hydra.new
- trackers.each do |tracker|
+
+ tracked = trackers.map do |tracker|
name, klass = constant_name(tracker), self.class
next unless klass.const_defined? name
- tracked[tracker] = klass.const_get(name).new(site)
- hydra.queue tracked[tracker].request
+ [
+ tracker,
+ build_thread(tracker, klass.const_get(name), site)
+ ]
+ end.each do |_, thread|
+ thread.join
+ end.map do |tracker, thread|
+ [tracker, thread.value]
end
- hydra.run
- tracked.keys.each do |tracker|
- tracked[tracker] = tracked[tracker].tracked
- end
-
- tracked
+ Hash[tracked]
end
private
+
+ def build_thread(tracker, instance, site)
+ Thread.new(tracker, instance, site) do |t, i, s|
+ i.new(s).run
+ end
+ end
def symbol_for(klass)
word = klass.to_s.dup
word.gsub!(/([A-Z]+)([A-Z][a-z])/){|match| "#{$1}_#{$2}" }
word.gsub!(/([a-z\d])([A-Z])/){|match| "#{$1}_#{$2}" }
\ No newline at end of file