Sha256: e842d79110a623f6fd1248564081b23126678e8d00a94eb17c3119abe7bdcd18

Contents?: true

Size: 800 Bytes

Versions: 5

Compression:

Stored size: 800 Bytes

Contents

require './example_setup'

require 'flipper'
require 'flipper/adapters/memory'

adapter = Flipper::Adapters::Memory.new
flipper = Flipper.new(adapter)
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
  def initialize(admin)
    @admin = admin
  end

  def admin?
    @admin == true
  end
end

admin = User.new(true)
non_admin = User.new(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(flipper.group(:admins))

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
flipper-0.3.0 examples/group.rb
flipper-0.2.1 examples/group.rb
flipper-0.2.0 examples/group.rb
flipper-0.1.1 examples/group.rb
flipper-0.1.0 examples/group.rb