Class: FaradayMiddleware::RelsMiddleware
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- FaradayMiddleware::RelsMiddleware
- Defined in:
- spaceship/lib/spaceship/helper/rels_middleware.rb
Instance Method Summary collapse
- #call(environment) ⇒ Object
-
#initialize(app, options = {}) ⇒ RelsMiddleware
constructor
A new instance of RelsMiddleware.
Constructor Details
#initialize(app, options = {}) ⇒ RelsMiddleware
Returns a new instance of RelsMiddleware.
11 12 13 14 |
# File 'spaceship/lib/spaceship/helper/rels_middleware.rb', line 11 def initialize(app, = {}) @app = app @options = end |
Instance Method Details
#call(environment) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'spaceship/lib/spaceship/helper/rels_middleware.rb', line 16 def call(environment) @app.call(environment).on_complete do |env| links = (env.response_headers["Link"] || "").split(', ').map do |link| href, name = link.match(/<(.*?)>; rel="(\w+)"/).captures [name.to_sym, href] end env.rels = Hash[*links.flatten] end end |