Class: Wayfarer::Middleware::Normalize

Inherits:
Object
  • Object
show all
Extended by:
Base
Defined in:
lib/wayfarer/middleware/normalize.rb

Constant Summary

Constants included from Base

Base::API_MODULE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

api, lazy

Class Method Details

.normalize(uri) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/wayfarer/middleware/normalize.rb', line 11

def self.normalize(uri)
  return uri.to_s unless %w[http https].include?(uri.scheme)

  NormalizeUrl.process(uri)
rescue NormalizeUrl::InvalidURIError
  nil
end

Instance Method Details

#call(task) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/wayfarer/middleware/normalize.rb', line 19

def call(task)
  return (yield if block_given?) if task[:normalized_url]

  return log(:invalid, task) unless (task[:normalized_url] = self.class.normalize(task[:uri]))

  yield if block_given?
end