ruby-nuggets 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to ruby-nuggets version 0.7.6
5
+ This documentation refers to ruby-nuggets version 0.7.7
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -31,20 +31,25 @@ module Nuggets
31
31
  module URI
32
32
  module ExistMixin
33
33
 
34
+ URI_EXIST_HTTP_CACHE = ::Hash.new { |h, k| h[k] = ::Net::HTTP.new(*k) }
35
+
34
36
  # call-seq:
35
37
  # URI.exist?(uri) => +true+ or +false+
36
38
  #
37
39
  # Return +true+ if the URI +uri+ exists.
38
- def exist?(uri)
40
+ def exist?(uri, cache = URI_EXIST_HTTP_CACHE, steps = 20, &block)
39
41
  uri = ::URI.parse(uri.to_s)
40
42
  return unless uri.is_a?(::URI::HTTP)
41
43
 
42
- path = uri.path
43
- path = '/' if path.empty?
44
-
45
- res = ::Net::HTTP.start(uri.host, uri.port) { |http| http.head(path) }
44
+ res = cache[[uri.host, uri.port]].head(uri.request_uri)
46
45
 
47
- block_given? ? yield(res) : true if res.success?
46
+ if res.is_a?(::Net::HTTPRedirection)
47
+ exist?(res['Location'], cache, steps - 1, &block) if steps > 0
48
+ elsif res.success?
49
+ block ? block[res] : true
50
+ else
51
+ false
52
+ end
48
53
  rescue ::SocketError, ::Errno::EHOSTUNREACH
49
54
  end
50
55
 
@@ -4,7 +4,7 @@ module Nuggets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 7
7
- TINY = 6
7
+ TINY = 7
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-nuggets
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 6
10
- version: 0.7.6
9
+ - 7
10
+ version: 0.7.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jens Wille
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-21 00:00:00 Z
18
+ date: 2011-10-24 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Some extensions to the Ruby programming language.
@@ -193,14 +193,14 @@ licenses: []
193
193
 
194
194
  post_install_message:
195
195
  rdoc_options:
196
- - --line-numbers
197
196
  - --main
198
197
  - README
199
- - --all
200
198
  - --charset
201
199
  - UTF-8
200
+ - --all
202
201
  - --title
203
- - ruby-nuggets Application documentation (v0.7.6)
202
+ - ruby-nuggets Application documentation (v0.7.7)
203
+ - --line-numbers
204
204
  require_paths:
205
205
  - lib
206
206
  required_ruby_version: !ruby/object:Gem::Requirement