Permalink
Browse files

Update readme and examples.

  • Loading branch information...
1 parent fad3fd0 commit 672aef6fa02a87c22862eb2112ca86af9e17c4f5 @jnunemaker committed Jan 1, 2013
Showing with 36 additions and 41 deletions.
  1. +8 −13 README.md
  2. +1 −1 examples/basic.rb
  3. +4 −7 examples/dsl.rb
  4. +7 −4 examples/group.rb
  5. +6 −6 examples/individual_actor.rb
  6. +9 −9 examples/percentage_of_actors.rb
  7. +1 −1 examples/percentage_of_random.rb
View
21 README.md
@@ -92,14 +92,11 @@ Turn on for individual thing. Think enable feature for someone to test or for a
```ruby
flipper = Flipper.new(adapter)
-# convert user or person or whatever to flipper actor for storing and checking
-actor = flipper.actor(user.id)
+flipper[:stats].enable user
+flipper[:stats].enabled? user # true
-flipper[:stats].enable actor
-flipper[:stats].enabled? actor # true
-
-flipper[:stats].disable actor
-flipper[:stats].disabled? actor # true
+flipper[:stats].disable user
+flipper[:stats].disabled? user # true
```
### 4. Percentage of Actors
@@ -109,17 +106,15 @@ Turn this on for a percentage of actors (think user, member, account, group, wha
```ruby
flipper = Flipper.new(adapter)
-# convert user or person or whatever to flipper actor for checking if in percentage
-actor = flipper.actor(user.id)
-
# returns a percentage of actors instance set to 10
percentage = flipper.actors(10)
# turn stats on for 10 percent of users in the system
flipper[:stats].enable percentage
-# checks if actor's identifier is in the enabled percentage
-flipper[:stats].enabled? actor
+# checks if actor's id is in the enabled percentage
+# uses hash of user.id.to_s to ensure enabled distribution is smooth
+flipper[:stats].enabled? user
```
@@ -139,7 +134,7 @@ percentage = flipper.random(5)
flipper[:logging].enable percentage
```
-Randomness is probably not a good idea for enabling new features in the UI. Most of the time you want a feature on or off for a user, but there are definitely times when I have found percentage of random to be very useful.
+Randomness is not a good idea for enabling new features in the UI. Most of the time you want a feature on or off for a user, but there are definitely times when I have found percentage of random to be very useful.
## Adapters
View
2 examples/basic.rb
@@ -1,4 +1,4 @@
-require './example_setup'
+require File.expand_path('../example_setup', __FILE__)
require 'flipper'
require 'flipper/adapters/memory'
View
11 examples/dsl.rb
@@ -1,4 +1,4 @@
-require './example_setup'
+require File.expand_path('../example_setup', __FILE__)
require 'flipper'
require 'flipper/adapters/memory'
@@ -68,12 +68,9 @@ def initialize(id)
responds_to_id = Struct.new(:id).new(10)
puts flipper.actor(responds_to_id).inspect
-# get an instance of an actor using an object that responds to identifier
-responds_to_identifier = Struct.new(:identifier).new(11)
-puts flipper.actor(responds_to_identifier).inspect
-
-# get an instance of an actor using a number
-puts flipper.actor(23).inspect
+# get an instance of an actor using an object
+thing = Struct.new(:id).new(22)
+puts flipper.actor(thing).inspect
# register a top level group
admins = Flipper.register(:admins) { |actor|
View
11 examples/group.rb
@@ -1,4 +1,4 @@
-require './example_setup'
+require File.expand_path('../example_setup', __FILE__)
require 'flipper'
require 'flipper/adapters/memory'
@@ -14,7 +14,10 @@
# Some class that represents actor that will be trying to do something
class User
- def initialize(admin)
+ attr_reader :id
+
+ def initialize(id, admin)
+ @id = id
@admin = admin
end
@@ -23,8 +26,8 @@ def admin?
end
end
-admin = User.new(true)
-non_admin = User.new(false)
+admin = User.new(1, true)
+non_admin = User.new(2, false)
puts "Stats for admin: #{stats.enabled?(admin)}"
puts "Stats for non_admin: #{stats.enabled?(non_admin)}"
View
12 examples/individual_actor.rb
@@ -1,4 +1,4 @@
-require './example_setup'
+require File.expand_path('../example_setup', __FILE__)
require 'flipper'
require 'flipper/adapters/memory'
@@ -19,11 +19,11 @@ def initialize(id)
user1 = User.new(1)
user2 = User.new(2)
-puts "Stats for user1: #{stats.enabled?(flipper.actor(user1))}"
-puts "Stats for user2: #{stats.enabled?(flipper.actor(user2))}"
+puts "Stats for user1: #{stats.enabled?(user1)}"
+puts "Stats for user2: #{stats.enabled?(user2)}"
puts "\nEnabling stats for user1...\n\n"
-stats.enable(flipper.actor(user1))
+stats.enable(user1)
-puts "Stats for user1: #{stats.enabled?(flipper.actor(user1))}"
-puts "Stats for user2: #{stats.enabled?(flipper.actor(user2))}"
+puts "Stats for user1: #{stats.enabled?(user1)}"
+puts "Stats for user2: #{stats.enabled?(user2)}"
View
18 examples/percentage_of_actors.rb
@@ -1,4 +1,4 @@
-require './example_setup'
+require File.expand_path('../example_setup', __FILE__)
require 'flipper'
require 'flipper/adapters/memory'
@@ -19,17 +19,17 @@ def initialize(id)
pitt = User.new(1)
clooney = User.new(10)
-puts "Stats for pitt: #{stats.enabled?(flipper.actor(pitt))}"
-puts "Stats for clooney: #{stats.enabled?(flipper.actor(clooney))}"
+puts "Stats for pitt: #{stats.enabled?(pitt)}"
+puts "Stats for clooney: #{stats.enabled?(clooney)}"
puts "\nEnabling stats for 5 percent...\n\n"
stats.enable(Flipper::Types::PercentageOfActors.new(5))
-puts "Stats for pitt: #{stats.enabled?(flipper.actor(pitt))}"
-puts "Stats for clooney: #{stats.enabled?(flipper.actor(clooney))}"
+puts "Stats for pitt: #{stats.enabled?(pitt)}"
+puts "Stats for clooney: #{stats.enabled?(clooney)}"
-puts "\nEnabling stats for 15 percent...\n\n"
-stats.enable(Flipper::Types::PercentageOfActors.new(15))
+puts "\nEnabling stats for 50 percent...\n\n"
+stats.enable(Flipper::Types::PercentageOfActors.new(50))
-puts "Stats for pitt: #{stats.enabled?(flipper.actor(pitt))}"
-puts "Stats for clooney: #{stats.enabled?(flipper.actor(clooney))}"
+puts "Stats for pitt: #{stats.enabled?(pitt)}"
+puts "Stats for clooney: #{stats.enabled?(clooney)}"
View
2 examples/percentage_of_random.rb
@@ -1,4 +1,4 @@
-require './example_setup'
+require File.expand_path('../example_setup', __FILE__)
require 'flipper'
require 'flipper/adapters/memory'

0 comments on commit 672aef6

Please sign in to comment.