Permalink
Browse files

Updated readme and examples.

  • Loading branch information...
1 parent bd5b70b commit 307ea52d603492b1fe5005271de6e54e5baa3176 @jnunemaker committed Jan 11, 2013
Showing with 38 additions and 10 deletions.
  1. +19 −5 README.md
  2. +7 −4 examples/dsl.rb
  3. +3 −0 examples/group.rb
  4. +3 −0 examples/individual_actor.rb
  5. +3 −0 examples/percentage_of_actors.rb
  6. +3 −1 examples/percentage_of_random.rb
View
@@ -87,7 +87,7 @@ There is no requirement that the thing yielded to the block be a user model or w
### 3. Individual Actor
-Turn feature on for individual thing. Think enable feature for someone to test or for a buddy. The only requirement for an individual actor is that it must respond to `id`.
+Turn feature on for individual thing. Think enable feature for someone to test or for a buddy. The only requirement for an individual actor is that it must respond to `flipper_id`.
```ruby
flipper = Flipper.new(adapter)
@@ -103,9 +103,23 @@ flipper[:search].enable group
flipper[:search].enabled? group
```
-The key is to make sure you do not enable two different types of objects for the same feature. Imagine that user has an id of 6 and group has an id of 6. Enabling search for user would automatically enable it for group, as they both have an id of 6.
+The key is to make sure you do not enable two different types of objects for the same feature. Imagine that user has a flipper_id of 6 and group has a flipper_id of 6. Enabling search for user would automatically enable it for group, as they both have a flipper_id of 6.
-The one exception to this rule is if you have globally unique ids, such as uuid's. If your ids are unique globally in your entire system, enabling two different types should be safe.
+The one exception to this rule is if you have globally unique flipper_ids, such as uuid's. If your flipper_ids are unique globally in your entire system, enabling two different types should be safe. Another way around this is to prefix the flipper_id with the class name like this:
+
+```ruby
+class User
+ def flipper_id
+ "User:#{id}"
+ end
+end
+
+class Group
+ def flipper_id
+ "Group:#{id}"
+ end
+end
+```
### 4. Percentage of Actors
@@ -120,8 +134,8 @@ percentage = flipper.actors(10)
# turn stats on for 10 percent of users in the system
flipper[:stats].enable percentage
-# checks if actor's id is in the enabled percentage
-# uses hash of user.id.to_s to ensure enabled distribution is smooth
+# checks if actor's flipper_id is in the enabled percentage by hashing
+# user.flipper_id.to_s to ensure enabled distribution is smooth
flipper[:stats].enabled? user
```
View
@@ -13,6 +13,9 @@ class Person
def initialize(id)
@id = id
end
+
+ # Must respond to flipper_id
+ alias_method :flipper_id, :id
end
person = Person.new(1)
@@ -64,12 +67,12 @@ def initialize(id)
# get an instance of the percentage of actors type set to 15
puts flipper.actors(15).inspect
-# get an instance of an actor using an object that responds to 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 flipper_id
+responds_to_flipper_id = Struct.new(:flipper_id).new(10)
+puts flipper.actor(responds_to_flipper_id).inspect
# get an instance of an actor using an object
-thing = Struct.new(:id).new(22)
+thing = Struct.new(:flipper_id).new(22)
puts flipper.actor(thing).inspect
# register a top level group
View
@@ -21,6 +21,9 @@ def initialize(id, admin)
@admin = admin
end
+ # Must respond to flipper_id
+ alias_method :flipper_id, :id
+
def admin?
@admin == true
end
@@ -14,6 +14,9 @@ class User
def initialize(id)
@id = id
end
+
+ # Must respond to flipper_id
+ alias_method :flipper_id, :id
end
user1 = User.new(1)
@@ -14,6 +14,9 @@ class User
def initialize(id)
@id = id
end
+
+ # Must respond to flipper_id
+ alias_method :flipper_id, :id
end
pitt = User.new(1)
@@ -25,9 +25,11 @@
actual = (enabled.size / total.to_f * 100).round(2)
# puts "#{enabled.size} / #{total}"
- puts "percentage: #{actual} vs #{number}"
+ puts "percentage: #{actual.to_s.rjust(6, ' ')} vs #{number.to_s.rjust(3, ' ')}"
end
+puts "percentage: Actual vs Hoped For"
+
[1, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 99, 100].each do |number|
perform_test.call number
end

0 comments on commit 307ea52

Please sign in to comment.