Class: Typhoeus::Hydra
- Inherits:
-
Object
- Object
- Typhoeus::Hydra
- Defined in:
- lib/typhoeus/hydra.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cache_getter(&block) ⇒ Object
- #cache_setter(&block) ⇒ Object
- #clear_stubs ⇒ Object
-
#initialize ⇒ Hydra
constructor
A new instance of Hydra.
- #on_complete(&block) ⇒ Object
- #on_complete=(proc) ⇒ Object
- #queue(request) ⇒ Object
- #run ⇒ Object
- #stub(method, url) ⇒ Object
Constructor Details
Class Method Details
.hydra ⇒ Object
11 12 13 |
# File 'lib/typhoeus/hydra.rb', line 11 def self.hydra @hydra ||= new end |
.hydra=(val) ⇒ Object
15 16 17 |
# File 'lib/typhoeus/hydra.rb', line 15 def self.hydra=(val) @hydra = val end |
Instance Method Details
#cache_getter(&block) ⇒ Object
55 56 57 |
# File 'lib/typhoeus/hydra.rb', line 55 def cache_getter(&block) @cache_getter = block end |
#cache_setter(&block) ⇒ Object
59 60 61 |
# File 'lib/typhoeus/hydra.rb', line 59 def cache_setter(&block) @cache_setter = block end |
#clear_stubs ⇒ Object
19 20 21 |
# File 'lib/typhoeus/hydra.rb', line 19 def clear_stubs @stubs = [] end |
#on_complete(&block) ⇒ Object
63 64 65 |
# File 'lib/typhoeus/hydra.rb', line 63 def on_complete(&block) @on_complete = block end |
#on_complete=(proc) ⇒ Object
67 68 69 |
# File 'lib/typhoeus/hydra.rb', line 67 def on_complete=(proc) @on_complete = proc end |
#queue(request) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/typhoeus/hydra.rb', line 23 def queue(request) return if assign_to_stub(request) if request.method == :get if @memoized_requests.has_key? request.url if response = @retrieved_from_cache[request.url] request.response = response request.call_handlers else @memoized_requests[request.url] << request end else @memoized_requests[request.url] = [] get_from_cache_or_queue(request) end else get_from_cache_or_queue(request) end end |
#run ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/typhoeus/hydra.rb', line 43 def run @stubs.each do |m| m.requests.each do |request| m.response.request = request handle_request(request, m.response) end end @multi.perform @memoized_requests = {} @retrieved_from_cache = {} end |