README.md in detour-0.0.7 vs README.md in detour-0.0.9

- old
+ new

@@ -1,8 +1,9 @@ # Detour -Rollouts for `ActiveRecord` models. It is a spiritual fork of [ArRollout](https://github.com/markpundsack/ar_rollout). +Rollouts for `ActiveRecord` models. It is a spiritual fork of +[ArRollout](https://github.com/markpundsack/ar_rollout). | development status | master status | Code Climate | | ------------------ | ------------- | ------------ | | [![development status][dev_image]][branch_status] | [![master status][master_image]][branch_status] | [![Code Climate][code_climate_image]][code_climate] @@ -15,10 +16,11 @@ ## Contents - [Installation](#installation) - [Usage](#usage) - [Configuration](#configuration) + - [Restricting the admin interface](#restricting-the-admin-interface) - [Marking a model as flaggable](#marking-a-model-as-flaggable) - [Determining if a record is flagged into a feature](#determining-if-a-record-is-flagged-into-a-feature) - [Defining programmatic groups](#defining-programmatic-groups) - [Contributing](#contributing) @@ -42,11 +44,12 @@ ## Usage `Detour` works by determining whether or not a specific record should have features accessible to it based on individual flags, flags for a -percentage of records, or flags for a programmable group of records. +percentage of records, flags for a database-backed group of records, or flags +for a code-defined group of records. ### Configuration Edit `config/initializers/detour.rb`: @@ -59,24 +62,50 @@ # Detour needs to know what directories to search # through in order to find places where you're # checking for flags in your code. Provide it an # array of glob strings: config.feature_search_dirs = %w[app/**/*.{rb,erb}] - - # Provide a default class to manage rollouts for, if - # desired. This means you can omit the class name from - # rake tasks: - config.default_flaggable_class_name = "User" end ``` Mount the app in `config/routes.rb`: ```ruby Rails.application.routes.draw do mount Detour::Engine => "/detour" end ``` + +### Restricting the admin interface + +If you'd like your Detour admin interface only accessible to admins, for example, +you can add a `before_filter` to `Detour::ApplicationController` in the Detour +initializer: + +```ruby +# config/initializers/detour.rb + +Detour::ApplicationController.class_eval do + include CurrentUser + + before_filter :admin_required! + + private + + def admin_required! + if current_user && current_user.admin? + true + else + # redirect somewhere for non-admins + end + end +end +``` + +Since `Detour::ApplicationController` isn't a subclass of my `ApplicationController`, +I've included a `CurrentUser` module that I built in this app that adds a +`current_user` method to any controller that it's included in. Now, only admins +will have access to the Detour admin interface. ### Marking a model as flaggable In addition to listing classes that are flaggable in your initializer, add `acts_as_flaggable` to the class definitions themselves: