Class: LinkMiddleware::Annotator
- Inherits:
-
Object
- Object
- LinkMiddleware::Annotator
- Defined in:
- lib/link-middleware/annotator.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Annotator
constructor
A new instance of Annotator.
Constructor Details
#initialize(app, options = {}) ⇒ Annotator
Returns a new instance of Annotator.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/link-middleware/annotator.rb', line 5 def initialize(app, ={}) @app = app @options = if [:store] @store = [:store] elsif [:store_impl] @store = [:store].new() else @store = LinkMiddleware::MemoryStore.new() end end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/link-middleware/annotator.rb', line 17 def call(env) status, headers, response = @app.call(env) request = Rack::Request.new( env ) stored_links = @store.read( request.url ) if !stored_links.links.empty? link_header = stored_links.to_s if headers["Link"] link_header = env["Link"] + ";" + link_header end headers["Link"] = link_header end [status, headers, response] end |