lib/rack/musicindex.rb in rack-musicindex-0.0.1 vs lib/rack/musicindex.rb in rack-musicindex-0.0.2

- old
+ new

@@ -8,25 +8,19 @@ init(options) end def init(options) @dirs = options - @files = {} - @static_paths = {} - @dirs.each do |path, dir| - @files[path] = Dir[dir + '/*.mp3'] - @files[path].each do |filename| - @static_paths[path + '/' + ::File.basename(filename)] = filename - end - end end def call(env) status, headers, response = @app.call(env) path_info = env['PATH_INFO'] + update_files + if dirs[path_info] headers['Content-Type'] = 'application/xml;charset=utf-8' body = podcast(env) headers["Content-Length"] = body.length.to_s response = [body] @@ -52,9 +46,21 @@ @files[media_dir] end def static_paths @static_paths + end + + def update_files + @files = {} + @static_paths = {} + + dirs.each do |path, dir| + @files[path] = Dir[dir + '/*.mp3'] + @files[path].each do |filename| + @static_paths[path + '/' + ::File.basename(filename)] = filename + end + end end def podcast(env) path = env['PATH_INFO'] req = Rack::Request.new(env)