Module: Nuggets::URI::ExistMixin
- Included in:
- URI
- Defined in:
- lib/nuggets/uri/exist_mixin.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#exist?(uri) ⇒ Boolean
(also: #exists?)
call-seq: URI.exist?(uri) =>
true
,false
ornil
URI.exist?(uri) { |res| … } => anObject,false
ornil
.
Class Method Details
.extended(base) ⇒ Object
34 35 36 |
# File 'lib/nuggets/uri/exist_mixin.rb', line 34 def self.extended(base) base.extend Nuggets::URI::RedirectMixin end |
Instance Method Details
#exist?(uri) ⇒ Boolean Also known as: exists?
call-seq:
URI.exist?(uri) => +true+, +false+ or +nil+
URI.exist?(uri) { |res| ... } => anObject, +false+ or +nil+
Checks whether the URI uri
exists by performing a HEAD
request. If successful, yields the response to the given block and returns its return value, or true
if no block was given. Returns false
in case of failure, or nil
if the redirect limit has been exceeded.
See Nuggets::URI::RedirectMixin#follow_redirect for more information.
48 49 50 |
# File 'lib/nuggets/uri/exist_mixin.rb', line 48 def exist?(uri) head_redirect(uri) { |res| res.success? && (!block_given? || yield(res)) } end |