-
-
Notifications
You must be signed in to change notification settings - Fork 419
/
Copy pathdsl.rb
57 lines (41 loc) · 1.39 KB
/
dsl.rb
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'bundler/setup'
require 'flipper'
# create an actor with an identifier
class Person < Struct.new(:id)
include Flipper::Identifier
end
person = Person.new(1)
puts "Stats are disabled by default\n\n"
# is a feature enabled
puts "flipper.enabled? :stats: #{Flipper.enabled? :stats}"
# is a feature on or off for a particular person
puts "Flipper.enabled? :stats, person: #{Flipper.enabled? :stats, person}"
# get at a feature
puts "\nYou can also get an individual feature like this:\nstats = Flipper[:stats]\n\n"
stats = Flipper[:stats]
# is that feature enabled
puts "stats.enabled?: #{stats.enabled?}"
# is that feature enabled for a particular person
puts "stats.enabled? person: #{stats.enabled? person}"
# enable a feature by name
puts "\nEnabling stats\n\n"
Flipper.enable :stats
# or, you can use the feature to enable
stats.enable
puts "stats.enabled?: #{stats.enabled?}"
puts "stats.enabled? person: #{stats.enabled? person}"
# oh, no, let's turn this baby off
puts "\nDisabling stats\n\n"
Flipper.disable :stats
# or we can disable using feature obviously
stats.disable
puts "stats.enabled?: #{stats.enabled?}"
puts "stats.enabled? person: #{stats.enabled? person}"
puts
# register a top level group
admins = Flipper.register(:admins) { |actor|
actor.respond_to?(:admin?) && actor.admin?
}
puts admins.inspect
# get instance of registered group by name
puts Flipper.group(:admins).inspect