Class: RHACK::ScoutSquad
Instance Method Summary collapse
-
#initialize(*args) ⇒ ScoutSquad
constructor
A new instance of ScoutSquad.
- #next ⇒ Object
- #rand ⇒ Object
- #to_s ⇒ Object (also: #inspect)
- #untargeted ⇒ Object
- #update(uri, forced = nil) ⇒ Object
Methods inherited from Array
Constructor Details
#initialize(*args) ⇒ ScoutSquad
Returns a new instance of ScoutSquad.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rhack/scout_squad.rb', line 11 def initialize(*args) raise ArgumentError, "can't create empty squad" if (num = args.pop) < 1 proxies = nil super [] if args[0].is Scout s = args[0] else if !args[0].is String args.unshift '' if (opts = args[-1]).is Hash and (opts[:cp] || opts[:ck]).is Hash L.warn "it's useless to setup cookies for untargeted squad!" end end if args[1] and args[1][0].is Array proxies = args[1] args[1] = proxies.shift end self[0] = s = Scout(*args) num -=1 end num.times {|i| self << Scout(s.root+s.path, (proxies ? proxies[i] : s.proxy), s.ua, s.refforge, :ck => s.main_cks, :raise => s.raise_err, :timeout => s.timeout, :retry => s.retry) } end |
Instance Method Details
#next ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rhack/scout_squad.rb', line 64 def next raise PickError if !b if scout = find {|_|!_.loaded?}; scout else # Curl should run here, otherwise `next'/`rand'-recursion will cause stack overflow unless Curl.status L.log "Curl must run in order to use ScoutSquad#next; setting Carier Thread" Curl.execute :unless_allready #raise "Curl must run in order to use ScoutSquad#next" end #Curl.wait loop { sleep 1 break if Curl.carier.reqs.size < size } self.next end end |
#rand ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rhack/scout_squad.rb', line 45 def rand raise PickError if !b # to_a because reject returns object of this class if scout = to_a.rand {|_|!_.loaded?}; scout else # Curl should run here, otherwise `next'/`rand'-recursion will cause stack overflow unless Curl.status L.log "Curl must run in order to use ScoutSquad#rand; setting Carier Thread" Curl.execute #raise "Curl must run in order to use ScoutSquad#rand" end #Curl.wait loop { sleep 1 break if Curl.carier.reqs.size < size } self.rand end end |
#to_s ⇒ Object Also known as: inspect
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rhack/scout_squad.rb', line 82 def to_s str = '<#ScoutSquad @ ' if b if first.webproxy str << "#{first.proxy} ~ " elsif first.proxy str << first.proxy*':'+" ~ " end str << "#{untargeted ? "no target" : first.root} " end str << "x#{size}>" end |
#untargeted ⇒ Object
41 42 43 |
# File 'lib/rhack/scout_squad.rb', line 41 def untargeted first.root == 'http://' end |
#update(uri, forced = nil) ⇒ Object
36 37 38 39 |
# File 'lib/rhack/scout_squad.rb', line 36 def update uri, forced=nil each {|s| return L.warn "failed to update scout loaded? with url: #{s.http.url}" if s.loaded?} if !forced each {|s| s.update uri} end |