Class: Rack::GridFSThumb
- Inherits:
-
Object
- Object
- Rack::GridFSThumb
- Defined in:
- lib/rack/version.rb,
lib/rack/gridfs-thumb.rb
Constant Summary collapse
- VERSION =
'0.2.0'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ GridFSThumb
constructor
A new instance of GridFSThumb.
- #route ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ GridFSThumb
Returns a new instance of GridFSThumb.
6 7 8 9 10 |
# File 'lib/rack/gridfs-thumb.rb', line 6 def initialize(app, = {}) @app = app @options = .merge() @gridfs = @options[:gridfs] || Rack::GridFS::Endpoint.new(@options) end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rack/gridfs-thumb.rb', line 12 def call(env) @request = Rack::Request.new(env) response = catch(:respond) do match(@request.path_info) do |path, geometry| status, @headers, image = request_image(path) if geometry.nil? throw :respond, [status, @headers, image] end thumb = thumbnail(image, geometry) response_for(thumb) end end response || @app.call(env) end |
#route ⇒ Object
31 32 33 |
# File 'lib/rack/gridfs-thumb.rb', line 31 def route %r{(/#{@options[:prefix]}/[^/]+)/?([^/]+)?/?$} end |