-
-
Notifications
You must be signed in to change notification settings - Fork 434
Expand file tree
/
Copy pathenabled_for_actor.rb
More file actions
37 lines (29 loc) · 941 Bytes
/
enabled_for_actor.rb
File metadata and controls
37 lines (29 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'bundler/setup'
require 'flipper'
# Some class that represents what will be trying to do something
class User
attr_reader :id
def initialize(id, admin)
@id = id
@admin = admin
end
def admin?
@admin
end
# Must respond to flipper_id
alias_method :flipper_id, :id
end
user1 = User.new(1, true)
user2 = User.new(2, false)
Flipper.register :admins do |actor|
actor.admin?
end
Flipper.enable :search
Flipper.enable_actor :stats, user1
Flipper.enable_percentage_of_actors :pro_stats, 50
Flipper.enable_group :tweets, :admins
Flipper.enable_actor :posts, user2
pp Flipper.features.select { |feature| feature.enabled?(user1) }.map(&:name).sort
pp Flipper.features.select { |feature| feature.enabled?(user2) }.map(&:name).sort
pp Flipper.features.select { |feature| feature.enabled?(user1, user2) }.map(&:name).sort
pp Flipper.features.select { |feature| feature.enabled?([user2, user1]) }.map(&:name).sort