typhoeus 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/typhoeus.rb +1 -1
  2. data/lib/typhoeus/hydra.rb +25 -9
  3. metadata +1 -1
data/lib/typhoeus.rb CHANGED
@@ -14,7 +14,7 @@ require 'typhoeus/request'
14
14
  require 'typhoeus/hydra'
15
15
 
16
16
  module Typhoeus
17
- VERSION = "0.1.2"
17
+ VERSION = "0.1.3"
18
18
 
19
19
  def self.easy_object_pool
20
20
  @easy_objects ||= []
@@ -3,7 +3,7 @@ module Typhoeus
3
3
  def initialize
4
4
  @multi = Multi.new
5
5
  @easy_pool = []
6
- @mocks = []
6
+ @stubs = []
7
7
  @memoized_requests = {}
8
8
  @retrieved_from_cache = {}
9
9
  end
@@ -11,9 +11,17 @@ module Typhoeus
11
11
  def self.hydra
12
12
  @hydra ||= new
13
13
  end
14
+
15
+ def self.hydra=(val)
16
+ @hydra = val
17
+ end
18
+
19
+ def clear_stubs
20
+ @stubs = []
21
+ end
14
22
 
15
23
  def queue(request)
16
- return if assign_to_mock(request)
24
+ return if assign_to_stub(request)
17
25
 
18
26
  if request.method == :get
19
27
  if @memoized_requests.has_key? request.url
@@ -33,7 +41,7 @@ module Typhoeus
33
41
  end
34
42
 
35
43
  def run
36
- @mocks.each do |m|
44
+ @stubs.each do |m|
37
45
  m.requests.each do |request|
38
46
  m.response.request = request
39
47
  handle_request(request, m.response)
@@ -60,16 +68,16 @@ module Typhoeus
60
68
  @on_complete = proc
61
69
  end
62
70
 
63
- def mock(method, url)
64
- @mocks << HydraMock.new(url, method)
65
- @mocks.last
71
+ def stub(method, url)
72
+ @stubs << HydraMock.new(url, method)
73
+ @stubs.last
66
74
  end
67
75
 
68
- def assign_to_mock(request)
69
- m = @mocks.detect {|mck| mck.method == request.method && mck.url == request.url}
76
+ def assign_to_stub(request)
77
+ m = @stubs.detect {|stub| stub.matches? request}
70
78
  m && m.add_request(request)
71
79
  end
72
- private :assign_to_mock
80
+ private :assign_to_stub
73
81
 
74
82
  def get_from_cache_or_queue(request)
75
83
  if @cache_getter
@@ -156,5 +164,13 @@ module Typhoeus
156
164
  def and_return(val)
157
165
  @response = val
158
166
  end
167
+
168
+ def matches?(request)
169
+ if url.kind_of?(String)
170
+ request.method == method && request.url == url
171
+ else
172
+ request.method == method && url =~ request.url
173
+ end
174
+ end
159
175
  end
160
176
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typhoeus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dix