Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #11 from ryanlower/usage_in_readme

Add basic rails / rack usage information to readme
  • Loading branch information...
commit 8a7bb138254a56f24ae763a7b853a403e9e6ea45 2 parents 79cb23f + 0002440
@jnunemaker authored
Showing with 52 additions and 0 deletions.
  1. +52 −0 README.md
View
52 README.md
@@ -18,6 +18,58 @@ Or install it yourself as:
$ gem install flipper-ui
+## Usage
+
+### Rails
+
+Given that you've already initialized `Flipper` as per the [flipper](https://github.com/jnunemaker/flipper) readme:
+
+```ruby
+# config/initializers/flipper.rb
+$flipper = Flipper.new(...)
+```
+
+you can mount `Flipper::UI` to a route of your choice:
+```ruby
+# config/routes.rb
+
+YourRailsApp::Application.routes.draw do
+ mount Flipper::UI.app($flipper) => '/flipper'
+end
+```
+
+#### Security
+
+You almost certainly want to limit access when using Flipper::UI in production. Using [routes constraints](http://guides.rubyonrails.org/routing.html#request-based-constraints) is one way to achieve this:
+
+```ruby
+# config/routes.rb
+
+flipper_constraint = lambda { |request| request.remote_ip == '127.0.0.1' }
+constraints flipper_constraint do
+ mount Flipper::UI.app($flipper) => '/flipper'
+end
+```
+
+
+### Standalone
+
+Minimal example for Rack:
+
+```ruby
+# config.ru
+
+require 'flipper-ui'
+require 'flipper/adapters/memory'
+
+adapter = Flipper::Adapters::Memory.new
+flipper = Flipper.new(adapter)
+
+run Flipper::UI.app(flipper)
+```
+
+See [examples/basic.ru](https://github.com/jnunemaker/flipper-ui/blob/master/examples/basic.ru) for a more full example
+
## Contributing
1. Fork it
Please sign in to comment.
Something went wrong with that request. Please try again.