Sha256: 043b9055e78467c7c8a19ad03fee795129bbd39be29e215d99fa17b9e957a9a8
Contents?: true
Size: 996 Bytes
Versions: 3
Compression:
Stored size: 996 Bytes
Contents
module Thumbs class Config def initialize(app, url_map) @app = app @url_pattern, @keys = compile(url_map) end def call(env) env['thumbs.url_pattern'] = @url_pattern if match = @url_pattern.match(env['PATH_INFO']) values = match.captures.to_a params = @keys.zip(values).inject({}) do |hash,(k,v)| hash[k.to_sym] = v hash end image = Image.new(params.merge(:thumbs_folder => env['thumbs.thumbs_folder'])) env['thumbs.remote_url'] = image.remote_url env['thumbs.resized_path'] = image.resized_path env['thumbs.original_path'] = image.original_path env['thumbs.size'] = image.size end @app.call(env) end protected def compile(url_map) keys = [] pattern = url_map.gsub(/((:\w+))/) do |match| keys << $2[1..-1] "(.+?)" end [/^#{pattern}$/, keys] end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
thumbs-0.0.5 | lib/thumbs/middleware/config.rb |
thumbs-0.0.4 | lib/thumbs/middleware/config.rb |
thumbs-0.0.3 | lib/thumbs/middleware/config.rb |