Sha256: 32bcca1b2c7e4ab4a3fb947ca59267eb71af2dd96dc4582d254a0a0169c543c4

Contents?: true

Size: 788 Bytes

Versions: 38

Compression:

Stored size: 788 Bytes

Contents

require 'bundler/setup'
require 'flipper'

stats = Flipper[:stats]

# Register group
Flipper.register(:admins) do |actor|
  actor.respond_to?(:admin?) && actor.admin?
end

# Some class that represents actor that will be trying to do something
class User
  attr_reader :id

  def initialize(id, admin)
    @id = id
    @admin = admin
  end

  # Must respond to flipper_id
  alias_method :flipper_id, :id

  def admin?
    @admin == true
  end
end

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)}"

puts "\nEnabling Stats for admins...\n\n"
stats.enable_group :admins

puts "Stats for admin: #{stats.enabled?(admin)}"
puts "Stats for non_admin: #{stats.enabled?(non_admin)}"

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
flipper-1.3.2 examples/group.rb
flipper-1.3.1 examples/group.rb
flipper-1.3.0 examples/group.rb
flipper-1.3.0.pre examples/group.rb
flipper-1.2.2 examples/group.rb
flipper-1.2.1 examples/group.rb
flipper-1.2.0 examples/group.rb
flipper-1.1.2 examples/group.rb
flipper-1.1.1 examples/group.rb
flipper-1.1.0 examples/group.rb
flipper-1.0.0 examples/group.rb
flipper-1.0.0.pre examples/group.rb
flipper-0.28.3 examples/group.rb
flipper-0.28.2 examples/group.rb
flipper-0.28.1 examples/group.rb
flipper-0.28.0 examples/group.rb
flipper-0.27.1 examples/group.rb
flipper-0.27.0 examples/group.rb
flipper-0.26.2 examples/group.rb
flipper-0.26.1 examples/group.rb