benschwarz-openuri_memcached 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/openuri_memcached.rb +23 -4
- metadata +2 -2
data/lib/openuri_memcached.rb
CHANGED
@@ -11,8 +11,16 @@ require 'memcached'
|
|
11
11
|
module Kernel
|
12
12
|
private
|
13
13
|
alias openuri_original_open open
|
14
|
-
def open(
|
15
|
-
|
14
|
+
def open(name, *rest, &block)
|
15
|
+
if name.respond_to?(:open)
|
16
|
+
name.open(*rest, &block)
|
17
|
+
elsif name.respond_to?(:to_str) &&
|
18
|
+
%r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
|
19
|
+
(uri = URI.parse(name)).respond_to?(:open)
|
20
|
+
OpenURI::open(name, *rest, &block)
|
21
|
+
else
|
22
|
+
open_uri_original_open(name, *rest, &block)
|
23
|
+
end
|
16
24
|
end
|
17
25
|
module_function :open, :openuri_original_open
|
18
26
|
end
|
@@ -29,10 +37,21 @@ module OpenURI
|
|
29
37
|
end
|
30
38
|
|
31
39
|
unless response
|
32
|
-
response = openuri_original_open(uri, *rest
|
40
|
+
response = openuri_original_open(uri, *rest).read
|
33
41
|
Cache::set(uri.to_s, response) if Cache.enabled?
|
34
42
|
end
|
35
|
-
|
43
|
+
|
44
|
+
response = StringIO.new(response)
|
45
|
+
|
46
|
+
if block_given?
|
47
|
+
begin
|
48
|
+
yield response
|
49
|
+
ensure
|
50
|
+
response.close
|
51
|
+
end
|
52
|
+
else
|
53
|
+
response
|
54
|
+
end
|
36
55
|
end
|
37
56
|
|
38
57
|
class Cache
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: benschwarz-openuri_memcached
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Schwarz
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-11 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|