README.md in rack-mogilefs-0.1.1 vs README.md in rack-mogilefs-0.1.2
- old
+ new
@@ -1,30 +1,34 @@
-# Rack middleware/endpoint for serving MogileFS files
+# rack-mogilefs
+If you are using Nginx you'll probably want to serve MogileFS files with
+the [MogileFS Module](http://www.grid.net.ru/nginx/mogilefs.en.html), but if
+you need to serve them out of a Rack app, this should help.
+
## Getting Started:
First install the gem:
gem install rack-mogilefs
There are a variety of ways to use it:
### Rack middleware
# (config.ru)
- use Rack::MogileFS, :path => %r{^/system/*}
+ use Rack::MogileFS, :path => %r{^/assets/*}
### Rails 3:
# (config/routes.rb)
- match "/system/*" => Rack::MogileFS::Endpoint.new
+ match "/assets/*" => Rack::MogileFS::Endpoint.new
### Rails 2:
- # (app/metal/mogilefs.rb)
- class MogileFSMetal
+ # (app/metal/mogilefs_metal.rb)
+ class MogilefsMetal
def self.call(env)
- if env["PATH_INFO"] =~ %r{^/system/*}
+ if env["PATH_INFO"] =~ %r{^/assets/*}
Rack::MogileFS::Endpoint.new.call(env)
else
[ 404, { "Content-Type" => "text/html" }, ["Not Found"] ]
end
end
@@ -34,14 +38,23 @@
`Rack::MogileFS` uses the request path (`PATH_INFO`) for the MogileFS key. The
content type of the file is detected by the extension, using the `mime-types`
gem.
+If you want to customize the mapping of the PATH_INFO string to a MogileFS key
+you can provide a mapper proc (or anything that responds to call) like this:
+
+ # map '/assets/filename.gif' to the mogilefs key 'filename.gif'
+ # Rack::MogileFS and Rack::MogileFS::Endpoint take the same options
+ use Rack::MogileFS,
+ :path => %r{^/assets/*},
+ :mapper => lambda { |path| path.sub('/assets/', '') }
+
## Configuration
-By default will look for a yaml config in `config/mogilefs.yml` that looks
-like this:
+If `Rack::MogileFS` detects it is inside a Rails app, it will look for a yaml
+config in `config/mogilefs.yml` that looks like this:
development:
connection:
domain: "development.myapp.com"
hosts:
@@ -50,10 +63,10 @@
class: "file"
staging:
...
-and initialize a mogilefs client like this:
+and initialize a MogileFS client like this:
config = YAML.load_file( Rails.root.join("config/mogilefs.yml") )[Rails.env]
MogileFS::MogileFS.new( config["connection"].symbolize_keys )
You can override this by passing in a MogileFS client of your own:
\ No newline at end of file